Skip to content

Commit dd8eaaa

Browse files
authored
Merge pull request #20041 from Veykril/push-yxlszoznuyno
Revert "Turn `BlockId` into a `#[salsa::tracked]`"
2 parents 58d4b99 + d41f48f commit dd8eaaa

File tree

5 files changed

+19
-39
lines changed

5 files changed

+19
-39
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use syntax::{AstPtr, ast};
1111
use triomphe::Arc;
1212

1313
use crate::{
14-
AssocItemId, AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, EnumVariantId,
15-
EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId,
16-
FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalFieldId, Macro2Id, Macro2Loc, MacroExpander,
17-
MacroId, MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId,
18-
StaticLoc, StructId, StructLoc, TraitAliasId, TraitAliasLoc, TraitId, TraitLoc, TypeAliasId,
19-
TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId,
14+
AssocItemId, AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc,
15+
EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc,
16+
FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalFieldId, Macro2Id, Macro2Loc,
17+
MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ProcMacroId,
18+
ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitAliasId, TraitAliasLoc, TraitId,
19+
TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId,
2020
attr::{Attrs, AttrsWithOwner},
2121
expr_store::{
2222
Body, BodySourceMap, ExpressionStore, ExpressionStoreSourceMap, scope::ExprScopes,
@@ -90,7 +90,10 @@ pub trait InternDatabase: RootQueryDb {
9090

9191
#[salsa::interned]
9292
fn intern_macro_rules(&self, loc: MacroRulesLoc) -> MacroRulesId;
93-
// // endregion: items
93+
// endregion: items
94+
95+
#[salsa::interned]
96+
fn intern_block(&self, loc: BlockLoc) -> BlockId;
9497
}
9598

9699
#[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, Intern, MacroDefId,
14+
HirFileId, InFile, 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-
BlockLoc { ast_id, module: self.module }.intern(self.db)
2151+
self.db.intern_block(BlockLoc { ast_id, module: self.module })
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-
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) }
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) }
194194
crate scope
195195
"#]],
196196
);

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -384,26 +384,7 @@ pub struct BlockLoc {
384384
/// The containing module.
385385
pub module: ModuleId,
386386
}
387-
#[salsa_macros::tracked(debug)]
388-
#[derive(PartialOrd, Ord)]
389-
pub struct BlockIdLt<'db> {
390-
pub loc: BlockLoc,
391-
}
392-
pub type BlockId = BlockIdLt<'static>;
393-
impl hir_expand::Intern for BlockLoc {
394-
type Database = dyn DefDatabase;
395-
type ID = BlockId;
396-
fn intern(self, db: &Self::Database) -> Self::ID {
397-
unsafe { std::mem::transmute::<BlockIdLt<'_>, BlockId>(BlockIdLt::new(db, self)) }
398-
}
399-
}
400-
impl hir_expand::Lookup for BlockId {
401-
type Database = dyn DefDatabase;
402-
type Data = BlockLoc;
403-
fn lookup(&self, db: &Self::Database) -> Self::Data {
404-
self.loc(db)
405-
}
406-
}
387+
impl_intern!(BlockId, BlockLoc, intern_block, lookup_intern_block);
407388

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

src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,12 @@ pub(crate) fn complete_postfix(
283283
let (open_brace, close_brace) =
284284
if block_should_be_wrapped { ("{ ", " }") } else { ("", "") };
285285
let (open_paren, close_paren) = if is_in_cond { ("(", ")") } else { ("", "") };
286-
let unsafe_completion_string = format!(
287-
"{}unsafe {}{receiver_text}{}{}",
288-
open_paren, open_brace, close_brace, close_paren
289-
);
286+
let unsafe_completion_string =
287+
format!("{open_paren}unsafe {open_brace}{receiver_text}{close_brace}{close_paren}");
290288
postfix_snippet("unsafe", "unsafe {}", &unsafe_completion_string).add_to(acc, ctx.db);
291289

292-
let const_completion_string = format!(
293-
"{}const {}{receiver_text}{}{}",
294-
open_paren, open_brace, close_brace, close_paren
295-
);
290+
let const_completion_string =
291+
format!("{open_paren}const {open_brace}{receiver_text}{close_brace}{close_paren}");
296292
postfix_snippet("const", "const {}", &const_completion_string).add_to(acc, ctx.db);
297293
}
298294

0 commit comments

Comments
 (0)