-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Forbid outer variables in const evaluations #7522
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
base: master
Are you sure you want to change the base?
Conversation
|
👍 |
CodSpeed Performance ReportMerging #7522 will not alter performanceComparing Summary
|
PR SummaryPrevents invalid constant evaluation that captured outer-scope variables and strengthens negative test coverage for array bounds.
Written by Cursor Bugbot for commit 1284e88. This will update automatically on new commits. Configure here. |
This reverts commit 3599c06.
test/src/e2e_vm_tests/test_programs/should_fail/const_eval_outer_vars/stdout.snap
Outdated
Show resolved
Hide resolved
|
Any reason to call this "outer variables"? I was thinking we were forbidding variable declarations "outside" of the const expression, even other const expressions. Why not something like "forbid non-const variables" or something to that effect... |
I am not particularly happy with the term "outer" either, but that's the best I figured out so far 😄 Suggestions are welcome! The reason for "outer" was that they are coming from a lexical scope(s) outer to the const evaluated expression itself. In other words, they are not declared inside of the expression being const evaluated. Also, we strictly distinguish between variables and constants, so I don't see that the "outer variable" would imply constants as well. What would be "non-const variables"? Like, immutable variables? Note that we ban both mutable and immutable variables because we don't know even if immutable are changed between the definition and usage in const. Having "immutable" e.g. |
Description
This PR fixes #7520 by forbidding const evaluation of expressions that contain variables from outer scope. Forbidding outer variables also partially tackles #7521 but also exposes an issue of SROA panicking on out of bounds array access. We will treat this issue fully in a separate PR.
This PR is a prerequisite for #7489 because optimizing initialization of aggregates requires valid const evaluation for certain cases.
Checklist
Breaking*orNew Featurelabels where relevant.