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: less generic-expression workarounds #821

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jul 31, 2023

Summary

Prevent expressions-depending-on-unresolved-type-variables passed to
tryConstExpr from reaching into the compile-time evaluation machinery.
This allows for removing multiple workarounds from mirgen and vmgen.

Details

Before tryConstExpr passes the expression to evalConstExpr, it now
first checks whether the expression either contains unresolved generic
parameters or is an unresolved type-parameter-lookup (e.g., T.param).
If either is the case, nil (which signals that the expression cannot
be evaluated at compile-time) is returned without passing the
expression to evalConstExpr.

While this approach is fundamentally also a workaround (expressions
containing unresolved generic parameters shouldn't be passed to
tryConstExpr in the first place), it at least prevents unresolved
expressions from reaching into transf, mirgen, and vmgen.

mirgen now doesn't have to push unresolved generic parameters or
type-parameter-lookups as mnkLiterals through the MIR phase, and
vmgen doesn't have to special-case them. More generally, vmgen can
now treat unexpected nodes reaching it as a defect (via unreachable).

Since vmGenDiagCodeGenUnexpectedSym and vmGenDiagCannotGenerateCode
are now unused, they are, together with everything related to them,
removed.

@zerbina zerbina added refactor Implementation refactor compiler/sem Related to semantic-analysis system of the compiler compiler/backend Related to backend system of the compiler labels Jul 31, 2023
@zerbina zerbina added this to the MIR phase milestone Jul 31, 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.

Wow, it's surprising how much that code proliferated.

@saem
Copy link
Collaborator

saem commented Jul 31, 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 31, 2023
Merged via the queue into nim-works:devel with commit f02934a Jul 31, 2023
@zerbina zerbina deleted the less-generic-expression-workarounds branch August 6, 2023 21:28
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 compiler/sem Related to semantic-analysis system of the compiler refactor Implementation refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants