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 a user-specified relative ordering for attributes #6271

Closed
jfecher opened this issue Oct 10, 2024 · 1 comment
Closed

Add a user-specified relative ordering for attributes #6271

jfecher opened this issue Oct 10, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Oct 10, 2024

Problem

Users cannot control which order their attributes run leading to issues such as #6143

Happy Case

We add two new attributes #[run_after(f)] and #[run_before(f)] which accept a function f as an argument and ensure that the attribute function they're applied to is run after or before the attribute function f.

For example:

#[run_after(derive)]
comptime fn check_if_eq_is_implemented(s: StructDefinition) {
    let eq = quote { Eq }.as_trait_constraint();
    assert(s.as_type().implements(eq));
}

We could also have a default step so that attributes can run before other attributes by default. If derive used this for example then there'd be no need for other attributes to have to know to run after it:

#[run_before(_)]
comptime fn derive(s: StructDefinition, traits: [TraitDefinition]) -> Quoted { ... }

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 Oct 10, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 10, 2024
@jfecher
Copy link
Contributor Author

jfecher commented Oct 24, 2024

We decided to go with source ordering instead for greater predictability and easier debugging of attributes

@jfecher jfecher closed this as completed Oct 24, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Oct 24, 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.

1 participant