Skip to content

Commit e7fbbaf

Browse files
authored
Merge pull request rust-lang#19995 from Veykril/push-zpyyzqqpywno
Turn `BlockId` into a `#[salsa::tracked]`
2 parents e01f53f + 82076c1 commit e7fbbaf

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use thin_vec::ThinVec;
1212
use triomphe::Arc;
1313

1414
use crate::{
15-
AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, EnumVariantId,
16-
EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId,
17-
FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalFieldId, Macro2Id, Macro2Loc, MacroExpander,
18-
MacroId, MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId,
15+
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, EnumVariantId, EnumVariantLoc,
16+
ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId, FunctionLoc,
17+
GenericDefId, ImplId, ImplLoc, LocalFieldId, Macro2Id, Macro2Loc, MacroExpander, MacroId,
18+
MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId,
1919
StaticLoc, StructId, StructLoc, TraitAliasId, TraitAliasLoc, TraitId, TraitLoc, TypeAliasId,
2020
TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId,
2121
attr::{Attrs, AttrsWithOwner},
@@ -96,9 +96,6 @@ pub trait InternDatabase: RootQueryDb {
9696
#[salsa::interned]
9797
fn intern_macro_rules(&self, loc: MacroRulesLoc) -> MacroRulesId;
9898
// // endregion: items
99-
100-
#[salsa::interned]
101-
fn intern_block(&self, loc: BlockLoc) -> BlockId;
10299
}
103100

104101
#[query_group::query_group]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use base_db::FxIndexSet;
1111
use cfg::CfgOptions;
1212
use either::Either;
1313
use hir_expand::{
14-
HirFileId, InFile, MacroDefId,
14+
HirFileId, InFile, Intern, MacroDefId,
1515
mod_path::tool_path,
1616
name::{AsName, Name},
1717
span_map::SpanMapRef,
@@ -2148,7 +2148,7 @@ impl ExprCollector<'_> {
21482148
) -> ExprId {
21492149
let block_id = self.expander.ast_id_map().ast_id_for_block(&block).map(|file_local_id| {
21502150
let ast_id = self.expander.in_file(file_local_id);
2151-
self.db.intern_block(BlockLoc { ast_id, module: self.module })
2151+
BlockLoc { ast_id, module: self.module }.intern(self.db)
21522152
});
21532153

21542154
let (module, def_map) =

src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests/body/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ fn f() {
189189
}
190190
"#,
191191
expect![[r#"
192-
BlockId(3c01) in BlockRelativeModuleId { block: Some(BlockId(3c00)), local_id: Idx::<ModuleData>(1) }
193-
BlockId(3c00) in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
192+
BlockIdLt { [salsa id]: Id(3c01) } in BlockRelativeModuleId { block: Some(BlockIdLt { [salsa id]: Id(3c00) }), local_id: Idx::<ModuleData>(1) }
193+
BlockIdLt { [salsa id]: Id(3c00) } in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
194194
crate scope
195195
"#]],
196196
);

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,26 @@ pub struct BlockLoc {
344344
/// The containing module.
345345
pub module: ModuleId,
346346
}
347-
impl_intern!(BlockId, BlockLoc, intern_block, lookup_intern_block);
347+
#[salsa_macros::tracked(debug)]
348+
#[derive(PartialOrd, Ord)]
349+
pub struct BlockIdLt<'db> {
350+
pub loc: BlockLoc,
351+
}
352+
pub type BlockId = BlockIdLt<'static>;
353+
impl hir_expand::Intern for BlockLoc {
354+
type Database = dyn DefDatabase;
355+
type ID = BlockId;
356+
fn intern(self, db: &Self::Database) -> Self::ID {
357+
unsafe { std::mem::transmute::<BlockIdLt<'_>, BlockId>(BlockIdLt::new(db, self)) }
358+
}
359+
}
360+
impl hir_expand::Lookup for BlockId {
361+
type Database = dyn DefDatabase;
362+
type Data = BlockLoc;
363+
fn lookup(&self, db: &Self::Database) -> Self::Data {
364+
self.loc(db)
365+
}
366+
}
348367

349368
/// A `ModuleId` that is always a crate's root module.
350369
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)