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

Add pub attribute for struct fields #232

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bufferhe4d
Copy link
Contributor

Attempts to resolve #224

Here is my approach:

I introduced a new component Option<Attribute> to fields in order to make use of the already defined Pub 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 called current_fn_kind that keeps track of the function we are in. This is further utilized in the type checker.

Copy link
Collaborator

@katat katat left a 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
Copy link
Collaborator

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 {
Copy link
Collaborator

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

@@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@katat
Copy link
Collaborator

katat commented Nov 14, 2024

@mimoo may want another pass

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

Successfully merging this pull request may close these issues.

Allow pub attribute for struct fields
2 participants