mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 20:31:59 +00:00
Make HirFileId, EditionedFileId and macro files Salsa struct
And make more queries non-interned. Also flip the default for queries, now the default is to not intern and to intern a query you need to say `invoke_interned`.
This commit is contained in:
parent
02ade79631
commit
c58ddafe90
195 changed files with 1473 additions and 1525 deletions
|
|
@ -4,11 +4,9 @@ use std::mem;
|
|||
|
||||
use base_db::Crate;
|
||||
use drop_bomb::DropBomb;
|
||||
use hir_expand::attrs::RawAttrs;
|
||||
use hir_expand::eager::EagerCallBackFn;
|
||||
use hir_expand::{
|
||||
ExpandError, ExpandErrorKind, ExpandResult, HirFileId, InFile, Lookup, MacroCallId,
|
||||
mod_path::ModPath, span_map::SpanMap,
|
||||
attrs::RawAttrs, eager::EagerCallBackFn, mod_path::ModPath, span_map::SpanMap,
|
||||
};
|
||||
use span::{AstIdMap, Edition, SyntaxContext};
|
||||
use syntax::ast::HasAttrs;
|
||||
|
|
@ -183,8 +181,7 @@ impl Expander {
|
|||
));
|
||||
}
|
||||
|
||||
let macro_file = call_id.as_macro_file();
|
||||
let res = db.parse_macro_expansion(macro_file);
|
||||
let res = db.parse_macro_expansion(call_id);
|
||||
|
||||
let err = err.or(res.err);
|
||||
ExpandResult {
|
||||
|
|
@ -192,7 +189,7 @@ impl Expander {
|
|||
let parse = res.value.0.cast::<T>();
|
||||
|
||||
self.recursion_depth += 1;
|
||||
let old_file_id = std::mem::replace(&mut self.current_file_id, macro_file.into());
|
||||
let old_file_id = std::mem::replace(&mut self.current_file_id, call_id.into());
|
||||
let old_span_map =
|
||||
std::mem::replace(&mut self.span_map, db.span_map(self.current_file_id));
|
||||
let prev_ast_id_map =
|
||||
|
|
|
|||
|
|
@ -9,13 +9,12 @@ use std::mem;
|
|||
|
||||
use either::Either;
|
||||
use hir_expand::{
|
||||
InFile, Lookup, MacroDefId,
|
||||
HirFileId, InFile, Lookup, MacroDefId,
|
||||
mod_path::tool_path,
|
||||
name::{AsName, Name},
|
||||
};
|
||||
use intern::{Symbol, sym};
|
||||
use rustc_hash::FxHashMap;
|
||||
use span::HirFileId;
|
||||
use stdx::never;
|
||||
use syntax::{
|
||||
AstNode, AstPtr, AstToken as _, SyntaxNodePtr,
|
||||
|
|
@ -1887,10 +1886,7 @@ impl ExprCollector<'_> {
|
|||
self.module.krate(),
|
||||
resolver,
|
||||
&mut |ptr, call| {
|
||||
_ = self
|
||||
.source_map
|
||||
.expansions
|
||||
.insert(ptr.map(|(it, _)| it), call.as_macro_file());
|
||||
_ = self.source_map.expansions.insert(ptr.map(|(it, _)| it), call);
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -2516,7 +2512,7 @@ impl ExprCollector<'_> {
|
|||
None
|
||||
} else {
|
||||
hygiene_id.lookup().outer_expn(self.db).map(|expansion| {
|
||||
let expansion = self.db.lookup_intern_macro_call(expansion);
|
||||
let expansion = self.db.lookup_intern_macro_call(expansion.into());
|
||||
(hygiene_id.lookup().parent(self.db), expansion.def)
|
||||
})
|
||||
};
|
||||
|
|
@ -2546,7 +2542,7 @@ impl ExprCollector<'_> {
|
|||
hygiene_id =
|
||||
HygieneId::new(parent_ctx.opaque_and_semitransparent(self.db));
|
||||
hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
|
||||
let expansion = self.db.lookup_intern_macro_call(expansion);
|
||||
let expansion = self.db.lookup_intern_macro_call(expansion.into());
|
||||
(parent_ctx.parent(self.db), expansion.def)
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ pub(super) fn lower_path(
|
|||
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
|
||||
let syn_ctxt = collector.expander.ctx_for_range(path.segment()?.syntax().text_range());
|
||||
if let Some(macro_call_id) = syn_ctxt.outer_expn(collector.db) {
|
||||
if collector.db.lookup_intern_macro_call(macro_call_id).def.local_inner {
|
||||
if collector.db.lookup_intern_macro_call(macro_call_id.into()).def.local_inner {
|
||||
kind = match resolve_crate_root(collector.db, syn_ctxt) {
|
||||
Some(crate_root) => PathKind::DollarCrate(crate_root),
|
||||
None => PathKind::Crate,
|
||||
|
|
|
|||
|
|
@ -319,7 +319,6 @@ fn compute_expr_scopes(
|
|||
mod tests {
|
||||
use base_db::RootQueryDb;
|
||||
use hir_expand::{InFile, name::AsName};
|
||||
use salsa::AsDynDatabase;
|
||||
use span::FileId;
|
||||
use syntax::{AstNode, algo::find_node_at_offset, ast};
|
||||
use test_fixture::WithFixture;
|
||||
|
|
@ -331,7 +330,7 @@ mod tests {
|
|||
let krate = db.test_crate();
|
||||
let crate_def_map = db.crate_def_map(krate);
|
||||
|
||||
let module = crate_def_map.modules_for_file(file_id).next().unwrap();
|
||||
let module = crate_def_map.modules_for_file(db, file_id).next().unwrap();
|
||||
let (_, def) = crate_def_map[module].scope.entries().next().unwrap();
|
||||
match def.take_values().unwrap() {
|
||||
ModuleDefId::FunctionId(it) => it,
|
||||
|
|
@ -354,11 +353,9 @@ mod tests {
|
|||
let editioned_file_id = position.file_id;
|
||||
let offset = position.offset;
|
||||
|
||||
let (file_id, _) = editioned_file_id.unpack();
|
||||
let editioned_file_id_wrapper =
|
||||
base_db::EditionedFileId::new(db.as_dyn_database(), editioned_file_id);
|
||||
let (file_id, _) = editioned_file_id.unpack(&db);
|
||||
|
||||
let file_syntax = db.parse(editioned_file_id_wrapper).syntax_node();
|
||||
let file_syntax = db.parse(editioned_file_id).syntax_node();
|
||||
let marker: ast::PathExpr = find_node_at_offset(&file_syntax, offset).unwrap();
|
||||
let function = find_function(&db, file_id);
|
||||
|
||||
|
|
@ -512,11 +509,9 @@ fn foo() {
|
|||
let editioned_file_id = position.file_id;
|
||||
let offset = position.offset;
|
||||
|
||||
let (file_id, _) = editioned_file_id.unpack();
|
||||
let file_id_wrapper =
|
||||
base_db::EditionedFileId::new(db.as_dyn_database(), editioned_file_id);
|
||||
let (file_id, _) = editioned_file_id.unpack(&db);
|
||||
|
||||
let file = db.parse(file_id_wrapper).ok().unwrap();
|
||||
let file = db.parse(editioned_file_id).ok().unwrap();
|
||||
let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into())
|
||||
.expect("failed to find a name at the target offset");
|
||||
let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), offset).unwrap();
|
||||
|
|
|
|||
|
|
@ -189,8 +189,8 @@ fn f() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
BlockId(4801) in BlockRelativeModuleId { block: Some(BlockId(4800)), local_id: Idx::<ModuleData>(1) }
|
||||
BlockId(4800) in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
|
||||
BlockId(3801) in BlockRelativeModuleId { block: Some(BlockId(3800)), local_id: Idx::<ModuleData>(1) }
|
||||
BlockId(3800) in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
|
||||
crate scope
|
||||
"#]],
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue