mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-30 11:37:31 +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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue