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

sem: keep shape of array constructors in typed AST #1340

Merged
merged 4 commits into from
Jun 8, 2024

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jun 8, 2024

Summary

Explicit indices in array constructors now stay in the AST after
typing. Since macros are able to observe this, this change is a
breaking change.

Details

Keeping the explicit indices is also necessary for being able to
retype the AST after it was typed once (without the index, array
constructors for arrays not starting at zero would have a
different type afterwards).

Instead of dropping the explicit index together with the parent
nkExprColonExpr node, both are kept by semArrayConstr, and then
later discarded by semfold (during constant evaluation) and transf,
where they are no longer needed.

zerbina added 4 commits June 8, 2024 17:28
Don't drop the `nkExprColonExpr` nodes during analysis of array
constructions, so that macros can inspect the full AST and that
the typed AST can be properly re-analyzed.
Folding is one case where the change in `nkBracket` syntax shows up.
The output of folding still expects bracket trees without the index
parts, so the `nkExprColonExpr` nodes are simply skipped.
The index part is not relevant beyond `transf`, so `transf` can simply
drop it. This is also necessary, since `nkExprColonExpr` in `nkBracket`
expression is not something that code operating on transformed AST
expects.
@zerbina zerbina added the compiler/sem Related to semantic-analysis system of the compiler label Jun 8, 2024
@zerbina zerbina requested a review from saem June 8, 2024 18:31
@zerbina
Copy link
Collaborator Author

zerbina commented Jun 8, 2024

While #1192 is not my focus at the moment, the change was easy enough that I figured I implement it right away.

Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

looks good to me. outside of normalization, which this wasn't, i think preserving the shape is the way to go.

@saem
Copy link
Collaborator

saem commented Jun 8, 2024

/merge

Copy link

github-actions bot commented Jun 8, 2024

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue Jun 8, 2024
Merged via the queue into nim-works:devel with commit b08c8f5 Jun 8, 2024
31 checks passed
@zerbina zerbina deleted the sem-keep-array-constr-shape branch June 9, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/sem Related to semantic-analysis system of the compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants