Rename intern_macro -> intern_macro_call

This commit is contained in:
Lukas Wirth 2021-11-14 16:25:40 +01:00
parent 2d7f5891f7
commit 5c0b895f69
10 changed files with 32 additions and 32 deletions

View file

@ -5,7 +5,7 @@
//! But we need this for at least LRU caching at the query level.
pub use hir_def::db::*;
pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternMacroQuery,
AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternMacroCallQuery,
MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery,
};
pub use hir_ty::db::*;

View file

@ -842,7 +842,7 @@ impl<'db> SemanticsImpl<'db> {
fn resolve_attr_macro_call(&self, item: &ast::Item) -> Option<MacroDef> {
let item_in_file = self.find_file(item.syntax().clone()).with_value(item.clone());
let macro_call_id = self.with_ctx(|ctx| ctx.item_to_macro_call(item_in_file))?;
Some(MacroDef { id: self.db.lookup_intern_macro(macro_call_id).def })
Some(MacroDef { id: self.db.lookup_intern_macro_call(macro_call_id).def })
}
fn resolve_path(&self, path: &ast::Path) -> Option<PathResolution> {

View file

@ -1141,7 +1141,7 @@ impl DefCollector<'_> {
&resolver,
) {
Ok(call_id) => {
let loc: MacroCallLoc = self.db.lookup_intern_macro(call_id);
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id);
if let MacroDefKind::ProcMacro(exp, ..) = &loc.def.kind {
if exp.is_dummy() {
// Proc macros that cannot be expanded are treated as not
@ -1214,7 +1214,7 @@ impl DefCollector<'_> {
// First, fetch the raw expansion result for purposes of error reporting. This goes through
// `macro_expand_error` to avoid depending on the full expansion result (to improve
// incrementality).
let loc: MacroCallLoc = self.db.lookup_intern_macro(macro_call_id);
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(macro_call_id);
let err = self.db.macro_expand_error(macro_call_id);
if let Some(err) = err {
let diag = match err {

View file

@ -168,7 +168,7 @@ fn find_builtin_crate(db: &dyn AstDatabase, id: MacroCallId) -> tt::TokenTree {
// FIXME: make hygiene works for builtin derive macro
// such that $crate can be used here.
let cg = db.crate_graph();
let krate = db.lookup_intern_macro(id).krate;
let krate = db.lookup_intern_macro_call(id).krate;
// XXX
// All crates except core itself should have a dependency on core,

View file

@ -326,7 +326,7 @@ fn cfg_expand(
id: MacroCallId,
tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> {
let loc = db.lookup_intern_macro(id);
let loc = db.lookup_intern_macro_call(id);
let expr = CfgExpr::parse(tt);
let enabled = db.crate_graph()[loc.krate].cfg_options.check(&expr) != Some(false);
let expanded = if enabled { quote!(true) } else { quote!(false) };
@ -338,7 +338,7 @@ fn panic_expand(
id: MacroCallId,
tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> {
let loc: MacroCallLoc = db.lookup_intern_macro(id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
// Expand to a macro call `$crate::panic::panic_{edition}`
let krate = tt::Ident { text: "$crate".into(), id: tt::TokenId::unspecified() };
let mut call = if db.crate_graph()[loc.krate].edition == Edition::Edition2021 {
@ -531,7 +531,7 @@ fn include_str_expand(
}
fn get_env_inner(db: &dyn AstDatabase, arg_id: MacroCallId, key: &str) -> Option<String> {
let krate = db.lookup_intern_macro(arg_id).krate;
let krate = db.lookup_intern_macro_call(arg_id).krate;
db.crate_graph()[krate].env.get(key)
}

View file

@ -103,7 +103,7 @@ pub trait AstDatabase: SourceDatabase {
/// We encode macro definitions into ids of macro calls, this what allows us
/// to be incremental.
#[salsa::interned]
fn intern_macro(&self, macro_call: MacroCallLoc) -> MacroCallId;
fn intern_macro_call(&self, macro_call: MacroCallLoc) -> MacroCallId;
/// Lowers syntactic macro call to a token tree representation.
#[salsa::transparent]
@ -139,7 +139,7 @@ pub fn expand_speculative(
speculative_args: &SyntaxNode,
token_to_map: SyntaxToken,
) -> Option<(SyntaxNode, SyntaxToken)> {
let loc = db.lookup_intern_macro(actual_macro_call);
let loc = db.lookup_intern_macro_call(actual_macro_call);
let macro_def = db.macro_def(loc.def).ok()?;
let token_range = token_to_map.text_range();
@ -231,7 +231,7 @@ fn parse_macro_expansion(
// Note:
// The final goal we would like to make all parse_macro success,
// such that the following log will not call anyway.
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
let node = loc.kind.to_node(db);
// collect parent information for warning log
@ -296,7 +296,7 @@ fn parse_macro_expansion(
fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
let arg = db.macro_arg_text(id)?;
let loc = db.lookup_intern_macro(id);
let loc = db.lookup_intern_macro_call(id);
let node = SyntaxNode::new_root(arg);
let censor = censor_for_macro_input(&loc, &node);
@ -339,7 +339,7 @@ fn censor_for_macro_input(loc: &MacroCallLoc, node: &SyntaxNode) -> FxHashSet<Sy
}
fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
let loc = db.lookup_intern_macro(id);
let loc = db.lookup_intern_macro_call(id);
let arg = loc.kind.arg(db)?;
if matches!(loc.kind, MacroCallKind::FnLike { .. }) {
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>,
fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<Option<Arc<tt::Subtree>>> {
let _p = profile::span("macro_expand");
let loc: MacroCallLoc = db.lookup_intern_macro(id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
if let Some(eager) = &loc.eager {
return ExpandResult {
value: Some(eager.arg_or_expansion.clone()),
@ -443,7 +443,7 @@ fn macro_expand_error(db: &dyn AstDatabase, macro_call: MacroCallId) -> Option<E
}
fn expand_proc_macro(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<tt::Subtree> {
let loc: MacroCallLoc = db.lookup_intern_macro(id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
let macro_arg = match db.macro_arg(id) {
Some(it) => it,
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>
}
fn macro_expand_to(db: &dyn AstDatabase, id: MacroCallId) -> ExpandTo {
let loc: MacroCallLoc = db.lookup_intern_macro(id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
loc.kind.expand_to()
}

View file

@ -119,7 +119,7 @@ pub fn expand_eager_macro(
// When `lazy_expand` is called, its *parent* file must be already exists.
// Here we store an eager macro id for the argument expanded subtree here
// for that purpose.
let arg_id = db.intern_macro(MacroCallLoc {
let arg_id = db.intern_macro_call(MacroCallLoc {
def,
krate,
eager: Some(EagerCallInfo {
@ -157,7 +157,7 @@ pub fn expand_eager_macro(
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to },
};
Ok(db.intern_macro(loc))
Ok(db.intern_macro_call(loc))
} else {
panic!("called `expand_eager_macro` on non-eager macro def {:?}", def);
}

View file

@ -141,7 +141,7 @@ impl HygieneInfo {
let token_id = self.exp_map.token_by_range(token)?;
let (mut token_id, origin) = self.macro_def.map_id_up(token_id);
let loc = db.lookup_intern_macro(self.file.macro_call_id);
let loc = db.lookup_intern_macro_call(self.file.macro_call_id);
let (token_map, tt) = match &loc.kind {
MacroCallKind::Attr { attr_args, .. } => match self.macro_arg_shift.unshift(token_id) {
@ -213,7 +213,7 @@ impl HygieneFrame {
let (info, krate, local_inner) = match file_id.0 {
HirFileIdRepr::FileId(_) => (None, None, false),
HirFileIdRepr::MacroFile(macro_file) => {
let loc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);
let info =
make_hygiene_info(db, macro_file, &loc).map(|info| (loc.kind.file_id(), info));
match loc.def.kind {

View file

@ -148,7 +148,7 @@ impl HirFileId {
match self.0 {
HirFileIdRepr::FileId(file_id) => file_id,
HirFileIdRepr::MacroFile(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
let file_id = match &loc.eager {
Some(EagerCallInfo { included_file: Some(file), .. }) => (*file).into(),
_ => loc.kind.file_id(),
@ -162,7 +162,7 @@ impl HirFileId {
let mut level = 0;
let mut curr = self;
while let HirFileIdRepr::MacroFile(macro_file) = curr.0 {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
level += 1;
curr = loc.kind.file_id();
@ -175,7 +175,7 @@ impl HirFileId {
match self.0 {
HirFileIdRepr::FileId(_) => None,
HirFileIdRepr::MacroFile(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
Some(loc.kind.to_node(db))
}
}
@ -186,7 +186,7 @@ impl HirFileId {
match self.0 {
HirFileIdRepr::FileId(_) => None,
HirFileIdRepr::MacroFile(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
let arg_tt = loc.kind.arg(db)?;
@ -231,7 +231,7 @@ impl HirFileId {
match self.0 {
HirFileIdRepr::FileId(_) => None,
HirFileIdRepr::MacroFile(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
let item = match loc.def.kind {
MacroDefKind::BuiltInDerive(..) => loc.kind.to_node(db),
_ => return None,
@ -245,7 +245,7 @@ impl HirFileId {
match self.0 {
HirFileIdRepr::FileId(_) => false,
HirFileIdRepr::MacroFile(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
match loc.def.kind {
MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _) => true,
_ => false,
@ -258,7 +258,7 @@ impl HirFileId {
pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
match self.0 {
HirFileIdRepr::MacroFile(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
matches!(loc.eager, Some(EagerCallInfo { included_file: Some(_), .. }))
}
_ => false,
@ -269,7 +269,7 @@ impl HirFileId {
pub fn is_attr_macro(&self, db: &dyn db::AstDatabase) -> bool {
match self.0 {
HirFileIdRepr::MacroFile(macro_file) => {
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
matches!(loc.kind, MacroCallKind::Attr { .. })
}
_ => false,
@ -288,7 +288,7 @@ impl MacroDefId {
krate: CrateId,
kind: MacroCallKind,
) -> MacroCallId {
db.intern_macro(MacroCallLoc { def: self, krate, eager: None, kind })
db.intern_macro_call(MacroCallLoc { def: self, krate, eager: None, kind })
}
pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
@ -402,7 +402,7 @@ impl ExpansionInfo {
HirFileIdRepr::FileId(_) => return None,
HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
};
let loc = db.lookup_intern_macro(call_id);
let loc = db.lookup_intern_macro_call(call_id);
let token_range = token.value.text_range();
match &loc.kind {
@ -458,7 +458,7 @@ impl ExpansionInfo {
HirFileIdRepr::FileId(_) => return None,
HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
};
let loc = db.lookup_intern_macro(call_id);
let loc = db.lookup_intern_macro_call(call_id);
let (token_map, tt) = match &loc.kind {
MacroCallKind::Attr { attr_args, .. } => match self.macro_arg_shift.unshift(token_id) {

View file

@ -78,7 +78,7 @@ impl RootDatabase {
hir::db::ParseMacroExpansionQuery
hir::db::MacroExpandQuery
hir::db::HygieneFrameQuery
hir::db::InternMacroQuery
hir::db::InternMacroCallQuery
// DefDatabase
hir::db::FileItemTreeQuery