You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
allow constants which can be set at compilation time, instead of current status quo (either in the source code or via immutables). this is similar to the -D flag in C/C++.
Motivation
currently, runtime constants can only be set in the source code, or via the immutables mechanism (set at deploy time). however, this blocks a whole class of optimizations which could be done if we had access to the immutables values earlier. here is an example which must currently be done with immutables (but cannot be optimized because the immutable value is only known at deploy-time):
N: immutable(uint256)
@deploydef __init__(n: uint256):
assert n <3
N = n
@externaldef foo(x: uint256):
if N ==0:
return x
if N ==1:
return x +5if N ==2:
return x *9
Specification
allow constant() values to be declared without specification, e.g.
N: constant(uint256)
if run from the CLI, the constant value must be included with vyper -D N=<value> (otherwise, the compiler should complain with something like "ConstantNotSpecified").
Simple Summary
allow constants which can be set at compilation time, instead of current status quo (either in the source code or via immutables). this is similar to the
-D
flag in C/C++.Motivation
currently, runtime constants can only be set in the source code, or via the immutables mechanism (set at deploy time). however, this blocks a whole class of optimizations which could be done if we had access to the immutables values earlier. here is an example which must currently be done with immutables (but cannot be optimized because the immutable value is only known at deploy-time):
Specification
allow
constant()
values to be declared without specification, e.g.if run from the CLI, the constant value must be included with
vyper -D N=<value>
(otherwise, the compiler should complain with something like "ConstantNotSpecified").Backwards Compatibility
backwards compatible
References
https://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Preprocessor-Options.html
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: