-
Notifications
You must be signed in to change notification settings - Fork 1.8k
internal: Rewrite attribute handling #20316
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
base: master
Are you sure you want to change the base?
Conversation
e69ea8b
to
b2ecf39
Compare
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.
You're killing me with these big PRs 😬 ..
I have some thought to note down on the EditionedFileId
stuff but that will have to wait for later
@@ -64,6 +65,58 @@ impl ModPath { | |||
ModPath { kind, segments: SmallVec::new_const() } | |||
} | |||
|
|||
pub fn from_tokens( |
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.
Ugh now we have 3 ways to parse these ...
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.
And all subtly different... Yeah I agree.
// FIXME: We probably should use this in more places. | ||
/// This is used to avoid interning the whole `AttrDefId`, so we intern just modules and not everything. | ||
#[salsa_macros::interned(debug, no_lifetime)] | ||
pub struct InternedModuleId { | ||
pub loc: ModuleId, | ||
} |
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.
Sounds like #20001
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.
Yeah, except using interneds and not tracked structs, and being localized to attrs. At least currently, analysis doesn't create this type, only IDE needs to resolve attributes on modules, so the memory impact is low.
#20001 is that right path forward though.
/// This can be empty if the path is not of 1 or 2 segments exactly. | ||
pub segments: ArrayVec<SyntaxToken, 2>, | ||
pub range: TextRange, | ||
pub is_test: bool, |
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.
This doesn't really make sense, we cannot know whether this is the test attribute at this layer, we have no name resolution here after all?
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.
I have a FIXME for this in hir-def/src/attrs.rs. The general point is that yes, we need proper name resolution for these, but it's hard to do. The reason I put this in Meta
is because macros often expand to the full name ::core::prelude::vX::test
, which is longer than 2 segments. I could make segments
4-length, but that may somewhat hurt perf. I don't feel strongly about that though.
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.
I added a FIXME here too.
Sorry! This one could probably be broken (at least to a rewrite of ast-based expand_cfg_attr then to flags-based attrs), but I didn't thought about that until it was too late... |
b2ecf39
to
fccfb8c
Compare
Basically, we switch to expanding cfg_attr in AST form, filter irrelevant attributes from the item tree, and move hir-def attributes (non-item-tree) to be flag-based. The main motivation is memory usage, although this also simplifies the code, and fixes some bugs around handling of `cfg_attr`s.
fccfb8c
to
c42bd8d
Compare
Should we wait with this until the trait solver lands? It looks like it will cause a lot of conflicts |
The changes in hir-ty here are minimal, but I can wait until the switch to the next trait solver lands. |
Basically, we switch to expanding cfg_attr in AST form, filter irrelevant attributes from the item tree, and move hir-def attributes (non-item-tree) to be flag-based.
The main motivation is memory usage, although this also simplifies the code, and fixes some bugs around handling of
cfg_attr
s.This saves 120mb on
analysis-stats .
🎉Fixes #10110 and maybe some other issues too.