-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add pub attribute for struct fields #232
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
It would be great to support modifying the struct fields inside the methods, as this pub
is also about a whitelist to controlling the values of a struct.
Maybe we can create another PR to implement the mut [arg]
as described here.
fn main(pub beds: Field) { | ||
let mut room = Room {beds: 2, size: 10}; | ||
room.beds = beds; // allowed | ||
room.size = 5; // not allowed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just test the negative case here. Then the positive tests should cover the rest.
src/inputs.rs
Outdated
@@ -140,7 +140,7 @@ impl<B: Backend> CompiledCircuit<B> { | |||
|
|||
// parse each field | |||
let mut res = vec![]; | |||
for (field_name, field_ty) in fields { | |||
for (field_name, field_ty, attribute) in fields { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attribute
is not used, so would be better _attribute
src/name_resolution/context.rs
Outdated
@@ -150,7 +150,7 @@ impl NameResCtx { | |||
self.resolve(module, true)?; | |||
|
|||
// we resolve the fully-qualified types of the fields | |||
for (_field_name, field_typ) in fields { | |||
for (_field_name, field_typ, attribute) in fields { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@mimoo may want another pass |
Attempts to resolve #224
Here is my approach:
I introduced a new component
Option<Attribute>
tofields
in order to make use of the already definedPub
attribute that is used for public inputs.The tricky part was to check whether we are inside a structs method or not. For that I introduced a new variable inside
TypedFnEnv
calledcurrent_fn_kind
that keeps track of the function we are in. This is further utilized in the type checker.