mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
Use stable AST IDs
Instead of simple numbering, we hash important bits, like the name of the item. This will allow for much better incrementality, e.g. when you add an item. Currently, this invalidates the IDs of all following items, which invalidates pretty much everything.
This commit is contained in:
parent
5b2c8bc9ae
commit
4bcf03e28b
22 changed files with 1220 additions and 546 deletions
|
|
@ -2141,26 +2141,10 @@ impl ExprCollector<'_> {
|
|||
block: ast::BlockExpr,
|
||||
mk_block: impl FnOnce(Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr,
|
||||
) -> ExprId {
|
||||
let block_has_items = {
|
||||
let statement_has_item = block.statements().any(|stmt| match stmt {
|
||||
ast::Stmt::Item(_) => true,
|
||||
// Macro calls can be both items and expressions. The syntax library always treats
|
||||
// them as expressions here, so we undo that.
|
||||
ast::Stmt::ExprStmt(es) => matches!(es.expr(), Some(ast::Expr::MacroExpr(_))),
|
||||
_ => false,
|
||||
});
|
||||
statement_has_item
|
||||
|| matches!(block.tail_expr(), Some(ast::Expr::MacroExpr(_)))
|
||||
|| (block.may_carry_attributes() && block.attrs().next().is_some())
|
||||
};
|
||||
|
||||
let block_id = if block_has_items {
|
||||
let file_local_id = self.expander.ast_id_map().ast_id(&block);
|
||||
let block_id = self.expander.ast_id_map().ast_id_for_block(&block).map(|file_local_id| {
|
||||
let ast_id = self.expander.in_file(file_local_id);
|
||||
Some(self.db.intern_block(BlockLoc { ast_id, module: self.module }))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.db.intern_block(BlockLoc { ast_id, module: self.module })
|
||||
});
|
||||
|
||||
let (module, def_map) =
|
||||
match block_id.map(|block_id| (block_def_map(self.db, block_id), block_id)) {
|
||||
|
|
|
|||
|
|
@ -353,8 +353,8 @@ impl Printer<'_> {
|
|||
let MacroCall { path, ast_id, expand_to, ctxt } = &self.tree[it];
|
||||
let _ = writeln!(
|
||||
self,
|
||||
"// AstId: {:?}, SyntaxContextId: {}, ExpandTo: {:?}",
|
||||
ast_id.erase().into_raw(),
|
||||
"// AstId: {:#?}, SyntaxContextId: {}, ExpandTo: {:?}",
|
||||
ast_id.erase(),
|
||||
ctxt,
|
||||
expand_to
|
||||
);
|
||||
|
|
@ -377,7 +377,7 @@ impl Printer<'_> {
|
|||
}
|
||||
|
||||
fn print_ast_id(&mut self, ast_id: ErasedFileAstId) {
|
||||
wln!(self, "// AstId: {:?}", ast_id.into_raw());
|
||||
wln!(self, "// AstId: {ast_id:#?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,23 +35,23 @@ use a::{c, d::{e}};
|
|||
#![no_std]
|
||||
#![doc = " another file comment"]
|
||||
|
||||
// AstId: 1
|
||||
// AstId: ExternCrate[5A82, 0]
|
||||
pub(self) extern crate self as renamed;
|
||||
|
||||
// AstId: 2
|
||||
// AstId: ExternCrate[7E1C, 0]
|
||||
pub(super) extern crate bli;
|
||||
|
||||
// AstId: 3
|
||||
// AstId: Use[0000, 0]
|
||||
pub use crate::path::{nested, items as renamed, Trait as _};
|
||||
|
||||
// AstId: 4
|
||||
// AstId: Use[0000, 1]
|
||||
pub(self) use globs::*;
|
||||
|
||||
#[doc = " docs on import"]
|
||||
// AstId: 5
|
||||
// AstId: Use[0000, 2]
|
||||
pub(self) use crate::{A, B};
|
||||
|
||||
// AstId: 6
|
||||
// AstId: Use[0000, 3]
|
||||
pub(self) use a::{c, d::{e}};
|
||||
"##]],
|
||||
);
|
||||
|
|
@ -75,18 +75,18 @@ extern "C" {
|
|||
"#,
|
||||
expect![[r##"
|
||||
#[on_extern_block]
|
||||
// AstId: 1
|
||||
// AstId: ExternBlock[0000, 0]
|
||||
extern "C" {
|
||||
#[on_extern_type]
|
||||
// AstId: 2
|
||||
// AstId: TypeAlias[9FDF, 0]
|
||||
pub(self) type ExType;
|
||||
|
||||
#[on_extern_static]
|
||||
// AstId: 3
|
||||
// AstId: Static[43C1, 0]
|
||||
pub(self) static EX_STATIC = _;
|
||||
|
||||
#[on_extern_fn]
|
||||
// AstId: 4
|
||||
// AstId: Fn[452D, 0]
|
||||
pub(self) fn ex_fn;
|
||||
}
|
||||
"##]],
|
||||
|
|
@ -124,39 +124,39 @@ enum E {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
// AstId: 1
|
||||
// AstId: Struct[DFF3, 0]
|
||||
pub(self) struct Unit;
|
||||
|
||||
#[derive(Debug)]
|
||||
// AstId: 2
|
||||
// AstId: Struct[C7A1, 0]
|
||||
pub(self) struct Struct {
|
||||
#[doc = " fld docs"]
|
||||
pub(self) fld,
|
||||
}
|
||||
|
||||
// AstId: 3
|
||||
// AstId: Struct[DAC2, 0]
|
||||
pub(self) struct Tuple(
|
||||
#[attr]
|
||||
pub(self) 0,
|
||||
);
|
||||
|
||||
// AstId: 4
|
||||
// AstId: Union[2DBB, 0]
|
||||
pub(self) union Ize {
|
||||
pub(self) a,
|
||||
pub(self) b,
|
||||
}
|
||||
|
||||
// AstId: 5
|
||||
// AstId: Enum[7FF8, 0]
|
||||
pub(self) enum E
|
||||
// AstId: 6
|
||||
// AstId: Variant[C717, 0]
|
||||
#[doc = " comment on Unit"]
|
||||
Unit,
|
||||
// AstId: 7
|
||||
// AstId: Variant[AEAB, 0]
|
||||
#[doc = " comment on Tuple"]
|
||||
Tuple(
|
||||
pub(self) 0,
|
||||
),
|
||||
// AstId: 8
|
||||
// AstId: Variant[4B1B, 0]
|
||||
Struct {
|
||||
#[doc = " comment on a: u8"]
|
||||
pub(self) a,
|
||||
|
|
@ -185,23 +185,23 @@ trait Tr: SuperTrait + 'lifetime {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
// AstId: 1
|
||||
// AstId: Static[B393, 0]
|
||||
pub static ST = _;
|
||||
|
||||
// AstId: 2
|
||||
// AstId: Const[B309, 0]
|
||||
pub(self) const _ = _;
|
||||
|
||||
#[attr]
|
||||
#[inner_attr_in_fn]
|
||||
// AstId: 3
|
||||
// AstId: Fn[75E3, 0]
|
||||
pub(self) fn f;
|
||||
|
||||
// AstId: 4
|
||||
// AstId: Trait[2998, 0]
|
||||
pub(self) trait Tr {
|
||||
// AstId: 6
|
||||
// AstId: TypeAlias[9F08, 0]
|
||||
pub(self) type Assoc;
|
||||
|
||||
// AstId: 7
|
||||
// AstId: Fn[6C0C, 0]
|
||||
pub(self) fn method;
|
||||
}
|
||||
"#]],
|
||||
|
|
@ -226,16 +226,16 @@ mod outline;
|
|||
expect![[r##"
|
||||
#[doc = " outer"]
|
||||
#[doc = " inner"]
|
||||
// AstId: 1
|
||||
// AstId: Module[CF93, 0]
|
||||
pub(self) mod inline {
|
||||
// AstId: 3
|
||||
// AstId: Use[0000, 0]
|
||||
pub(self) use super::*;
|
||||
|
||||
// AstId: 4
|
||||
// AstId: Fn[1B26, 0]
|
||||
pub(self) fn fn_in_module;
|
||||
}
|
||||
|
||||
// AstId: 2
|
||||
// AstId: Module[8994, 0]
|
||||
pub(self) mod outline;
|
||||
"##]],
|
||||
);
|
||||
|
|
@ -254,13 +254,13 @@ pub macro m2() {}
|
|||
m!();
|
||||
"#,
|
||||
expect![[r#"
|
||||
// AstId: 1
|
||||
// AstId: MacroRules[88CE, 0]
|
||||
macro_rules! m { ... }
|
||||
|
||||
// AstId: 2
|
||||
// AstId: MacroDef[DC34, 0]
|
||||
pub macro m2 { ... }
|
||||
|
||||
// AstId: 3, SyntaxContextId: ROOT2024, ExpandTo: Items
|
||||
// AstId: MacroCall[612F, 0], SyntaxContextId: ROOT2024, ExpandTo: Items
|
||||
m!(...);
|
||||
"#]],
|
||||
);
|
||||
|
|
@ -273,7 +273,7 @@ fn pub_self() {
|
|||
pub(self) struct S;
|
||||
"#,
|
||||
expect![[r#"
|
||||
// AstId: 1
|
||||
// AstId: Struct[42E2, 0]
|
||||
pub(self) struct S;
|
||||
"#]],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ macro_rules! f {
|
|||
};
|
||||
}
|
||||
|
||||
struct#0:1@58..64#14336# MyTraitMap2#0:2@31..42#ROOT2024# {#0:1@72..73#14336#
|
||||
map#0:1@86..89#14336#:#0:1@89..90#14336# #0:1@89..90#14336#::#0:1@91..93#14336#std#0:1@93..96#14336#::#0:1@96..98#14336#collections#0:1@98..109#14336#::#0:1@109..111#14336#HashSet#0:1@111..118#14336#<#0:1@118..119#14336#(#0:1@119..120#14336#)#0:1@120..121#14336#>#0:1@121..122#14336#,#0:1@122..123#14336#
|
||||
}#0:1@132..133#14336#
|
||||
struct#0:MacroRules[8C8E, 0]@58..64#14336# MyTraitMap2#0:MacroCall[D499, 0]@31..42#ROOT2024# {#0:MacroRules[8C8E, 0]@72..73#14336#
|
||||
map#0:MacroRules[8C8E, 0]@86..89#14336#:#0:MacroRules[8C8E, 0]@89..90#14336# #0:MacroRules[8C8E, 0]@89..90#14336#::#0:MacroRules[8C8E, 0]@91..93#14336#std#0:MacroRules[8C8E, 0]@93..96#14336#::#0:MacroRules[8C8E, 0]@96..98#14336#collections#0:MacroRules[8C8E, 0]@98..109#14336#::#0:MacroRules[8C8E, 0]@109..111#14336#HashSet#0:MacroRules[8C8E, 0]@111..118#14336#<#0:MacroRules[8C8E, 0]@118..119#14336#(#0:MacroRules[8C8E, 0]@119..120#14336#)#0:MacroRules[8C8E, 0]@120..121#14336#>#0:MacroRules[8C8E, 0]@121..122#14336#,#0:MacroRules[8C8E, 0]@122..123#14336#
|
||||
}#0:MacroRules[8C8E, 0]@132..133#14336#
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
@ -75,12 +75,12 @@ macro_rules! f {
|
|||
};
|
||||
}
|
||||
|
||||
fn#0:2@30..32#ROOT2024# main#0:2@33..37#ROOT2024#(#0:2@37..38#ROOT2024#)#0:2@38..39#ROOT2024# {#0:2@40..41#ROOT2024#
|
||||
1#0:2@50..51#ROOT2024#;#0:2@51..52#ROOT2024#
|
||||
1.0#0:2@61..64#ROOT2024#;#0:2@64..65#ROOT2024#
|
||||
(#0:2@74..75#ROOT2024#(#0:2@75..76#ROOT2024#1#0:2@76..77#ROOT2024#,#0:2@77..78#ROOT2024# )#0:2@78..79#ROOT2024#,#0:2@79..80#ROOT2024# )#0:2@80..81#ROOT2024#.#0:2@81..82#ROOT2024#0#0:2@82..85#ROOT2024#.#0:2@82..85#ROOT2024#0#0:2@82..85#ROOT2024#;#0:2@85..86#ROOT2024#
|
||||
let#0:2@95..98#ROOT2024# x#0:2@99..100#ROOT2024# =#0:2@101..102#ROOT2024# 1#0:2@103..104#ROOT2024#;#0:2@104..105#ROOT2024#
|
||||
}#0:2@110..111#ROOT2024#
|
||||
fn#0:MacroCall[D499, 0]@30..32#ROOT2024# main#0:MacroCall[D499, 0]@33..37#ROOT2024#(#0:MacroCall[D499, 0]@37..38#ROOT2024#)#0:MacroCall[D499, 0]@38..39#ROOT2024# {#0:MacroCall[D499, 0]@40..41#ROOT2024#
|
||||
1#0:MacroCall[D499, 0]@50..51#ROOT2024#;#0:MacroCall[D499, 0]@51..52#ROOT2024#
|
||||
1.0#0:MacroCall[D499, 0]@61..64#ROOT2024#;#0:MacroCall[D499, 0]@64..65#ROOT2024#
|
||||
(#0:MacroCall[D499, 0]@74..75#ROOT2024#(#0:MacroCall[D499, 0]@75..76#ROOT2024#1#0:MacroCall[D499, 0]@76..77#ROOT2024#,#0:MacroCall[D499, 0]@77..78#ROOT2024# )#0:MacroCall[D499, 0]@78..79#ROOT2024#,#0:MacroCall[D499, 0]@79..80#ROOT2024# )#0:MacroCall[D499, 0]@80..81#ROOT2024#.#0:MacroCall[D499, 0]@81..82#ROOT2024#0#0:MacroCall[D499, 0]@82..85#ROOT2024#.#0:MacroCall[D499, 0]@82..85#ROOT2024#0#0:MacroCall[D499, 0]@82..85#ROOT2024#;#0:MacroCall[D499, 0]@85..86#ROOT2024#
|
||||
let#0:MacroCall[D499, 0]@95..98#ROOT2024# x#0:MacroCall[D499, 0]@99..100#ROOT2024# =#0:MacroCall[D499, 0]@101..102#ROOT2024# 1#0:MacroCall[D499, 0]@103..104#ROOT2024#;#0:MacroCall[D499, 0]@104..105#ROOT2024#
|
||||
}#0:MacroCall[D499, 0]@110..111#ROOT2024#
|
||||
|
||||
|
||||
"#]],
|
||||
|
|
@ -171,7 +171,7 @@ fn main(foo: ()) {
|
|||
}
|
||||
|
||||
fn main(foo: ()) {
|
||||
/* error: unresolved macro unresolved */"helloworld!"#0:3@236..321#ROOT2024#;
|
||||
/* error: unresolved macro unresolved */"helloworld!"#0:Fn[B9C7, 0]@236..321#ROOT2024#;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ macro_rules! mk_struct {
|
|||
#[macro_use]
|
||||
mod foo;
|
||||
|
||||
struct#1:1@59..65#14336# Foo#0:2@32..35#ROOT2024#(#1:1@70..71#14336#u32#0:2@41..44#ROOT2024#)#1:1@74..75#14336#;#1:1@75..76#14336#
|
||||
struct#1:MacroRules[E572, 0]@59..65#14336# Foo#0:MacroCall[BDD3, 0]@32..35#ROOT2024#(#1:MacroRules[E572, 0]@70..71#14336#u32#0:MacroCall[BDD3, 0]@41..44#ROOT2024#)#1:MacroRules[E572, 0]@74..75#14336#;#1:MacroRules[E572, 0]@75..76#14336#
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,9 +181,9 @@ fn foo(&self) {
|
|||
self.0. 1;
|
||||
}
|
||||
|
||||
fn#0:1@45..47#ROOT2024# foo#0:1@48..51#ROOT2024#(#0:1@51..52#ROOT2024#�:1@52..53#ROOT2024#self#0:1@53..57#ROOT2024# )#0:1@57..58#ROOT2024# {#0:1@59..60#ROOT2024#
|
||||
self#0:1@65..69#ROOT2024# .#0:1@69..70#ROOT2024#0#0:1@70..71#ROOT2024#.#0:1@71..72#ROOT2024#1#0:1@73..74#ROOT2024#;#0:1@74..75#ROOT2024#
|
||||
}#0:1@76..77#ROOT2024#"#]],
|
||||
fn#0:Fn[4D85, 0]@45..47#ROOT2024# foo#0:Fn[4D85, 0]@48..51#ROOT2024#(#0:Fn[4D85, 0]@51..52#ROOT2024#�:Fn[4D85, 0]@52..53#ROOT2024#self#0:Fn[4D85, 0]@53..57#ROOT2024# )#0:Fn[4D85, 0]@57..58#ROOT2024# {#0:Fn[4D85, 0]@59..60#ROOT2024#
|
||||
self#0:Fn[4D85, 0]@65..69#ROOT2024# .#0:Fn[4D85, 0]@69..70#ROOT2024#0#0:Fn[4D85, 0]@70..71#ROOT2024#.#0:Fn[4D85, 0]@71..72#ROOT2024#1#0:Fn[4D85, 0]@73..74#ROOT2024#;#0:Fn[4D85, 0]@74..75#ROOT2024#
|
||||
}#0:Fn[4D85, 0]@76..77#ROOT2024#"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue