-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Skip building subtrees for builtin derives #15251
Conversation
I'm not sure about this. When we implement cfg stripping for fields/variants (#8434), the expanders will need a way to ignore some of them after this PR. I guess we can do something like "if |
Oh that's something we should have a test for at least (cfg usage in a builtin derive).
I think this is an assumption we can make, the tokenmap will exactly contain entries for uncensored tokens in the input (and if that changes, we can always easily revert this change here I think). The current censoring we have for attributes is in general kind of broken and only partially works. I would expect us to have some other form of censoring in the future and if that doesn't work with this approach here we can again just revert this (the diff here is bigger because I cleaned up something unrelated afterwards). Another part of what drives the change here as well is my token map rewrite tbh, reducing the usages of token trees and the like makes my life a bit simpler there 😅 (though only very slightly tbf) I just find it very unsightly that we re-parse item subtrees back into ast nodes just to fetch some things from them, given these are builtins there is no reason for us to convert them here again. |
That's fair. One thing I'm a bit worried/don't really understand if we can make the assumption is this kind of code,
Yeah I definitely understand the motivation here. It's really unfortunate that macros operate on tts, which is based on rustc internal and pretty much foreign to us so we gotta go back and forth 😢 |
Ye that's just a safety hatch, if this is hit not much should suffer from it in theory, and it should disappear fully after my macro map rewrite (in theory, though I still have to adjust my design unfortunately) |
That resolves all of my concerns, thanks! I'm really looking forward to the token map rewrite 🙂 |
@bors r+ |
☀️ Test successful - checks-actions |
Turns out I missed something crucial here making this a very bad idea! We now have a dependency edge from |
fix: Remove accidental dependency between `parse_macro_expansion` and `parse` Turns out my idea from #15251 causes all builtin derive expansions to obviously rely on the main parse, meaning the entire `macro_arg` layer becomes kind of pointless. So this reverts that PR again.
This is a waste of resources, we go from node to subtree just to go from subtree to node in the expander impl. We can skip the subtree building and only build the tokenmap instead.