-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Constant expression evaluation at compile time #3157
Comments
I, by the way, vote for finally starting with this at least soonish... |
Should we consider C++-style literals and use them in expressions, such as |
Going forward I'd very much like for this to work even for user-defined pure functions, e.g.
Or even stuff like
Not in a first step for sure, but eventually... |
Is it in any way possible to compile this via yul and run it through an interpreter? Then we would at least not have to re-implement everything. |
Why not? |
We should definitely allow compile-time evaluation of user-defined pure functions. |
Some things that we might want to explicitly add to the list of stuff that should be evaluated a compilation time:
|
Another case that might be of practical interest, brought up by @nventuro:
This is useful in |
Note that mine was just a toy example - a real use case would have non-constant constructor arguments. I'm not sure there's many use cases for the one you mention. |
ok, right. We should still have things like this handled as a part of this mechanism but I guess you're right, constant arguments for this are likely not very common. |
Variables can be declared
constant
which allows:keccak256
,ecrecover
,sha256
,ripemd160
,addmod
,mulmod
,new
(for creating objects only, such as arrays)Currently whenever a constant expression is used, the entire expression is placed into the output. This is of course reduced/optimised, but that is mostly restricted to operations on literals and some edge cases.
We should consider one or more of the following:
constant
into two,constant
which only allows literals andconstexpr
which allows more complex expressionsecrecover
,sha256
,ripemd160
)constant
orconstexpr
in a VM during compilation time and use the result only (this VM could be a subset of the EVM, since many features are not required)Obviously 2 and 3 contradict eachother. I would opt for 2. unless 4. is implemented and then 3. could be allowed.
Somewhat relevant is #715.
The text was updated successfully, but these errors were encountered: