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

feat: Add a relative ordering for attributes #6319

Closed
wants to merge 4 commits into from
Closed

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Oct 22, 2024

Description

Problem*

Resolves #6271

Summary*

Wanted to get this before the discussion tomorrow for reference.

Adds a user-defined relative ordering for attributes which orders attributes by annotations placed by the library author of the attribute. This is done with the new #[run_before(attr)] and #[run_after(attr)] attributes which accept another attribute as an argument. Internally, the compiler builds a graph for attributes and topologically sorts it. Then the compiler sorts each attribute usage according to that topological ordering.

TODO:

  • Detect graph for cycles, we can use the same method of our existing cycle detection for the dependency graph
  • Some miscellaneous errors that are left as todo!()s in the code
  • Insert CollectedItems into the program after each attribute group.
    • This is a bit of an interesting case since we should still pool results of each derive to avoid errors there.
    • This also means attributes of the same name will always run in the same grouping. So derived traits are not found by get_trait_impl #6143 would still exist in the case of one attribute applied to several different items, checking for past work. Different attributes will always be on different steps however.

Additional Context

If needed, users can still override an attribute's order by making their own wrapper for the attribute

#[run_after(foo)]
comptime fn my_wrapper(s: StructDefinition) -> Quoted {
    library_attribute(s)
}

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher
Copy link
Contributor Author

jfecher commented Oct 24, 2024

Superseded by #6326

@jfecher jfecher closed this Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add a user-specified relative ordering for attributes
1 participant