Skip to content

Commit 20a5e4f

Browse files
authored
Merge pull request #22328 from ChayimFriedman2/variant-name
internal: Remove interning from query_group
2 parents e266f5c + 5b9f7db commit 20a5e4f

32 files changed

Lines changed: 129 additions & 387 deletions

File tree

crates/hir-def/src/db.rs

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,16 @@ use hir_expand::{
77
use triomphe::Arc;
88

99
use crate::{
10-
AssocItemId, AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, EnumId, EnumLoc, EnumVariantId,
11-
EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId,
12-
FunctionLoc, ImplId, ImplLoc, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId,
13-
MacroRulesLoc, MacroRulesLocFlags, ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId,
14-
StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc,
10+
AssocItemId, AttrDefId, Macro2Loc, MacroExpander, MacroId, MacroRulesLoc, MacroRulesLocFlags,
11+
TraitId,
1512
attrs::AttrFlags,
1613
item_tree::{ItemTree, file_item_tree},
1714
nameres::crate_def_map,
1815
visibility::{self, Visibility},
1916
};
2017

21-
use salsa::plumbing::AsId;
22-
23-
#[query_group::query_group(InternDatabaseStorage)]
24-
pub trait InternDatabase: SourceDatabase {
25-
// region: items
26-
#[salsa::interned]
27-
fn intern_use(&self, loc: UseLoc) -> UseId;
28-
29-
#[salsa::interned]
30-
fn intern_extern_crate(&self, loc: ExternCrateLoc) -> ExternCrateId;
31-
32-
#[salsa::interned]
33-
fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
34-
35-
#[salsa::interned]
36-
fn intern_struct(&self, loc: StructLoc) -> StructId;
37-
38-
#[salsa::interned]
39-
fn intern_union(&self, loc: UnionLoc) -> UnionId;
40-
41-
#[salsa::interned]
42-
fn intern_enum(&self, loc: EnumLoc) -> EnumId;
43-
44-
#[salsa::interned]
45-
fn intern_enum_variant(&self, loc: EnumVariantLoc) -> EnumVariantId;
46-
47-
#[salsa::interned]
48-
fn intern_const(&self, loc: ConstLoc) -> ConstId;
49-
50-
#[salsa::interned]
51-
fn intern_static(&self, loc: StaticLoc) -> StaticId;
52-
53-
#[salsa::interned]
54-
fn intern_trait(&self, loc: TraitLoc) -> TraitId;
55-
56-
#[salsa::interned]
57-
fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
58-
59-
#[salsa::interned]
60-
fn intern_impl(&self, loc: ImplLoc) -> ImplId;
61-
62-
#[salsa::interned]
63-
fn intern_extern_block(&self, loc: ExternBlockLoc) -> ExternBlockId;
64-
65-
#[salsa::interned]
66-
fn intern_macro2(&self, loc: Macro2Loc) -> Macro2Id;
67-
68-
#[salsa::interned]
69-
fn intern_proc_macro(&self, loc: ProcMacroLoc) -> ProcMacroId;
70-
71-
#[salsa::interned]
72-
fn intern_macro_rules(&self, loc: MacroRulesLoc) -> MacroRulesId;
73-
// endregion: items
74-
75-
#[salsa::interned]
76-
fn intern_block(&self, loc: BlockLoc) -> BlockId;
77-
}
78-
7918
#[query_group::query_group]
80-
pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase {
19+
pub trait DefDatabase: ExpandDatabase + SourceDatabase {
8120
/// Whether to expand procedural macros during name resolution.
8221
#[salsa::input]
8322
fn expand_proc_attr_macros(&self) -> bool;
@@ -118,11 +57,7 @@ fn include_macro_invoc(
11857
.modules
11958
.values()
12059
.flat_map(|m| m.scope.iter_macro_invoc())
121-
.filter_map(|invoc| {
122-
db.lookup_intern_macro_call(*invoc.1)
123-
.include_file_id(db, *invoc.1)
124-
.map(|x| (*invoc.1, x))
125-
})
60+
.filter_map(|invoc| invoc.1.loc(db).include_file_id(db, *invoc.1).map(|x| (*invoc.1, x)))
12661
.collect()
12762
}
12863

crates/hir-def/src/expr_store/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ impl<'db> ExprCollector<'db> {
25012501
) -> ExprId {
25022502
let block_id = self.expander.ast_id_map().ast_id_for_block(&block).map(|file_local_id| {
25032503
let ast_id = self.expander.in_file(file_local_id);
2504-
self.db.intern_block(BlockLoc { ast_id, module: self.module })
2504+
BlockId::new(self.db, BlockLoc { ast_id, module: self.module })
25052505
});
25062506

25072507
let (module, def_map) =
@@ -2953,7 +2953,7 @@ impl<'db> ExprCollector<'db> {
29532953
None
29542954
} else {
29552955
hygiene_id.syntax_context().outer_expn(self.db).map(|expansion| {
2956-
let expansion = self.db.lookup_intern_macro_call(expansion.into());
2956+
let expansion = hir_expand::MacroCallId::from(expansion).loc(self.db);
29572957
(hygiene_id.syntax_context().parent(self.db), expansion.def)
29582958
})
29592959
};
@@ -2983,7 +2983,7 @@ impl<'db> ExprCollector<'db> {
29832983

29842984
hygiene_id = HygieneId::new(parent_ctx.opaque_and_semiopaque(self.db));
29852985
hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
2986-
let expansion = self.db.lookup_intern_macro_call(expansion.into());
2986+
let expansion = hir_expand::MacroCallId::from(expansion).loc(self.db);
29872987
(parent_ctx.parent(self.db), expansion.def)
29882988
});
29892989
}

crates/hir-def/src/expr_store/lower/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub(super) fn lower_path(
217217
{
218218
let syn_ctxt = collector.expander.ctx_for_range(path.segment()?.syntax().text_range());
219219
if let Some(macro_call_id) = syn_ctxt.outer_expn(collector.db)
220-
&& collector.db.lookup_intern_macro_call(macro_call_id.into()).def.local_inner
220+
&& hir_expand::MacroCallId::from(macro_call_id).loc(collector.db).def.local_inner
221221
{
222222
kind = match resolve_crate_root(collector.db, syn_ctxt) {
223223
Some(crate_root) => PathKind::DollarCrate(crate_root),

crates/hir-def/src/lib.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ impl<N: AstIdNode> AstIdLoc for AssocItemLoc<N> {
220220
}
221221

222222
macro_rules! impl_intern {
223-
($id:ident, $loc:ident, $intern:ident, $lookup:ident) => {
223+
($id:ident, $loc:ident) => {
224224
impl_intern_key!($id, $loc);
225-
impl_intern_lookup!(DefDatabase, $id, $loc, $intern, $lookup);
225+
impl_intern_lookup!(DefDatabase, $id, $loc);
226226
};
227227
}
228228

@@ -249,10 +249,10 @@ macro_rules! impl_loc {
249249
}
250250

251251
type FunctionLoc = AssocItemLoc<ast::Fn>;
252-
impl_intern!(FunctionId, FunctionLoc, intern_function, lookup_intern_function);
252+
impl_intern!(FunctionId, FunctionLoc);
253253

254254
type StructLoc = ItemLoc<ast::Struct>;
255-
impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct);
255+
impl_intern!(StructId, StructLoc);
256256

257257
impl StructId {
258258
pub fn fields(self, db: &dyn DefDatabase) -> &VariantFields {
@@ -269,7 +269,7 @@ impl StructId {
269269
}
270270

271271
pub type UnionLoc = ItemLoc<ast::Union>;
272-
impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union);
272+
impl_intern!(UnionId, UnionLoc);
273273

274274
impl UnionId {
275275
pub fn fields(self, db: &dyn DefDatabase) -> &VariantFields {
@@ -286,7 +286,7 @@ impl UnionId {
286286
}
287287

288288
pub type EnumLoc = ItemLoc<ast::Enum>;
289-
impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum);
289+
impl_intern!(EnumId, EnumLoc);
290290

291291
impl EnumId {
292292
#[inline]
@@ -304,13 +304,13 @@ impl EnumId {
304304
}
305305

306306
type ConstLoc = AssocItemLoc<ast::Const>;
307-
impl_intern!(ConstId, ConstLoc, intern_const, lookup_intern_const);
307+
impl_intern!(ConstId, ConstLoc);
308308

309309
pub type StaticLoc = AssocItemLoc<ast::Static>;
310-
impl_intern!(StaticId, StaticLoc, intern_static, lookup_intern_static);
310+
impl_intern!(StaticId, StaticLoc);
311311

312312
pub type TraitLoc = ItemLoc<ast::Trait>;
313-
impl_intern!(TraitId, TraitLoc, intern_trait, lookup_intern_trait);
313+
impl_intern!(TraitId, TraitLoc);
314314

315315
impl TraitId {
316316
#[inline]
@@ -320,10 +320,10 @@ impl TraitId {
320320
}
321321

322322
type TypeAliasLoc = AssocItemLoc<ast::TypeAlias>;
323-
impl_intern!(TypeAliasId, TypeAliasLoc, intern_type_alias, lookup_intern_type_alias);
323+
impl_intern!(TypeAliasId, TypeAliasLoc);
324324

325325
type ImplLoc = ItemLoc<ast::Impl>;
326-
impl_intern!(ImplId, ImplLoc, intern_impl, lookup_intern_impl);
326+
impl_intern!(ImplId, ImplLoc);
327327

328328
impl ImplId {
329329
#[inline]
@@ -353,13 +353,13 @@ pub struct BuiltinDeriveImplId {
353353
}
354354

355355
type UseLoc = ItemLoc<ast::Use>;
356-
impl_intern!(UseId, UseLoc, intern_use, lookup_intern_use);
356+
impl_intern!(UseId, UseLoc);
357357

358358
type ExternCrateLoc = ItemLoc<ast::ExternCrate>;
359-
impl_intern!(ExternCrateId, ExternCrateLoc, intern_extern_crate, lookup_intern_extern_crate);
359+
impl_intern!(ExternCrateId, ExternCrateLoc);
360360

361361
type ExternBlockLoc = ItemLoc<ast::ExternBlock>;
362-
impl_intern!(ExternBlockId, ExternBlockLoc, intern_extern_block, lookup_intern_extern_block);
362+
impl_intern!(ExternBlockId, ExternBlockLoc);
363363

364364
impl ExternBlockId {
365365
pub fn abi(self, db: &dyn DefDatabase) -> ExternAbi {
@@ -373,7 +373,7 @@ pub struct EnumVariantLoc {
373373
pub parent: EnumId,
374374
pub index: u32,
375375
}
376-
impl_intern!(EnumVariantId, EnumVariantLoc, intern_enum_variant, lookup_intern_enum_variant);
376+
impl_intern!(EnumVariantId, EnumVariantLoc);
377377
impl_loc!(EnumVariantLoc, id: Variant, parent: EnumId);
378378

379379
impl EnumVariantId {
@@ -398,7 +398,7 @@ pub struct Macro2Loc {
398398
pub allow_internal_unsafe: bool,
399399
pub edition: Edition,
400400
}
401-
impl_intern!(Macro2Id, Macro2Loc, intern_macro2, lookup_intern_macro2);
401+
impl_intern!(Macro2Id, Macro2Loc);
402402
impl_loc!(Macro2Loc, id: MacroDef, container: ModuleId);
403403

404404
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -409,7 +409,7 @@ pub struct MacroRulesLoc {
409409
pub flags: MacroRulesLocFlags,
410410
pub edition: Edition,
411411
}
412-
impl_intern!(MacroRulesId, MacroRulesLoc, intern_macro_rules, lookup_intern_macro_rules);
412+
impl_intern!(MacroRulesId, MacroRulesLoc);
413413
impl_loc!(MacroRulesLoc, id: MacroRules, container: ModuleId);
414414

415415
bitflags::bitflags! {
@@ -437,7 +437,7 @@ pub struct ProcMacroLoc {
437437
pub kind: ProcMacroKind,
438438
pub edition: Edition,
439439
}
440-
impl_intern!(ProcMacroId, ProcMacroLoc, intern_proc_macro, lookup_intern_proc_macro);
440+
impl_intern!(ProcMacroId, ProcMacroLoc);
441441
impl_loc!(ProcMacroLoc, id: Fn, container: ModuleId);
442442

443443
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
@@ -446,7 +446,7 @@ pub struct BlockLoc {
446446
/// The containing module.
447447
pub module: ModuleId,
448448
}
449-
impl_intern!(BlockId, BlockLoc, intern_block, lookup_intern_block);
449+
impl_intern!(BlockId, BlockLoc);
450450

451451
#[salsa_macros::tracked(debug)]
452452
#[derive(PartialOrd, Ord)]

crates/hir-def/src/macro_expansion_tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect)
6464
.filter_map(|macro_call| {
6565
let errors = db.parse_macro_expansion_error(macro_call)?;
6666
let errors = errors.err.as_ref()?.render_to_string(&db);
67-
let macro_loc = db.lookup_intern_macro_call(macro_call);
67+
let macro_loc = macro_call.loc(&db);
6868
let ast_id = match macro_loc.kind {
6969
MacroCallKind::FnLike { ast_id, .. } => ast_id.map(|it| it.erase()),
7070
MacroCallKind::Derive { ast_id, .. } => ast_id.map(|it| it.erase()),

crates/hir-def/src/nameres/assoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'db> AssocItemCollector<'db> {
217217
attr_id,
218218
) {
219219
Ok(ResolvedAttr::Macro(call_id)) => {
220-
let loc = self.db.lookup_intern_macro_call(call_id);
220+
let loc = call_id.loc(self.db);
221221
if let MacroDefKind::ProcMacro(_, exp, _) = loc.def.kind {
222222
// If there's no expander for the proc macro (e.g. the
223223
// proc macro is ignored, or building the proc macro

crates/hir-def/src/resolver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ fn handle_macro_def_scope(
936936
// and use its parent expansion.
937937
*hygiene_id = HygieneId::new(parent_ctx.opaque_and_semiopaque(db));
938938
*hygiene_info = parent_ctx.outer_expn(db).map(|expansion| {
939-
let expansion = db.lookup_intern_macro_call(expansion.into());
939+
let expansion = hir_expand::MacroCallId::from(expansion).loc(db);
940940
(parent_ctx.parent(db), expansion.def)
941941
});
942942
}
@@ -950,7 +950,7 @@ fn hygiene_info(
950950
if !hygiene_id.is_root() {
951951
let ctx = hygiene_id.syntax_context();
952952
ctx.outer_expn(db).map(|expansion| {
953-
let expansion = db.lookup_intern_macro_call(expansion.into());
953+
let expansion = hir_expand::MacroCallId::from(expansion).loc(db);
954954
(ctx.parent(db), expansion.def)
955955
})
956956
} else {

crates/hir-expand/src/builtin/attr_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn derive_expand(
122122
tt: &tt::TopSubtree,
123123
span: Span,
124124
) -> ExpandResult<tt::TopSubtree> {
125-
let loc = db.lookup_intern_macro_call(id);
125+
let loc = id.loc(db);
126126
let derives = match &loc.kind {
127127
MacroCallKind::Attr { attr_args: Some(attr_args), .. } if loc.def.is_attribute_derive() => {
128128
attr_args

crates/hir-expand/src/builtin/fn_macro.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ fn cfg_select_expand(
357357
tt: &tt::TopSubtree,
358358
span: Span,
359359
) -> ExpandResult<tt::TopSubtree> {
360-
let loc = db.lookup_intern_macro_call(id);
360+
let loc = id.loc(db);
361361
let cfg_options = loc.krate.cfg_options(db);
362362

363363
let mut iter = tt.iter();
@@ -446,7 +446,7 @@ fn cfg_expand(
446446
tt: &tt::TopSubtree,
447447
span: Span,
448448
) -> ExpandResult<tt::TopSubtree> {
449-
let loc = db.lookup_intern_macro_call(id);
449+
let loc = id.loc(db);
450450
let expr = CfgExpr::parse(tt);
451451
let enabled = loc.krate.cfg_options(db).check(&expr) != Some(false);
452452
let expanded = if enabled { quote!(span=>true) } else { quote!(span=>false) };
@@ -518,7 +518,7 @@ fn use_panic_2021(db: &dyn ExpandDatabase, span: Span) -> bool {
518518
let Some(expn) = span.ctx.outer_expn(db) else {
519519
break false;
520520
};
521-
let expn = db.lookup_intern_macro_call(expn.into());
521+
let expn = crate::MacroCallId::from(expn).loc(db);
522522
// FIXME: Record allow_internal_unstable in the macro def (not been done yet because it
523523
// would consume quite a bit extra memory for all call locs...)
524524
// if let Some(features) = expn.def.allow_internal_unstable {
@@ -764,7 +764,7 @@ fn relative_file(
764764
allow_recursion: bool,
765765
err_span: Span,
766766
) -> Result<EditionedFileId, ExpandError> {
767-
let lookup = db.lookup_intern_macro_call(call_id);
767+
let lookup = call_id.loc(db);
768768
let call_site = lookup.kind.file_id().original_file_respecting_includes(db).file_id(db);
769769
let path = AnchoredPath { anchor: call_site, path: path_str };
770770
let res: FileId = db
@@ -900,7 +900,7 @@ fn include_str_expand(
900900
}
901901

902902
fn get_env_inner(db: &dyn ExpandDatabase, arg_id: MacroCallId, key: &Symbol) -> Option<String> {
903-
let krate = db.lookup_intern_macro_call(arg_id).krate;
903+
let krate = arg_id.loc(db).krate;
904904
krate.env(db).get(key.as_str())
905905
}
906906

0 commit comments

Comments
 (0)