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 extra attributes to functions and structs #5874

Closed
jfecher opened this issue Aug 30, 2024 · 0 comments · Fixed by #5945
Closed

Add extra attributes to functions and structs #5874

jfecher opened this issue Aug 30, 2024 · 0 comments · Fixed by #5945
Assignees
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Aug 30, 2024

Problem

Feature request comes from a slack request.

There is no way to add new attributes to functions or structs while metaprogramming

Happy Case

We could add the functions:

impl FunctionDefinition {
    fn add_attribute<N>(self, attribute: str<N>) {}
}

impl StructDefinition {
    fn add_attribute<N>(self, attribute: str<N>) {}
}

The example given to me was to add #[abi(tag)] or #[recursive].
Using strings is a bit awkward here but attributes internally remain as strings until they're later parsed so using Quoted would also be awkward. Using just strings prevents users from quoting/unquoting code to create these attributes though.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@jfecher jfecher added the enhancement New feature or request label Aug 30, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Aug 30, 2024
@asterite asterite self-assigned this Sep 5, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 5, 2024
# Description

## Problem

Part of #5874

## Summary

This is fun 😄 


![fn-add-attribute](https://github.com/user-attachments/assets/3fa5bf97-b7f1-4c85-8c54-4198ee35efeb)

## Additional Context

I'll add similar methods to `StructDefinition` and `Module` in follow-up
PRs.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
github-merge-queue bot pushed a commit that referenced this issue Sep 5, 2024
…#5945)

# Description

## Problem

Resolves #5874

## Summary

## Additional Context

I originally wanted to test this by adding `abi(...)` to a struct and
seeing that it errors if that struct appears in a signature but is
outside of a contract, but... function parameters are type-checked
before that (I think). So another way to test this is to also have
`has_named_attribute`, so I added that too.

Side note: maybe adding an attribute to a function/struct should
eventually invoke the associated function, if there's any, but we can
probably try to do that in a separate PR, and only if really needed.

## Documentation

Check one:
- [ ] No documentation needed.
- [x] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants