-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Propagate purity information for member access to foreign pure variables #12928
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
Propagate purity information for member access to foreign pure variables #12928
Conversation
test/libsolidity/semanticTests/constants/define_constants_with_external_constant_member_var.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/semanticTests/constants/define_constants_with_external_constant_member_var.sol
Outdated
Show resolved
Hide resolved
51b6878
to
8b4dcdb
Compare
Btw, where does the "constant variable evaluation & substitution" step happen? I wonder if this would affect it, since we are allowing member access in rhs of constant variables now. |
Looking deeper, we were handling this correctly for file-level constant because of this line. Member access is similar to identifier, so this should give more confidence to this PR. |
See |
Hmm I did check all the usages but none of them is doing what I was looking for. Then I dumped the IR and things make sense now. At least at the IR level, it seems that each constant (or all?) variable is turned into a function, and the initialization expression is linearized into IR statements in the function body. I assume constant propagation will clean things up further? Regardless, this PR shouldn't affect things there. |
8b4dcdb
to
c5ce9c0
Compare
Rebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Tests need to be a bit stronger (see my suggestions) but other than that it's a nice enhancement that users will probably appreciate!
Also, please add a changelog entry.
test/libsolidity/syntaxTests/constants/cyclic_dependency_file_constants.sol
Show resolved
Hide resolved
test/libsolidity/syntaxTests/constants/define_constants_with_external_constant_member_var.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/syntaxTests/constants/cyclic_dependency_file_constants.sol
Show resolved
Hide resolved
test/libsolidity/syntaxTests/constants/define_constants_with_external_constant_member_var.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/syntaxTests/constants/define_constants_with_external_constant_member_var.sol
Outdated
Show resolved
Hide resolved
c5ce9c0
to
6924460
Compare
Please also add some tests where the constants are used as array lengths of statically-sized arrays, both as forward and as backward references. |
I think this is more involved than expected. The logic chain is as follows:
I think this reveals a larger issue than this PR is concerned -- We probably want to augment Currently the compilation stack is a bit awkward for constant evaluation, i.e.,
I think the logics in parenthesis should be reversed...? |
a880a6a
to
223adaf
Compare
Rebase. |
Sorry, I should have clarified: Please add tests so that we see that it does not catastrophically fail. I did not mean to implement this feature for the constant evaluator. And you are right, the constant evaluator is not at the right place, we have a larger issue planned to extend it. |
Got it. Done. |
223adaf
to
dae3218
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing.
It's minor enough that I'm approving this already but I really think these tests need to be separate.
test/libsolidity/syntaxTests/constants/constant_with_dependencies_on_constants.sol
Outdated
Show resolved
Hide resolved
dae3218
to
386fb5f
Compare
58d9dc4
to
484df3f
Compare
5ba2d9c
to
4a0acfa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good. I'd merge this already but we have just released 0.8.15 so the changelog entry needs to be moved.
4a0acfa
to
3b2c6de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, partly based on @cameel's earlier approval.
Fixes #12927.