Skip to content

Commit 7366833

Browse files
bors[bot]Veykril
andauthored
Merge #10767
10767: minor: Rename intern_macro -> intern_macro_call r=Veykril a=Veykril We potentially want to intern macro definitions so the names would probably collide bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 4b9b714 + 5c0b895 commit 7366833

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

crates/hir/src/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! But we need this for at least LRU caching at the query level.
66
pub use hir_def::db::*;
77
pub use hir_expand::db::{
8-
AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternMacroQuery,
8+
AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternMacroCallQuery,
99
MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery,
1010
};
1111
pub use hir_ty::db::*;

crates/hir/src/semantics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ impl<'db> SemanticsImpl<'db> {
842842
fn resolve_attr_macro_call(&self, item: &ast::Item) -> Option<MacroDef> {
843843
let item_in_file = self.find_file(item.syntax().clone()).with_value(item.clone());
844844
let macro_call_id = self.with_ctx(|ctx| ctx.item_to_macro_call(item_in_file))?;
845-
Some(MacroDef { id: self.db.lookup_intern_macro(macro_call_id).def })
845+
Some(MacroDef { id: self.db.lookup_intern_macro_call(macro_call_id).def })
846846
}
847847

848848
fn resolve_path(&self, path: &ast::Path) -> Option<PathResolution> {

crates/hir_def/src/nameres/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ impl DefCollector<'_> {
11411141
&resolver,
11421142
) {
11431143
Ok(call_id) => {
1144-
let loc: MacroCallLoc = self.db.lookup_intern_macro(call_id);
1144+
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id);
11451145
if let MacroDefKind::ProcMacro(exp, ..) = &loc.def.kind {
11461146
if exp.is_dummy() {
11471147
// Proc macros that cannot be expanded are treated as not
@@ -1214,7 +1214,7 @@ impl DefCollector<'_> {
12141214
// First, fetch the raw expansion result for purposes of error reporting. This goes through
12151215
// `macro_expand_error` to avoid depending on the full expansion result (to improve
12161216
// incrementality).
1217-
let loc: MacroCallLoc = self.db.lookup_intern_macro(macro_call_id);
1217+
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(macro_call_id);
12181218
let err = self.db.macro_expand_error(macro_call_id);
12191219
if let Some(err) = err {
12201220
let diag = match err {

crates/hir_expand/src/builtin_derive_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn find_builtin_crate(db: &dyn AstDatabase, id: MacroCallId) -> tt::TokenTree {
168168
// FIXME: make hygiene works for builtin derive macro
169169
// such that $crate can be used here.
170170
let cg = db.crate_graph();
171-
let krate = db.lookup_intern_macro(id).krate;
171+
let krate = db.lookup_intern_macro_call(id).krate;
172172

173173
// XXX
174174
// All crates except core itself should have a dependency on core,

crates/hir_expand/src/builtin_fn_macro.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn cfg_expand(
326326
id: MacroCallId,
327327
tt: &tt::Subtree,
328328
) -> ExpandResult<tt::Subtree> {
329-
let loc = db.lookup_intern_macro(id);
329+
let loc = db.lookup_intern_macro_call(id);
330330
let expr = CfgExpr::parse(tt);
331331
let enabled = db.crate_graph()[loc.krate].cfg_options.check(&expr) != Some(false);
332332
let expanded = if enabled { quote!(true) } else { quote!(false) };
@@ -338,7 +338,7 @@ fn panic_expand(
338338
id: MacroCallId,
339339
tt: &tt::Subtree,
340340
) -> ExpandResult<tt::Subtree> {
341-
let loc: MacroCallLoc = db.lookup_intern_macro(id);
341+
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
342342
// Expand to a macro call `$crate::panic::panic_{edition}`
343343
let krate = tt::Ident { text: "$crate".into(), id: tt::TokenId::unspecified() };
344344
let mut call = if db.crate_graph()[loc.krate].edition == Edition::Edition2021 {
@@ -531,7 +531,7 @@ fn include_str_expand(
531531
}
532532

533533
fn get_env_inner(db: &dyn AstDatabase, arg_id: MacroCallId, key: &str) -> Option<String> {
534-
let krate = db.lookup_intern_macro(arg_id).krate;
534+
let krate = db.lookup_intern_macro_call(arg_id).krate;
535535
db.crate_graph()[krate].env.get(key)
536536
}
537537

crates/hir_expand/src/db.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub trait AstDatabase: SourceDatabase {
103103
/// We encode macro definitions into ids of macro calls, this what allows us
104104
/// to be incremental.
105105
#[salsa::interned]
106-
fn intern_macro(&self, macro_call: MacroCallLoc) -> MacroCallId;
106+
fn intern_macro_call(&self, macro_call: MacroCallLoc) -> MacroCallId;
107107

108108
/// Lowers syntactic macro call to a token tree representation.
109109
#[salsa::transparent]
@@ -139,7 +139,7 @@ pub fn expand_speculative(
139139
speculative_args: &SyntaxNode,
140140
token_to_map: SyntaxToken,
141141
) -> Option<(SyntaxNode, SyntaxToken)> {
142-
let loc = db.lookup_intern_macro(actual_macro_call);
142+
let loc = db.lookup_intern_macro_call(actual_macro_call);
143143
let macro_def = db.macro_def(loc.def).ok()?;
144144
let token_range = token_to_map.text_range();
145145

@@ -231,7 +231,7 @@ fn parse_macro_expansion(
231231
// Note:
232232
// The final goal we would like to make all parse_macro success,
233233
// such that the following log will not call anyway.
234-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
234+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
235235
let node = loc.kind.to_node(db);
236236

237237
// collect parent information for warning log
@@ -296,7 +296,7 @@ fn parse_macro_expansion(
296296

297297
fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
298298
let arg = db.macro_arg_text(id)?;
299-
let loc = db.lookup_intern_macro(id);
299+
let loc = db.lookup_intern_macro_call(id);
300300

301301
let node = SyntaxNode::new_root(arg);
302302
let censor = censor_for_macro_input(&loc, &node);
@@ -339,7 +339,7 @@ fn censor_for_macro_input(loc: &MacroCallLoc, node: &SyntaxNode) -> FxHashSet<Sy
339339
}
340340

341341
fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
342-
let loc = db.lookup_intern_macro(id);
342+
let loc = db.lookup_intern_macro_call(id);
343343
let arg = loc.kind.arg(db)?;
344344
if matches!(loc.kind, MacroCallKind::FnLike { .. }) {
345345
let first = arg.first_child_or_token().map_or(T![.], |it| it.kind());
@@ -402,7 +402,7 @@ fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Result<Arc<TokenExpander>,
402402

403403
fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<Option<Arc<tt::Subtree>>> {
404404
let _p = profile::span("macro_expand");
405-
let loc: MacroCallLoc = db.lookup_intern_macro(id);
405+
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
406406
if let Some(eager) = &loc.eager {
407407
return ExpandResult {
408408
value: Some(eager.arg_or_expansion.clone()),
@@ -443,7 +443,7 @@ fn macro_expand_error(db: &dyn AstDatabase, macro_call: MacroCallId) -> Option<E
443443
}
444444

445445
fn expand_proc_macro(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<tt::Subtree> {
446-
let loc: MacroCallLoc = db.lookup_intern_macro(id);
446+
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
447447
let macro_arg = match db.macro_arg(id) {
448448
Some(it) => it,
449449
None => return ExpandResult::str_err("No arguments for proc-macro".to_string()),
@@ -488,7 +488,7 @@ fn hygiene_frame(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<HygieneFrame>
488488
}
489489

490490
fn macro_expand_to(db: &dyn AstDatabase, id: MacroCallId) -> ExpandTo {
491-
let loc: MacroCallLoc = db.lookup_intern_macro(id);
491+
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
492492
loc.kind.expand_to()
493493
}
494494

crates/hir_expand/src/eager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn expand_eager_macro(
119119
// When `lazy_expand` is called, its *parent* file must be already exists.
120120
// Here we store an eager macro id for the argument expanded subtree here
121121
// for that purpose.
122-
let arg_id = db.intern_macro(MacroCallLoc {
122+
let arg_id = db.intern_macro_call(MacroCallLoc {
123123
def,
124124
krate,
125125
eager: Some(EagerCallInfo {
@@ -157,7 +157,7 @@ pub fn expand_eager_macro(
157157
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to },
158158
};
159159

160-
Ok(db.intern_macro(loc))
160+
Ok(db.intern_macro_call(loc))
161161
} else {
162162
panic!("called `expand_eager_macro` on non-eager macro def {:?}", def);
163163
}

crates/hir_expand/src/hygiene.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl HygieneInfo {
141141
let token_id = self.exp_map.token_by_range(token)?;
142142
let (mut token_id, origin) = self.macro_def.map_id_up(token_id);
143143

144-
let loc = db.lookup_intern_macro(self.file.macro_call_id);
144+
let loc = db.lookup_intern_macro_call(self.file.macro_call_id);
145145

146146
let (token_map, tt) = match &loc.kind {
147147
MacroCallKind::Attr { attr_args, .. } => match self.macro_arg_shift.unshift(token_id) {
@@ -213,7 +213,7 @@ impl HygieneFrame {
213213
let (info, krate, local_inner) = match file_id.0 {
214214
HirFileIdRepr::FileId(_) => (None, None, false),
215215
HirFileIdRepr::MacroFile(macro_file) => {
216-
let loc = db.lookup_intern_macro(macro_file.macro_call_id);
216+
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);
217217
let info =
218218
make_hygiene_info(db, macro_file, &loc).map(|info| (loc.kind.file_id(), info));
219219
match loc.def.kind {

crates/hir_expand/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl HirFileId {
148148
match self.0 {
149149
HirFileIdRepr::FileId(file_id) => file_id,
150150
HirFileIdRepr::MacroFile(macro_file) => {
151-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
151+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
152152
let file_id = match &loc.eager {
153153
Some(EagerCallInfo { included_file: Some(file), .. }) => (*file).into(),
154154
_ => loc.kind.file_id(),
@@ -162,7 +162,7 @@ impl HirFileId {
162162
let mut level = 0;
163163
let mut curr = self;
164164
while let HirFileIdRepr::MacroFile(macro_file) = curr.0 {
165-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
165+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
166166

167167
level += 1;
168168
curr = loc.kind.file_id();
@@ -175,7 +175,7 @@ impl HirFileId {
175175
match self.0 {
176176
HirFileIdRepr::FileId(_) => None,
177177
HirFileIdRepr::MacroFile(macro_file) => {
178-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
178+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
179179
Some(loc.kind.to_node(db))
180180
}
181181
}
@@ -186,7 +186,7 @@ impl HirFileId {
186186
match self.0 {
187187
HirFileIdRepr::FileId(_) => None,
188188
HirFileIdRepr::MacroFile(macro_file) => {
189-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
189+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
190190

191191
let arg_tt = loc.kind.arg(db)?;
192192

@@ -231,7 +231,7 @@ impl HirFileId {
231231
match self.0 {
232232
HirFileIdRepr::FileId(_) => None,
233233
HirFileIdRepr::MacroFile(macro_file) => {
234-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
234+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
235235
let item = match loc.def.kind {
236236
MacroDefKind::BuiltInDerive(..) => loc.kind.to_node(db),
237237
_ => return None,
@@ -245,7 +245,7 @@ impl HirFileId {
245245
match self.0 {
246246
HirFileIdRepr::FileId(_) => false,
247247
HirFileIdRepr::MacroFile(macro_file) => {
248-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
248+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
249249
match loc.def.kind {
250250
MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _) => true,
251251
_ => false,
@@ -258,7 +258,7 @@ impl HirFileId {
258258
pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
259259
match self.0 {
260260
HirFileIdRepr::MacroFile(macro_file) => {
261-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
261+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
262262
matches!(loc.eager, Some(EagerCallInfo { included_file: Some(_), .. }))
263263
}
264264
_ => false,
@@ -269,7 +269,7 @@ impl HirFileId {
269269
pub fn is_attr_macro(&self, db: &dyn db::AstDatabase) -> bool {
270270
match self.0 {
271271
HirFileIdRepr::MacroFile(macro_file) => {
272-
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
272+
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
273273
matches!(loc.kind, MacroCallKind::Attr { .. })
274274
}
275275
_ => false,
@@ -288,7 +288,7 @@ impl MacroDefId {
288288
krate: CrateId,
289289
kind: MacroCallKind,
290290
) -> MacroCallId {
291-
db.intern_macro(MacroCallLoc { def: self, krate, eager: None, kind })
291+
db.intern_macro_call(MacroCallLoc { def: self, krate, eager: None, kind })
292292
}
293293

294294
pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
@@ -402,7 +402,7 @@ impl ExpansionInfo {
402402
HirFileIdRepr::FileId(_) => return None,
403403
HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
404404
};
405-
let loc = db.lookup_intern_macro(call_id);
405+
let loc = db.lookup_intern_macro_call(call_id);
406406

407407
let token_range = token.value.text_range();
408408
match &loc.kind {
@@ -458,7 +458,7 @@ impl ExpansionInfo {
458458
HirFileIdRepr::FileId(_) => return None,
459459
HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
460460
};
461-
let loc = db.lookup_intern_macro(call_id);
461+
let loc = db.lookup_intern_macro_call(call_id);
462462

463463
let (token_map, tt) = match &loc.kind {
464464
MacroCallKind::Attr { attr_args, .. } => match self.macro_arg_shift.unshift(token_id) {

crates/ide_db/src/apply_change.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl RootDatabase {
7878
hir::db::ParseMacroExpansionQuery
7979
hir::db::MacroExpandQuery
8080
hir::db::HygieneFrameQuery
81-
hir::db::InternMacroQuery
81+
hir::db::InternMacroCallQuery
8282

8383
// DefDatabase
8484
hir::db::FileItemTreeQuery

0 commit comments

Comments
 (0)