Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/hir-def/src/db.rs | 4 | ||||
| -rw-r--r-- | crates/hir-def/src/expr_store/expander.rs | 33 | ||||
| -rw-r--r-- | crates/hir-def/src/expr_store/lower.rs | 2 | ||||
| -rw-r--r-- | crates/hir-def/src/find_path.rs | 3 | ||||
| -rw-r--r-- | crates/hir-def/src/import_map.rs | 25 | ||||
| -rw-r--r-- | crates/hir-def/src/item_tree.rs | 33 | ||||
| -rw-r--r-- | crates/hir-def/src/item_tree/lower.rs | 15 | ||||
| -rw-r--r-- | crates/hir-def/src/nameres/assoc.rs | 17 | ||||
| -rw-r--r-- | crates/hir-def/src/nameres/tests/incremental.rs | 68 | ||||
| -rw-r--r-- | crates/hir-def/src/resolver.rs | 2 | ||||
| -rw-r--r-- | crates/hir-expand/src/db.rs | 9 | ||||
| -rw-r--r-- | crates/hir-ty/src/builtin_derive.rs | 8 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/incremental.rs | 30 | ||||
| -rw-r--r-- | crates/hir/src/display.rs | 10 | ||||
| -rw-r--r-- | crates/ide-db/src/prime_caches.rs | 4 |
15 files changed, 121 insertions, 142 deletions
diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index 0451523390..2f2889ec66 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -15,7 +15,6 @@ use crate::{ ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId, attrs::AttrFlags, - import_map::ImportMap, item_tree::{ItemTree, file_item_tree_query}, nameres::crate_def_map, visibility::{self, Visibility}, @@ -97,9 +96,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase { #[salsa::invoke(macro_def)] fn macro_def(&self, m: MacroId) -> MacroDefId; - #[salsa::invoke(ImportMap::import_map_query)] - fn import_map(&self, krate: Crate) -> Arc<ImportMap>; - // region:visibilities #[salsa::invoke(visibility::field_visibilities_query)] diff --git a/crates/hir-def/src/expr_store/expander.rs b/crates/hir-def/src/expr_store/expander.rs index d34ec9bbc1..2fffa02c13 100644 --- a/crates/hir-def/src/expr_store/expander.rs +++ b/crates/hir-def/src/expr_store/expander.rs @@ -14,7 +14,6 @@ use hir_expand::{ use span::{AstIdMap, SyntaxContext}; use syntax::ast::HasAttrs; use syntax::{AstNode, Parse, ast}; -use triomphe::Arc; use tt::TextRange; use crate::{ @@ -23,21 +22,21 @@ use crate::{ }; #[derive(Debug)] -pub(super) struct Expander { +pub(super) struct Expander<'db> { span_map: SpanMap, current_file_id: HirFileId, - ast_id_map: Arc<AstIdMap>, + ast_id_map: &'db AstIdMap, /// `recursion_depth == usize::MAX` indicates that the recursion limit has been reached. recursion_depth: u32, recursion_limit: usize, } -impl Expander { +impl<'db> Expander<'db> { pub(super) fn new( - db: &dyn DefDatabase, + db: &'db dyn DefDatabase, current_file_id: HirFileId, - def_map: &DefMap, - ) -> Expander { + def_map: &'db DefMap, + ) -> Expander<'db> { let recursion_limit = def_map.recursion_limit() as usize; let recursion_limit = if cfg!(test) { // Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug @@ -77,12 +76,12 @@ impl Expander { pub(super) fn enter_expand<T: ast::AstNode>( &mut self, - db: &dyn DefDatabase, + db: &'db dyn DefDatabase, macro_call: ast::MacroCall, krate: Crate, resolver: impl Fn(&ModPath) -> Option<MacroId>, eager_callback: EagerCallBackFn<'_>, - ) -> Result<ExpandResult<Option<(Mark, Option<Parse<T>>)>>, UnresolvedMacro> { + ) -> Result<ExpandResult<Option<(Mark<'db>, Option<Parse<T>>)>>, UnresolvedMacro> { // FIXME: within_limit should support this, instead of us having to extract the error let mut unresolved_macro_err = None; @@ -130,13 +129,13 @@ impl Expander { pub(super) fn enter_expand_id<T: ast::AstNode>( &mut self, - db: &dyn DefDatabase, + db: &'db dyn DefDatabase, call_id: MacroCallId, - ) -> ExpandResult<Option<(Mark, Option<Parse<T>>)>> { + ) -> ExpandResult<Option<(Mark<'db>, Option<Parse<T>>)>> { self.within_limit(db, |_this| ExpandResult::ok(Some(call_id))) } - pub(super) fn exit(&mut self, Mark { file_id, span_map, ast_id_map, mut bomb }: Mark) { + pub(super) fn exit(&mut self, Mark { file_id, span_map, ast_id_map, mut bomb }: Mark<'db>) { self.span_map = span_map; self.current_file_id = file_id; self.ast_id_map = ast_id_map; @@ -162,9 +161,9 @@ impl Expander { fn within_limit<F, T: ast::AstNode>( &mut self, - db: &dyn DefDatabase, + db: &'db dyn DefDatabase, op: F, - ) -> ExpandResult<Option<(Mark, Option<Parse<T>>)>> + ) -> ExpandResult<Option<(Mark<'db>, Option<Parse<T>>)>> where F: FnOnce(&mut Self) -> ExpandResult<Option<MacroCallId>>, { @@ -219,7 +218,7 @@ impl Expander { #[inline] pub(super) fn ast_id_map(&self) -> &AstIdMap { - &self.ast_id_map + self.ast_id_map } #[inline] @@ -229,9 +228,9 @@ impl Expander { } #[derive(Debug)] -pub(super) struct Mark { +pub(super) struct Mark<'db> { file_id: HirFileId, span_map: SpanMap, - ast_id_map: Arc<AstIdMap>, + ast_id_map: &'db AstIdMap, bomb: DropBomb, } diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs index de1f7463af..afa1c7fcfd 100644 --- a/crates/hir-def/src/expr_store/lower.rs +++ b/crates/hir-def/src/expr_store/lower.rs @@ -414,7 +414,7 @@ pub(crate) fn lower_function( pub struct ExprCollector<'db> { db: &'db dyn DefDatabase, cfg_options: &'db CfgOptions, - expander: Expander, + expander: Expander<'db>, def_map: &'db DefMap, local_def_map: &'db LocalDefMap, module: ModuleId, diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs index 5d1cac8e93..8308203693 100644 --- a/crates/hir-def/src/find_path.rs +++ b/crates/hir-def/src/find_path.rs @@ -14,6 +14,7 @@ use rustc_hash::FxHashSet; use crate::{ FindPathConfig, ModuleDefId, ModuleId, db::DefDatabase, + import_map::ImportMap, item_scope::ItemInNs, nameres::DefMap, visibility::{Visibility, VisibilityExplicitness}, @@ -426,7 +427,7 @@ fn find_in_dep( best_choice: &mut Option<Choice>, dep: Crate, ) { - let import_map = ctx.db.import_map(dep); + let import_map = ImportMap::of(ctx.db, dep); let Some(import_info_for) = import_map.import_info_for(item) else { return; }; diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs index 6c5d226cac..0014e1af5c 100644 --- a/crates/hir-def/src/import_map.rs +++ b/crates/hir-def/src/import_map.rs @@ -10,7 +10,6 @@ use rustc_hash::FxHashSet; use smallvec::SmallVec; use span::Edition; use stdx::format_to; -use triomphe::Arc; use crate::{ AssocItemId, AttrDefId, Complete, FxIndexMap, ModuleDefId, ModuleId, TraitId, @@ -63,6 +62,14 @@ enum IsTraitAssocItem { type ImportMapIndex = FxIndexMap<ItemInNs, (SmallVec<[ImportInfo; 1]>, IsTraitAssocItem)>; +#[salsa::tracked] +impl ImportMap { + #[salsa::tracked(returns(ref))] + pub fn of(db: &dyn DefDatabase, krate: Crate) -> Self { + Self::import_map_query_impl(db, krate) + } +} + impl ImportMap { pub fn dump(&self, db: &dyn DefDatabase) -> String { let mut out = String::new(); @@ -76,7 +83,7 @@ impl ImportMap { out } - pub(crate) fn import_map_query(db: &dyn DefDatabase, krate: Crate) -> Arc<Self> { + fn import_map_query_impl(db: &dyn DefDatabase, krate: Crate) -> Self { let _p = tracing::info_span!("import_map_query").entered(); let map = Self::collect_import_map(db, krate); @@ -120,7 +127,7 @@ impl ImportMap { } let importables = importables.into_iter().map(|(item, _, idx)| (item, idx)).collect(); - Arc::new(ImportMap { item_to_info_map: map, fst: builder.into_map(), importables }) + ImportMap { item_to_info_map: map, fst: builder.into_map(), importables } } pub fn import_info_for(&self, item: ItemInNs) -> Option<&[ImportInfo]> { @@ -424,7 +431,7 @@ pub fn search_dependencies( let _p = tracing::info_span!("search_dependencies", ?query).entered(); let import_maps: Vec<_> = - krate.data(db).dependencies.iter().map(|dep| db.import_map(dep.crate_id)).collect(); + krate.data(db).dependencies.iter().map(|dep| ImportMap::of(db, dep.crate_id)).collect(); let mut op = fst::map::OpBuilder::new(); @@ -458,7 +465,7 @@ pub fn search_dependencies( fn search_maps( _db: &dyn DefDatabase, - import_maps: &[Arc<ImportMap>], + import_maps: &[&ImportMap], mut stream: fst::map::Union<'_>, query: &Query, ) -> FxHashSet<(ItemInNs, Complete)> { @@ -467,7 +474,7 @@ fn search_maps( for &IndexedValue { index: import_map_idx, value } in indexed_values { let end = (value & 0xFFFF_FFFF) as usize; let start = (value >> 32) as usize; - let ImportMap { item_to_info_map, importables, .. } = &*import_maps[import_map_idx]; + let ImportMap { item_to_info_map, importables, .. } = import_maps[import_map_idx]; let importables = &importables[start..end]; let iter = importables @@ -546,9 +553,9 @@ mod tests { .into_iter() .filter_map(|(dependency, _)| { let dependency_krate = dependency.krate(&db)?; - let dependency_imports = db.import_map(dependency_krate); + let dependency_imports = ImportMap::of(&db, dependency_krate); - let (path, mark) = match assoc_item_path(&db, &dependency_imports, dependency) { + let (path, mark) = match assoc_item_path(&db, dependency_imports, dependency) { Some(assoc_item_path) => (assoc_item_path, "a"), None => ( render_path(&db, &dependency_imports.import_info_for(dependency)?[0]), @@ -618,7 +625,7 @@ mod tests { let cdata = &krate.extra_data(&db); let name = cdata.display_name.as_ref()?; - let map = db.import_map(krate); + let map = ImportMap::of(&db, krate); Some(format!("{name}:\n{}\n", map.fmt_for_test(&db))) }) diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs index 9825dbfe1c..e7ab2b390f 100644 --- a/crates/hir-def/src/item_tree.rs +++ b/crates/hir-def/src/item_tree.rs @@ -192,45 +192,22 @@ pub(crate) fn file_item_tree_query( } } -#[salsa_macros::tracked(returns(deref))] +#[salsa_macros::tracked(returns(ref))] pub(crate) fn block_item_tree_query( db: &dyn DefDatabase, block: BlockId, krate: Crate, -) -> Arc<ItemTree> { +) -> ItemTree { let _p = tracing::info_span!("block_item_tree_query", ?block).entered(); - static EMPTY: OnceLock<Arc<ItemTree>> = OnceLock::new(); - let loc = block.lookup(db); let block = loc.ast_id.to_node(db); let ctx = lower::Ctx::new(db, loc.ast_id.file_id, krate); let mut item_tree = ctx.lower_block(&block); - let ItemTree { top_level, top_attrs, attrs, vis, big_data, small_data } = &item_tree; - if small_data.is_empty() - && big_data.is_empty() - && top_level.is_empty() - && attrs.is_empty() - && top_attrs.is_empty() - && vis.arena.is_empty() - { - EMPTY - .get_or_init(|| { - Arc::new(ItemTree { - top_level: Box::new([]), - attrs: FxHashMap::default(), - small_data: FxHashMap::default(), - big_data: FxHashMap::default(), - top_attrs: AttrsOrCfg::empty(), - vis: ItemVisibilities { arena: ThinVec::new() }, - }) - }) - .clone() - } else { - item_tree.shrink_to_fit(); - Arc::new(item_tree) - } + item_tree.shrink_to_fit(); + item_tree } + /// The item tree of a source file. #[derive(Debug, Default, Eq, PartialEq)] pub struct ItemTree { diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs index 31c6ef867d..31e409d86e 100644 --- a/crates/hir-def/src/item_tree/lower.rs +++ b/crates/hir-def/src/item_tree/lower.rs @@ -16,7 +16,6 @@ use syntax::{ AstNode, ast::{self, HasModuleItem, HasName}, }; -use triomphe::Arc; use crate::{ db::DefDatabase, @@ -29,20 +28,20 @@ use crate::{ }, }; -pub(super) struct Ctx<'a> { - pub(super) db: &'a dyn DefDatabase, +pub(super) struct Ctx<'db> { + pub(super) db: &'db dyn DefDatabase, tree: ItemTree, - source_ast_id_map: Arc<AstIdMap>, + source_ast_id_map: &'db AstIdMap, span_map: OnceCell<SpanMap>, file: HirFileId, - cfg_options: OnceCell<&'a CfgOptions>, + cfg_options: OnceCell<&'db CfgOptions>, krate: Crate, top_level: Vec<ModItemId>, visibilities: FxIndexSet<RawVisibility>, } -impl<'a> Ctx<'a> { - pub(super) fn new(db: &'a dyn DefDatabase, file: HirFileId, krate: Crate) -> Self { +impl<'db> Ctx<'db> { + pub(super) fn new(db: &'db dyn DefDatabase, file: HirFileId, krate: Crate) -> Self { Self { db, tree: ItemTree::default(), @@ -57,7 +56,7 @@ impl<'a> Ctx<'a> { } #[inline] - pub(super) fn cfg_options(&self) -> &'a CfgOptions { + pub(super) fn cfg_options(&self) -> &'db CfgOptions { self.cfg_options.get_or_init(|| self.krate.cfg_options(self.db)) } diff --git a/crates/hir-def/src/nameres/assoc.rs b/crates/hir-def/src/nameres/assoc.rs index 9d2b2109fb..f5a852b39c 100644 --- a/crates/hir-def/src/nameres/assoc.rs +++ b/crates/hir-def/src/nameres/assoc.rs @@ -17,7 +17,6 @@ use syntax::{ ast::{self, HasModuleItem, HasName}, }; use thin_vec::ThinVec; -use triomphe::Arc; use crate::{ AssocItemId, AstIdWithPath, ConstLoc, FunctionId, FunctionLoc, ImplId, ItemContainerId, @@ -133,14 +132,14 @@ impl ImplItems { } } -struct AssocItemCollector<'a> { - db: &'a dyn DefDatabase, +struct AssocItemCollector<'db> { + db: &'db dyn DefDatabase, module_id: ModuleId, - def_map: &'a DefMap, - local_def_map: &'a LocalDefMap, - ast_id_map: Arc<AstIdMap>, + def_map: &'db DefMap, + local_def_map: &'db LocalDefMap, + ast_id_map: &'db AstIdMap, span_map: SpanMap, - cfg_options: &'a CfgOptions, + cfg_options: &'db CfgOptions, file_id: HirFileId, diagnostics: Vec<DefDiagnostic>, container: ItemContainerId, @@ -150,9 +149,9 @@ struct AssocItemCollector<'a> { macro_calls: ThinVec<(AstId<ast::Item>, MacroCallId)>, } -impl<'a> AssocItemCollector<'a> { +impl<'db> AssocItemCollector<'db> { fn new( - db: &'a dyn DefDatabase, + db: &'db dyn DefDatabase, module_id: ModuleId, container: ItemContainerId, file_id: HirFileId, diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs index 7fedfa03bb..5b75c078ec 100644 --- a/crates/hir-def/src/nameres/tests/incremental.rs +++ b/crates/hir-def/src/nameres/tests/incremental.rs @@ -166,15 +166,15 @@ fn no() {} [ "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "EnumVariants::of_", @@ -183,7 +183,7 @@ fn no() {} expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "EnumVariants::of_", @@ -224,21 +224,21 @@ pub struct S {} [ "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "decl_macro_expander_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "macro_def_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "macro_arg_shim", ] @@ -246,12 +246,12 @@ pub struct S {} expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "macro_arg_shim", "parse_macro_expansion_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", ] "#]], @@ -282,26 +282,26 @@ fn f() { foo } [ "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "crate_local_def_map", "proc_macros_for_crate_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "macro_def_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "expand_proc_macro_shim", "macro_arg_shim", @@ -311,13 +311,13 @@ fn f() { foo } expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "macro_arg_shim", "expand_proc_macro_shim", "parse_macro_expansion_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", ] "#]], @@ -406,38 +406,38 @@ pub struct S {} [ "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "crate_local_def_map", "proc_macros_for_crate_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "decl_macro_expander_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "macro_def_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "macro_arg_shim", "decl_macro_expander_shim", "macro_def_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "macro_arg_shim", "macro_def_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "expand_proc_macro_shim", "macro_arg_shim", @@ -447,7 +447,7 @@ pub struct S {} expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "macro_arg_shim", @@ -523,29 +523,29 @@ m!(Z); [ "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "decl_macro_expander_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "macro_def_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "macro_arg_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "macro_arg_shim", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_macro_expansion_shim", "macro_arg_shim", ] @@ -572,7 +572,7 @@ m!(Z); expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "macro_arg_shim", @@ -610,7 +610,7 @@ pub type Ty = (); expect![[r#" [ "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", ] @@ -630,7 +630,7 @@ pub type Ty = (); expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", ] diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs index 1a0e6a46f1..dee7800e84 100644 --- a/crates/hir-def/src/resolver.rs +++ b/crates/hir-def/src/resolver.rs @@ -1020,7 +1020,7 @@ impl<'db> Scope<'db> { }) }); } - &Scope::GenericParams { ref params, def: parent } => { + &Scope::GenericParams { params, def: parent } => { if let GenericDefId::ImplId(impl_) = parent { acc.add(&Name::new_symbol_root(sym::Self_), ScopeDef::ImplSelfType(impl_)); } else if let GenericDefId::AdtId(adt) = parent { diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs index 363465fdda..020731cf9a 100644 --- a/crates/hir-expand/src/db.rs +++ b/crates/hir-expand/src/db.rs @@ -58,8 +58,8 @@ pub trait ExpandDatabase: RootQueryDb { fn proc_macros_for_crate(&self, krate: Crate) -> Option<Arc<CrateProcMacros>>; #[salsa::invoke(ast_id_map)] - #[salsa::lru(1024)] - fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; + #[salsa::transparent] + fn ast_id_map(&self, file_id: HirFileId) -> &AstIdMap; #[salsa::transparent] fn resolve_span(&self, span: Span) -> FileRange; @@ -334,8 +334,9 @@ pub fn expand_speculative( Some((node.syntax_node(), token)) } -fn ast_id_map(db: &dyn ExpandDatabase, file_id: HirFileId) -> triomphe::Arc<AstIdMap> { - triomphe::Arc::new(AstIdMap::from_source(&db.parse_or_expand(file_id))) +#[salsa::tracked(lru = 1024, returns(ref))] +fn ast_id_map(db: &dyn ExpandDatabase, file_id: HirFileId) -> AstIdMap { + AstIdMap::from_source(&db.parse_or_expand(file_id)) } /// Main public API -- parses a hir file, not caring whether it's a real diff --git a/crates/hir-ty/src/builtin_derive.rs b/crates/hir-ty/src/builtin_derive.rs index 6cdc07e430..92629b7a05 100644 --- a/crates/hir-ty/src/builtin_derive.rs +++ b/crates/hir-ty/src/builtin_derive.rs @@ -133,7 +133,7 @@ pub fn impl_trait<'db>( let args = GenericArgs::identity_for_item(interner, loc.adt.into()); let self_ty = Ty::new_adt(interner, loc.adt, args); let Some((pointee_param_idx, _, new_param_ty)) = - coerce_pointee_params(interner, loc, &generic_params, trait_id) + coerce_pointee_params(interner, loc, generic_params, trait_id) else { // Malformed derive. return EarlyBinder::bind(TraitRef::new( @@ -168,7 +168,7 @@ pub fn predicates<'db>(db: &'db dyn HirDatabase, impl_: BuiltinDeriveImplId) -> | BuiltinDeriveImplTrait::PartialOrd | BuiltinDeriveImplTrait::Eq | BuiltinDeriveImplTrait::PartialEq => { - simple_trait_predicates(interner, loc, &generic_params, adt_predicates, trait_id) + simple_trait_predicates(interner, loc, generic_params, adt_predicates, trait_id) } BuiltinDeriveImplTrait::Default => { if matches!(loc.adt, AdtId::EnumId(_)) { @@ -178,12 +178,12 @@ pub fn predicates<'db>(db: &'db dyn HirDatabase, impl_: BuiltinDeriveImplId) -> .store(), )) } else { - simple_trait_predicates(interner, loc, &generic_params, adt_predicates, trait_id) + simple_trait_predicates(interner, loc, generic_params, adt_predicates, trait_id) } } BuiltinDeriveImplTrait::CoerceUnsized | BuiltinDeriveImplTrait::DispatchFromDyn => { let Some((pointee_param_idx, pointee_param_id, new_param_ty)) = - coerce_pointee_params(interner, loc, &generic_params, trait_id) + coerce_pointee_params(interner, loc, generic_params, trait_id) else { // Malformed derive. return GenericPredicates::from_explicit_own_predicates(StoredEarlyBinder::bind( diff --git a/crates/hir-ty/src/tests/incremental.rs b/crates/hir-ty/src/tests/incremental.rs index 3e8089c9c1..e806999cb4 100644 --- a/crates/hir-ty/src/tests/incremental.rs +++ b/crates/hir-ty/src/tests/incremental.rs @@ -34,7 +34,7 @@ fn foo() -> i32 { "source_root_crates_shim", "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "InferenceResult::for_body_", @@ -77,7 +77,7 @@ fn foo() -> i32 { expect_test::expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "AttrFlags::query_", @@ -122,7 +122,7 @@ fn baz() -> i32 { "source_root_crates_shim", "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "InferenceResult::for_body_", @@ -190,7 +190,7 @@ fn baz() -> i32 { expect_test::expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "AttrFlags::query_", @@ -242,7 +242,7 @@ $0", "source_root_crates_shim", "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "TraitImpls::for_crate_", @@ -279,7 +279,7 @@ pub struct NewStruct { expect_test::expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "crate_local_def_map", @@ -317,7 +317,7 @@ $0", "source_root_crates_shim", "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "TraitImpls::for_crate_", @@ -355,7 +355,7 @@ pub enum SomeEnum { expect_test::expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "crate_local_def_map", @@ -393,7 +393,7 @@ $0", "source_root_crates_shim", "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "TraitImpls::for_crate_", @@ -428,7 +428,7 @@ fn bar() -> f32 { expect_test::expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "crate_local_def_map", @@ -470,7 +470,7 @@ $0", "source_root_crates_shim", "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "TraitImpls::for_crate_", @@ -513,7 +513,7 @@ impl SomeStruct { expect_test::expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "crate_local_def_map", @@ -571,7 +571,7 @@ fn main() { "source_root_crates_shim", "crate_local_def_map", "file_item_tree_query", - "ast_id_map_shim", + "ast_id_map", "parse_shim", "real_span_map_shim", "TraitItems::query_with_diagnostics_", @@ -665,7 +665,7 @@ fn main() { expect_test::expect![[r#" [ "parse_shim", - "ast_id_map_shim", + "ast_id_map", "file_item_tree_query", "real_span_map_shim", "crate_local_def_map", @@ -716,6 +716,7 @@ fn execute_assert_events( ) { crate::attach_db(db, || { let (executed, events) = db.log_executed(f); + expect.assert_debug_eq(&executed); for (event, count) in required { let n = executed.iter().filter(|it| it.contains(event)).count(); assert_eq!( @@ -731,6 +732,5 @@ fn execute_assert_events( .collect::<Vec<_>>(), ); } - expect.assert_debug_eq(&executed); }); } diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index aa34177b89..ef885f0be8 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -101,7 +101,7 @@ impl<'db> HirDisplay<'db> for Function { if f.show_container_bounds() && !params.is_empty() { write_trait_header(trait_.into(), f)?; f.write_char('\n')?; - has_disaplayable_predicates(f.db, ¶ms, params_store) + has_disaplayable_predicates(f.db, params, params_store) .then_some((params, params_store)) } else { None @@ -112,7 +112,7 @@ impl<'db> HirDisplay<'db> for Function { if f.show_container_bounds() && !params.is_empty() { write_impl_header(impl_, f)?; f.write_char('\n')?; - has_disaplayable_predicates(f.db, ¶ms, params_store) + has_disaplayable_predicates(f.db, params, params_store) .then_some((params, params_store)) } else { None @@ -134,7 +134,7 @@ impl<'db> HirDisplay<'db> for Function { _ => unreachable!(), }; write!(f, "\n // Bounds from {container_name}:",)?; - write_where_predicates(&container_params, container_params_store, f)?; + write_where_predicates(container_params, container_params_store, f)?; } Ok(()) } @@ -719,12 +719,12 @@ fn write_generic_params_or_args<'db>( fn write_where_clause<'db>(def: GenericDefId, f: &mut HirFormatter<'_, 'db>) -> Result<bool> { let (params, store) = GenericParams::with_store(f.db, def); - if !has_disaplayable_predicates(f.db, ¶ms, store) { + if !has_disaplayable_predicates(f.db, params, store) { return Ok(false); } f.write_str("\nwhere")?; - write_where_predicates(¶ms, store, f)?; + write_where_predicates(params, store, f)?; Ok(true) } diff --git a/crates/ide-db/src/prime_caches.rs b/crates/ide-db/src/prime_caches.rs index 015b06e8e0..d264428212 100644 --- a/crates/ide-db/src/prime_caches.rs +++ b/crates/ide-db/src/prime_caches.rs @@ -4,7 +4,7 @@ //! various caches, it's not really advanced at the moment. use std::panic::AssertUnwindSafe; -use hir::{Symbol, db::DefDatabase}; +use hir::{Symbol, import_map::ImportMap}; use rustc_hash::FxHashMap; use salsa::{Cancelled, Database}; @@ -123,7 +123,7 @@ pub fn parallel_prime_caches( Ok::<_, crossbeam_channel::SendError<_>>(()) }; let handle_import_map = |crate_id| { - let cancelled = Cancelled::catch(|| _ = db.import_map(crate_id)); + let cancelled = Cancelled::catch(|| _ = ImportMap::of(&db, crate_id)); match cancelled { Ok(()) => { |