-
Notifications
You must be signed in to change notification settings - Fork 187
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
Const fields #192
Comments
I am trying to solve this and I was going through the codebase to understand the implementation. I have figured out the following steps. I have a few doubts. If you can clear those it will help me speed up.
|
Hi @rahulbansal16, thank you very much for reaching out. So yeah, as you noted, The grammar is somewhat incorrect, though, in that we can't assign a value to a field, which is of course what we need to do in the case of a constant field. Currently, we have:
when we should have:
Making this change to the grammar file, updating the parser, and then creating a test to make sure a statement like |
Thanks @g-r-a-n-t I am making changes to add the feature. The PR is #196 I was trying to run the test locally on the master branch and I got the following errors for the tests for the test_parser.rs file.
I am using a windows system and I am not doing a full build. |
Sorry to hijack the issue but..Any chance you'd be interested to add CI coverage + Release builds for Windows? I tried to add Windows to our CI suite a while back in #64 but failed to get it to work. None of us is on a windows machine so having someone familiar with windows looking into it would be very much welcome :) |
No worries @cburgdorf, I can start looking into it after I am done with this issue. |
@cburgdorf I am able to download the boost and updating the path. I am getting link errors. I tried the multiple version of the boost and the error is for the boost version 1.69.0 refer to the build logs for more details.
Do you have any idea about fixing them? |
I was also trying with the boost version of 1.73.0 and the error in the build logs is
I have few approaches that I am trying. Here Have you encountered these errors before? |
@rahulbansal16 Let's discuss this over in #198 I have a rough idea regarding the |
I'm going to pick this up since constants are quite important and should be part of our I just want to make sure I remember correctly what we discussed about constants already. As I understand, we are planning to have three different ways to create them.
Open question: would this actually need to be read through
Open question: would this actually need to be read/write through Do I have these three cases right? Maybe there's value to not use a different keyword for case 3? My immediate reaction would be that |
It might also be possible to compile base type const values in-line as opposed to reading them from data, as a means to save gas. This would make compilation more complicated, tho, since const values set during initialization would need to be managed using the setimmutable function, which of course relies on data objects.
What is meant by "declaration time"? If the value is set in the the init function, then we would overwrite the compiled value during initialization. But if the value is not set in the init function, then we would leave it alone. So the stages with regard to const values would be:
Yes, but to be more specific I'd say: Contracts use the
Hard to say, but I don't think whether or not it's held in contract storage is the deciding factor. I think it's more a question of what looks the best and is consistent with other rules, which requires some more thought.
I think all three should have the same name. We've also discussed having an |
hmm.. or maybe the default mutability of a contract field should be immutable (aka const), which gets into the problem of not having a |
After thinking about it more, I believe the relevant question is, is this part of a contract instance? I believe it should be, as the following contract Foo:
const BAR: u8
pub fn __init__(bar: u8):
BAR = bar
# return value of BAR (which takes no args) is not known at compile-time
pub fn misleading_pure() -> u8:
return BAR This on the other hand should be totally ok. const BAR: u8 = 26
contract Foo:
pub fn actual_pure() -> u8:
return BAR |
Good point!
I meant a
Yep, makes sense 👍
Yes, after thinking about it a bit more I think accessing a |
Another question that appeared to me is how we want to deal with scoping rules. E.g. would this be legal:
What about this:
My current thinking is that we should be strict and not allow shadowing constants with local variables since it can make contracts harder to audit. |
I removed the |
What is wrong?
There is no way for a user to specify that a field is constant.
This would allow for significant gas saving, since we can store constant values in bytecode, instead of storage.
How can it be fixed
Do something similar to the work done on static strings. The syntax should look something like this:
const MINIMUM_LIQUIDITY: u256 = 1000
The text was updated successfully, but these errors were encountered: