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

allow inlining of constant constructor variables #6586

Closed
rainbreak opened this issue Apr 24, 2019 · 3 comments
Closed

allow inlining of constant constructor variables #6586

rainbreak opened this issue Apr 24, 2019 · 3 comments

Comments

@rainbreak
Copy link
Contributor

Currently the constructor does not respect the constant keyword and occupies storage slots unnecessarily.

contract C {
    uint constant x;
    constructor(uint x_) public {
        x = x_;
    }
    function get() public view returns (uint) {
        return x;
    }
}

Here, the function get will sload x from the first storage slot. However x could have instead been inlined into the contract code, avoiding using up any slots and avoiding a relatively expensive sload. This would be important in contracts that use delegatecall and wish to avoid any runtime dependence on their own storage.

@chriseth
Copy link
Contributor

This code does not compile for me and it actually should not occupy any storage slot. Is this intended as a bug report or a feature request?

@chriseth
Copy link
Contributor

This might be a duplicate of #3835

@rainbreak
Copy link
Contributor Author

Sorry, yes this is a duplicate. Also of #6561

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

2 participants