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

internal: remove obsolete nkExprColonExpr detection #808

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jul 20, 2023

Summary

Remove detection of nkExprColonExpr nodes in the context of tuple,
array, and object construction expressions in the code generators. The
ASTs reaching the code generators are expected to have a specific shape;
violations thereof need to be treated as internal errors and should
not be silently supported.

Details

The AST coming out of astgen does not contain nkExprColonExpr nodes
in nkTupleConstr trees, so the detection for them in
ccgexprs.genTupleConstr and vmgen.genTupleConstr is obsolete and
thus removed. Since jsgen.genTupleConstr is used for both normal
procedure-level code and constant initializers, it cannot have the
detection removed, as constant initializers do use nkExprColonExpr
nodes for named tuple constructions (nkTupleConstr).

In addition, the constant initializer AST that comes out of both
semfold or vmcompilerserdes:

  • doesn't have nkExprColonExpr nodes in nkBracket (array
    construction) trees
  • always has nkExprColonExpr nodes in nkObjConstr trees

Therefore, ccgexprs.getNullValueAux (code generation for constant
object constructions) can depend on the presence of nkExprColonExpr
nodes and ccgexprs.genConstSimpleList (code generation for constant
array constructions) on their absence.

Summary
=======

Remove detection of `nkExprColonExpr` nodes in the context of tuple,
array, and object construction expressions in the code generators. The
ASTs reaching the code generators are expected to have a specific shape;
violations thereof need to be treated as internal errors and should
not be silently supported.

Details
=======

The AST coming out of `astgen` does not contain `nkExprColonExpr` nodes
in `nkTupleConstr` trees, so the detection for them in
`ccgexprs.genTupleConstr` and `vmgen.genTupleConstr` is obsolete and
thus removed. Since `jsgen.genTupleConstr` is used for both normal
procedure-level code and constant initializers, it cannot have the
detection removed, as constant initializers do use `nkExprColonExpr`
nodes for named tuple constructions (`nkTupleConstr`).

In addition, the constant initializer AST that comes out of both
`semfold` or `vmcompilerserdes`:
- doesn't have `nkExprColonExpr` nodes in `nkBracket` (array
  construction) trees
- always has `nkExprColonExpr` nodes in `nkObjConstr` trees

Therefore, `ccgexprs.getNullValueAux` (code generation for constant
object constructions) can depend on the presence of `nkExprColonExpr`
nodes and `ccgexprs.genConstSimpleList` (code generation for constant
array constructions) on their absence.
@zerbina zerbina added compiler/backend Related to backend system of the compiler simplification Removal of the old, unused, unnecessary or un/under-specified language features. labels Jul 20, 2023
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.

oh nice, I imagine there is a fair number of such simplifications that can be taken advantage of in the backends.

@saem
Copy link
Collaborator

saem commented Jul 20, 2023

/merge

@github-actions
Copy link

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 Jul 20, 2023
Merged via the queue into nim-works:devel with commit 141f610 Jul 20, 2023
18 checks passed
@zerbina zerbina deleted the codegen-remove-expr-colon-expr-detection branch July 20, 2023 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/backend Related to backend system of the compiler simplification Removal of the old, unused, unnecessary or un/under-specified language features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants