Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a number of bugs in SyntaxTree and SyntaxTreeCode #5165

Merged
merged 5 commits into from
Oct 27, 2022

Conversation

ChrisJefferson
Copy link
Contributor

I believe this fixes #5117, but it would be good if @zickgraf could have a look.

Note that this changes some previously generated trees (see the diff), but I believe they were always wrong, it's just that the integer 1 was being interpreted as an Expr (where it is 0), but the integer 2 interpreted as an Expr caused a crash.

src/syntaxtree.c Outdated Show resolved Hide resolved
@@ -864,7 +866,7 @@ static const CompilerT Compilers[] = {
COMPILER_(EXPR_ELMS_LIST_LEV,
ARG_EXPR_("lists"),
ARG_EXPR_("poss"),
ARG_EXPR_("level")),
ARG_EXPR("level", ObjInt_UInt, UInt_ObjInt)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, that makes sense. Nice catch!

@zickgraf
Copy link
Contributor

Thanks a lot, works perfectly! And it confirms my expectation that a stack of EXPR_ELMS_LIST_LEV always terminates with an EXPR_ELMS_LIST, which means my solution in #5116 is actually correct :D

While reading the documentation again, I noticed that this level thing also exists for the usual list access (EXPR_ELM_LIST_LEV). Trying to use this gives a segfault which I guess has an analogous fix:

SYNTAX_TREE( function ( x ) return [ [ [ [ 1 ] ] ] ]{[ 1 ]}[1]{[1]}[1]; end )

Note: This is in no way important for me, I'm just trying to find further ways to produce crashes :D

@fingolfin
Copy link
Member

Thanks @zickgraf , good catch. Perhaps @ChrisJefferson will also fix that, too :-)

fingolfin
fingolfin previously approved these changes Oct 21, 2022
@fingolfin fingolfin added the gapdays2022-summer Issues and PRs that arose at https://www.gapdays.de/gapdays2022-summer label Oct 21, 2022
@ChrisJefferson
Copy link
Contributor Author

This PR grew slightly out of control while fixing some other SYNTAX_TREE issues, I'm happy to pull it apart.

Now it contains:

(outside of SYNTAX_TREE) while tracking down a crash I added asserts to SIZE_EXPR. This revealed for chars we make bags of size uchar(1), which mean we shouldn't the read and write Exprs (which are size 8) from them. As we already round allocations up to word size this wasn't actually doing any harm in practice, but let's fix it anyway.

I also (this is the slightly horrible code) generalised the SYNTAX_TREE code to support variadics in the middle of an object.

@ChrisJefferson ChrisJefferson force-pushed the fix-syntax-tree branch 2 times, most recently from 43845ec to 253b48a Compare October 21, 2022 17:08
src/code.h Outdated Show resolved Hide resolved
@ChrisJefferson
Copy link
Contributor Author

Just to point out (in particular if @zickgraf is using this), this PR changes how matrix indexing is done, to make it (correctly) handle 2d matrices. Also (last push, as I'm sat in the airport), I decided to add an assert which makes sure all of an expr is used in SyntaxTree. This showed up a bug in handling EXPR_REC_TILDE. On deep investigation, it turns out this doesn't need to be handled differently (as we don't need to worry here where the tildes bind to, just preserve their presence).

Added an assert which checks all of an expr is used during
SYNTAX_TREE. This showed that EXPR_REC_TILDE wasn't implemented.
@fingolfin fingolfin self-requested a review October 22, 2022 08:27
@fingolfin fingolfin dismissed their stale review October 22, 2022 08:27

Lots of changes were made after my review

@ChrisJefferson ChrisJefferson changed the title Fix EXPR_ELMS_LIST_LEV in SYNTAX_TREE Fix various bugs in in SYNTAX_TREE Oct 23, 2022
@ChrisJefferson ChrisJefferson added kind: bug Issues describing general bugs, and PRs fixing them release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes labels Oct 23, 2022
@ChrisJefferson ChrisJefferson changed the title Fix various bugs in in SYNTAX_TREE Fix a number of bugs in SyntaxTree and SyntaxTreeCode Oct 23, 2022
Copy link
Contributor

@zickgraf zickgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort! I have run all of my tests using this PR and there are no regressions :-)

@fingolfin fingolfin changed the title Fix a number of bugs in SyntaxTree and SyntaxTreeCode Fix a number of bugs in SyntaxTree and SyntaxTreeCode Oct 27, 2022
@fingolfin fingolfin merged commit 7905d48 into gap-system:master Oct 27, 2022
@ChrisJefferson ChrisJefferson deleted the fix-syntax-tree branch December 18, 2023 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gapdays2022-summer Issues and PRs that arose at https://www.gapdays.de/gapdays2022-summer kind: bug Issues describing general bugs, and PRs fixing them release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault when getting syntax tree of function with nested sublist extraction of level 3 (or more)
3 participants