Skip to content

Commit 4f1a07c

Browse files
committed
Remove ast ids from item tree mod items
1 parent e39c1e9 commit 4f1a07c

File tree

4 files changed

+121
-161
lines changed

4 files changed

+121
-161
lines changed

src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ impl ItemTree {
212212
SmallModItem::Trait(_) => traits += 1,
213213
SmallModItem::Impl(_) => impls += 1,
214214
SmallModItem::MacroRules(_) => macro_rules += 1,
215+
SmallModItem::MacroCall(_) => macro_calls += 1,
215216
_ => {}
216217
}
217218
}
218219
for item in self.big_data.values() {
219220
match item {
220221
BigModItem::Mod(_) => mods += 1,
221-
BigModItem::MacroCall(_) => macro_calls += 1,
222222
_ => {}
223223
}
224224
}
@@ -246,11 +246,14 @@ struct ItemVisibilities {
246246
enum SmallModItem {
247247
Const(Const),
248248
Enum(Enum),
249+
ExternBlock(ExternBlock),
249250
Function(Function),
250251
Impl(Impl),
251252
Macro2(Macro2),
253+
MacroCall(MacroCall),
252254
MacroRules(MacroRules),
253255
Static(Static),
256+
Struct(Struct),
254257
Trait(Trait),
255258
TraitAlias(TraitAlias),
256259
TypeAlias(TypeAlias),
@@ -259,11 +262,8 @@ enum SmallModItem {
259262

260263
#[derive(Debug, Clone, Eq, PartialEq)]
261264
enum BigModItem {
262-
ExternBlock(ExternBlock),
263265
ExternCrate(ExternCrate),
264-
MacroCall(MacroCall),
265266
Mod(Mod),
266-
Struct(Struct),
267267
Use(Use),
268268
}
269269

@@ -370,23 +370,23 @@ macro_rules! mod_items {
370370

371371
mod_items! {
372372
ModItemId ->
373-
Use in big_data -> ast::Use,
373+
Const in small_data -> ast::Const,
374+
Enum in small_data -> ast::Enum,
375+
ExternBlock in small_data -> ast::ExternBlock,
374376
ExternCrate in big_data -> ast::ExternCrate,
375-
ExternBlock in big_data -> ast::ExternBlock,
376377
Function in small_data -> ast::Fn,
377-
Struct in big_data -> ast::Struct,
378-
Union in small_data -> ast::Union,
379-
Enum in small_data -> ast::Enum,
380-
Const in small_data -> ast::Const,
378+
Impl in small_data -> ast::Impl,
379+
Macro2 in small_data -> ast::MacroDef,
380+
MacroCall in small_data -> ast::MacroCall,
381+
MacroRules in small_data -> ast::MacroRules,
382+
Mod in big_data -> ast::Module,
381383
Static in small_data -> ast::Static,
384+
Struct in small_data -> ast::Struct,
382385
Trait in small_data -> ast::Trait,
383386
TraitAlias in small_data -> ast::TraitAlias,
384-
Impl in small_data -> ast::Impl,
385387
TypeAlias in small_data -> ast::TypeAlias,
386-
Mod in big_data -> ast::Module,
387-
MacroCall in big_data -> ast::MacroCall,
388-
MacroRules in small_data -> ast::MacroRules,
389-
Macro2 in small_data -> ast::MacroDef,
388+
Union in small_data -> ast::Union,
389+
Use in big_data -> ast::Use,
390390
}
391391

392392
impl Index<RawVisibilityId> for ItemTree {
@@ -425,7 +425,6 @@ impl Index<RawVisibilityId> for ItemTree {
425425
#[derive(Debug, Clone, Eq, PartialEq)]
426426
pub struct Use {
427427
pub(crate) visibility: RawVisibilityId,
428-
pub(crate) ast_id: FileAstId<ast::Use>,
429428
pub(crate) use_tree: UseTree,
430429
}
431430

@@ -490,42 +489,36 @@ pub struct ExternCrate {
490489
pub name: Name,
491490
pub alias: Option<ImportAlias>,
492491
pub(crate) visibility: RawVisibilityId,
493-
pub ast_id: FileAstId<ast::ExternCrate>,
494492
}
495493

496494
#[derive(Debug, Clone, Eq, PartialEq)]
497495
pub struct ExternBlock {
498-
pub ast_id: FileAstId<ast::ExternBlock>,
499496
pub(crate) children: Box<[ModItemId]>,
500497
}
501498

502499
#[derive(Debug, Clone, Eq, PartialEq)]
503500
pub struct Function {
504501
pub name: Name,
505502
pub(crate) visibility: RawVisibilityId,
506-
pub ast_id: FileAstId<ast::Fn>,
507503
}
508504

509505
#[derive(Debug, Clone, Eq, PartialEq)]
510506
pub struct Struct {
511507
pub name: Name,
512508
pub(crate) visibility: RawVisibilityId,
513509
pub shape: FieldsShape,
514-
pub ast_id: FileAstId<ast::Struct>,
515510
}
516511

517512
#[derive(Debug, Clone, Eq, PartialEq)]
518513
pub struct Union {
519514
pub name: Name,
520515
pub(crate) visibility: RawVisibilityId,
521-
pub ast_id: FileAstId<ast::Union>,
522516
}
523517

524518
#[derive(Debug, Clone, Eq, PartialEq)]
525519
pub struct Enum {
526520
pub name: Name,
527521
pub(crate) visibility: RawVisibilityId,
528-
pub ast_id: FileAstId<ast::Enum>,
529522
}
530523

531524
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -564,48 +557,40 @@ pub struct Const {
564557
/// `None` for `const _: () = ();`
565558
pub name: Option<Name>,
566559
pub(crate) visibility: RawVisibilityId,
567-
pub ast_id: FileAstId<ast::Const>,
568560
}
569561

570562
#[derive(Debug, Clone, Eq, PartialEq)]
571563
pub struct Static {
572564
pub name: Name,
573565
pub(crate) visibility: RawVisibilityId,
574-
pub ast_id: FileAstId<ast::Static>,
575566
}
576567

577568
#[derive(Debug, Clone, Eq, PartialEq)]
578569
pub struct Trait {
579570
pub name: Name,
580571
pub(crate) visibility: RawVisibilityId,
581-
pub ast_id: FileAstId<ast::Trait>,
582572
}
583573

584574
#[derive(Debug, Clone, Eq, PartialEq)]
585575
pub struct TraitAlias {
586576
pub name: Name,
587577
pub(crate) visibility: RawVisibilityId,
588-
pub ast_id: FileAstId<ast::TraitAlias>,
589578
}
590579

591580
#[derive(Debug, Clone, Eq, PartialEq)]
592-
pub struct Impl {
593-
pub ast_id: FileAstId<ast::Impl>,
594-
}
581+
pub struct Impl {}
595582

596583
#[derive(Debug, Clone, PartialEq, Eq)]
597584
pub struct TypeAlias {
598585
pub name: Name,
599586
pub(crate) visibility: RawVisibilityId,
600-
pub ast_id: FileAstId<ast::TypeAlias>,
601587
}
602588

603589
#[derive(Debug, Clone, Eq, PartialEq)]
604590
pub struct Mod {
605591
pub name: Name,
606592
pub(crate) visibility: RawVisibilityId,
607593
pub(crate) kind: ModKind,
608-
pub ast_id: FileAstId<ast::Module>,
609594
}
610595

611596
#[derive(Debug, Clone, Eq, PartialEq)]
@@ -620,7 +605,6 @@ pub(crate) enum ModKind {
620605
pub struct MacroCall {
621606
/// Path to the called macro.
622607
pub path: Interned<ModPath>,
623-
pub ast_id: FileAstId<ast::MacroCall>,
624608
pub expand_to: ExpandTo,
625609
pub ctxt: SyntaxContext,
626610
}
@@ -629,15 +613,13 @@ pub struct MacroCall {
629613
pub struct MacroRules {
630614
/// The name of the declared macro.
631615
pub name: Name,
632-
pub ast_id: FileAstId<ast::MacroRules>,
633616
}
634617

635618
/// "Macros 2.0" macro definition.
636619
#[derive(Debug, Clone, Eq, PartialEq)]
637620
pub struct Macro2 {
638621
pub name: Name,
639622
pub(crate) visibility: RawVisibilityId,
640-
pub ast_id: FileAstId<ast::MacroDef>,
641623
}
642624

643625
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ impl<'a> Ctx<'a> {
168168
let name = strukt.name()?.as_name();
169169
let ast_id = self.source_ast_id_map.ast_id(strukt);
170170
let shape = adt_shape(strukt.kind());
171-
let res = Struct { name, visibility, shape, ast_id };
172-
self.tree.big_data.insert(ast_id.upcast(), BigModItem::Struct(res));
171+
let res = Struct { name, visibility, shape };
172+
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Struct(res));
173173

174174
Some(ast_id)
175175
}
@@ -178,7 +178,7 @@ impl<'a> Ctx<'a> {
178178
let visibility = self.lower_visibility(union);
179179
let name = union.name()?.as_name();
180180
let ast_id = self.source_ast_id_map.ast_id(union);
181-
let res = Union { name, visibility, ast_id };
181+
let res = Union { name, visibility };
182182
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Union(res));
183183
Some(ast_id)
184184
}
@@ -187,7 +187,7 @@ impl<'a> Ctx<'a> {
187187
let visibility = self.lower_visibility(enum_);
188188
let name = enum_.name()?.as_name();
189189
let ast_id = self.source_ast_id_map.ast_id(enum_);
190-
let res = Enum { name, visibility, ast_id };
190+
let res = Enum { name, visibility };
191191
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Enum(res));
192192
Some(ast_id)
193193
}
@@ -198,7 +198,7 @@ impl<'a> Ctx<'a> {
198198

199199
let ast_id = self.source_ast_id_map.ast_id(func);
200200

201-
let res = Function { name, visibility, ast_id };
201+
let res = Function { name, visibility };
202202

203203
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Function(res));
204204
Some(ast_id)
@@ -211,7 +211,7 @@ impl<'a> Ctx<'a> {
211211
let name = type_alias.name()?.as_name();
212212
let visibility = self.lower_visibility(type_alias);
213213
let ast_id = self.source_ast_id_map.ast_id(type_alias);
214-
let res = TypeAlias { name, visibility, ast_id };
214+
let res = TypeAlias { name, visibility };
215215
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TypeAlias(res));
216216
Some(ast_id)
217217
}
@@ -220,7 +220,7 @@ impl<'a> Ctx<'a> {
220220
let name = static_.name()?.as_name();
221221
let visibility = self.lower_visibility(static_);
222222
let ast_id = self.source_ast_id_map.ast_id(static_);
223-
let res = Static { name, visibility, ast_id };
223+
let res = Static { name, visibility };
224224
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Static(res));
225225
Some(ast_id)
226226
}
@@ -229,7 +229,7 @@ impl<'a> Ctx<'a> {
229229
let name = konst.name().map(|it| it.as_name());
230230
let visibility = self.lower_visibility(konst);
231231
let ast_id = self.source_ast_id_map.ast_id(konst);
232-
let res = Const { name, visibility, ast_id };
232+
let res = Const { name, visibility };
233233
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Const(res));
234234
ast_id
235235
}
@@ -251,7 +251,7 @@ impl<'a> Ctx<'a> {
251251
}
252252
};
253253
let ast_id = self.source_ast_id_map.ast_id(module);
254-
let res = Mod { name, visibility, kind, ast_id };
254+
let res = Mod { name, visibility, kind };
255255
self.tree.big_data.insert(ast_id.upcast(), BigModItem::Mod(res));
256256
Some(ast_id)
257257
}
@@ -261,7 +261,7 @@ impl<'a> Ctx<'a> {
261261
let visibility = self.lower_visibility(trait_def);
262262
let ast_id = self.source_ast_id_map.ast_id(trait_def);
263263

264-
let def = Trait { name, visibility, ast_id };
264+
let def = Trait { name, visibility };
265265
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Trait(def));
266266
Some(ast_id)
267267
}
@@ -274,7 +274,7 @@ impl<'a> Ctx<'a> {
274274
let visibility = self.lower_visibility(trait_alias_def);
275275
let ast_id = self.source_ast_id_map.ast_id(trait_alias_def);
276276

277-
let alias = TraitAlias { name, visibility, ast_id };
277+
let alias = TraitAlias { name, visibility };
278278
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::TraitAlias(alias));
279279
Some(ast_id)
280280
}
@@ -283,7 +283,7 @@ impl<'a> Ctx<'a> {
283283
let ast_id = self.source_ast_id_map.ast_id(impl_def);
284284
// Note that trait impls don't get implicit `Self` unlike traits, because here they are a
285285
// type alias rather than a type parameter, so this is handled by the resolver.
286-
let res = Impl { ast_id };
286+
let res = Impl {};
287287
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Impl(res));
288288
ast_id
289289
}
@@ -295,7 +295,7 @@ impl<'a> Ctx<'a> {
295295
self.span_map().span_for_range(range).ctx
296296
})?;
297297

298-
let res = Use { visibility, ast_id, use_tree };
298+
let res = Use { visibility, use_tree };
299299
self.tree.big_data.insert(ast_id.upcast(), BigModItem::Use(res));
300300
Some(ast_id)
301301
}
@@ -311,7 +311,7 @@ impl<'a> Ctx<'a> {
311311
let visibility = self.lower_visibility(extern_crate);
312312
let ast_id = self.source_ast_id_map.ast_id(extern_crate);
313313

314-
let res = ExternCrate { name, alias, visibility, ast_id };
314+
let res = ExternCrate { name, alias, visibility };
315315
self.tree.big_data.insert(ast_id.upcast(), BigModItem::ExternCrate(res));
316316
Some(ast_id)
317317
}
@@ -325,16 +325,16 @@ impl<'a> Ctx<'a> {
325325
})?);
326326
let ast_id = self.source_ast_id_map.ast_id(m);
327327
let expand_to = hir_expand::ExpandTo::from_call_site(m);
328-
let res = MacroCall { path, ast_id, expand_to, ctxt: span_map.span_for_range(range).ctx };
329-
self.tree.big_data.insert(ast_id.upcast(), BigModItem::MacroCall(res));
328+
let res = MacroCall { path, expand_to, ctxt: span_map.span_for_range(range).ctx };
329+
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::MacroCall(res));
330330
Some(ast_id)
331331
}
332332

333333
fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<ItemTreeAstId<MacroRules>> {
334334
let name = m.name()?;
335335
let ast_id = self.source_ast_id_map.ast_id(m);
336336

337-
let res = MacroRules { name: name.as_name(), ast_id };
337+
let res = MacroRules { name: name.as_name() };
338338
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::MacroRules(res));
339339
Some(ast_id)
340340
}
@@ -345,7 +345,7 @@ impl<'a> Ctx<'a> {
345345
let ast_id = self.source_ast_id_map.ast_id(m);
346346
let visibility = self.lower_visibility(m);
347347

348-
let res = Macro2 { name: name.as_name(), ast_id, visibility };
348+
let res = Macro2 { name: name.as_name(), visibility };
349349
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Macro2(res));
350350
Some(ast_id)
351351
}
@@ -372,8 +372,8 @@ impl<'a> Ctx<'a> {
372372
.collect()
373373
});
374374

375-
let res = ExternBlock { ast_id, children };
376-
self.tree.big_data.insert(ast_id.upcast(), BigModItem::ExternBlock(res));
375+
let res = ExternBlock { children };
376+
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::ExternBlock(res));
377377
ast_id
378378
}
379379

0 commit comments

Comments
 (0)