-
Notifications
You must be signed in to change notification settings - Fork 93
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
Attribute Macros on Items #528
Conversation
It looks good to me, I've merged your changes onto main after merging #526 since they both touch on the same stuff. In the end I'll squash everything as it's merged anyways, so history doesn't matter. I'm just keeping it so we can reference it. |
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.
Looks good to me. Some missing pieces and possible meta conflict, but all the infrastructure to run the macros seem to be there. Good job!
well this broke builtin attributes such as Would it be possible to actually impllement them as attribute macros? Or should we somehow skip them and keep them arround though I'm not sure how that would work best. |
Skip over attributes you can't process until the end, then error if any unprocessed attributes remain? |
So I don't error on unknown attributes, but just ignore them so that the item handler would error later. |
Hm, I'm not entirely following. What is the problem right now? I'll also look over the PR later, so maybe I'll better understand what's going on then 😅 |
So I'm really not sure how to best implement this, e.g. in this: #[some_macro]
#[test]
#[another_macro]
fn foobar() {} This should expand Currently I use In my current setup this is actually reasonably possible, that is, because I haven't implemented lenient import resolution i.e.:
is currently an error. To support the order agnostic usage, I would need to:
It is not possible to skip the top attribute if unknown and expand the ones below, because an unknown attribute might remove said attributes which would have been erroneously expanded. From that, I think it would be best to filter built-in attributes directly, (maybe directly in I can as an MVP support attributes that are resolved in order, i.e., only if the import was before the attribute, and just skip unknown attributes and leave dealing with them to |
This shouldn't be an issue if you keep any attributes which you can't expand and hand it to downstream steps, which will then either process them or error. But due note that Let's say Does this make sense?
The type of import resolution currently implemented simply means that macros are "evaluated last". So what you need to do is look over available items once - and if they contain attributes that could be expanded by a macro put them in the queue to be expanded after all other items. That way uses (which are not production of macros) are always expanded first. And the rest of evaluation is order-dependent from top-to bottom as they are added to the queue. So to determine whether something should be deferred or not, I think some kind of first pass needs to be performed to test if there are attributes that need to be expanded. |
that does make it more easily achievable. I'll look into it! |
I'm nursing a cold right now, will get into it when I'm 100% again! |
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.
Thank you, this is a great start. Only the Name
issue (I think).
Thank you! |
rune::attribute_macro