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

VIP: compile-time parametrizable constants #3944

Open
charles-cooper opened this issue Apr 13, 2024 · 0 comments
Open

VIP: compile-time parametrizable constants #3944

charles-cooper opened this issue Apr 13, 2024 · 0 comments

Comments

@charles-cooper
Copy link
Member

charles-cooper commented Apr 13, 2024

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):

N: immutable(uint256)

@deploy
def __init__(n: uint256):
    assert n < 3
    N = n

@external
def foo(x: uint256):
    if N == 0:
        return x
    if N == 1:
        return x + 5
    if 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").

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant