Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21897 from Veykril/push-qpksnpswtlkk
Remove `Arc` from `GenericParams` and `AstIdMap`
36 files changed, 249 insertions, 297 deletions
diff --git a/crates/hir-def/src/attrs.rs b/crates/hir-def/src/attrs.rs index 0b8f656872..e3e1aac709 100644 --- a/crates/hir-def/src/attrs.rs +++ b/crates/hir-def/src/attrs.rs @@ -894,7 +894,7 @@ impl AttrFlags { def: GenericDefId, ) -> &(ArenaMap<LocalLifetimeParamId, AttrFlags>, ArenaMap<LocalTypeOrConstParamId, AttrFlags>) { - let generic_params = GenericParams::new(db, def); + let generic_params = GenericParams::of(db, def); let params_count_excluding_self = generic_params.len() - usize::from(generic_params.trait_self_param().is_some()); if params_count_excluding_self == 0 { diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index 9c7f4943db..2f2889ec66 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -10,13 +10,11 @@ use triomphe::Arc; use crate::{ AnonConstId, AnonConstLoc, AssocItemId, AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, EnumId, EnumLoc, EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, - ExternCrateLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalFieldId, Macro2Id, - Macro2Loc, MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, - ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, - TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId, + ExternCrateLoc, FunctionId, FunctionLoc, ImplId, ImplLoc, LocalFieldId, Macro2Id, Macro2Loc, + MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, MacroRulesLocFlags, ProcMacroId, + ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId, + TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId, attrs::AttrFlags, - hir::generics::GenericParams, - import_map::ImportMap, item_tree::{ItemTree, file_item_tree_query}, nameres::crate_def_map, visibility::{self, Visibility}, @@ -98,13 +96,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase { #[salsa::invoke(macro_def)] fn macro_def(&self, m: MacroId) -> MacroDefId; - #[salsa::transparent] - #[salsa::invoke(GenericParams::new)] - fn generic_params(&self, def: GenericDefId) -> Arc<GenericParams>; - - #[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 3ed1b58741..afa1c7fcfd 100644 --- a/crates/hir-def/src/expr_store/lower.rs +++ b/crates/hir-def/src/expr_store/lower.rs @@ -28,7 +28,6 @@ use syntax::{ }, }; use thin_vec::ThinVec; -use triomphe::Arc; use tt::TextRange; use crate::{ @@ -201,7 +200,7 @@ pub(crate) fn lower_generic_params( file_id: HirFileId, param_list: Option<ast::GenericParamList>, where_clause: Option<ast::WhereClause>, -) -> (ExpressionStore, Arc<GenericParams>, ExpressionStoreSourceMap) { +) -> (ExpressionStore, GenericParams, ExpressionStoreSourceMap) { let mut expr_collector = ExprCollector::signature(db, module, file_id); let mut collector = generics::GenericParamsCollector::new(def); collector.lower(&mut expr_collector, param_list, where_clause); @@ -215,7 +214,7 @@ pub(crate) fn lower_impl( module: ModuleId, impl_syntax: InFile<ast::Impl>, impl_id: ImplId, -) -> (ExpressionStore, ExpressionStoreSourceMap, TypeRefId, Option<TraitRef>, Arc<GenericParams>) { +) -> (ExpressionStore, ExpressionStoreSourceMap, TypeRefId, Option<TraitRef>, GenericParams) { let mut expr_collector = ExprCollector::signature(db, module, impl_syntax.file_id); let self_ty = expr_collector.lower_type_ref_opt_disallow_impl_trait(impl_syntax.value.self_ty()); @@ -243,7 +242,7 @@ pub(crate) fn lower_trait( module: ModuleId, trait_syntax: InFile<ast::Trait>, trait_id: TraitId, -) -> (ExpressionStore, ExpressionStoreSourceMap, Arc<GenericParams>) { +) -> (ExpressionStore, ExpressionStoreSourceMap, GenericParams) { let mut expr_collector = ExprCollector::signature(db, module, trait_syntax.file_id); let mut collector = generics::GenericParamsCollector::with_self_param( &mut expr_collector, @@ -265,13 +264,8 @@ pub(crate) fn lower_type_alias( module: ModuleId, alias: InFile<ast::TypeAlias>, type_alias_id: TypeAliasId, -) -> ( - ExpressionStore, - ExpressionStoreSourceMap, - Arc<GenericParams>, - Box<[TypeBound]>, - Option<TypeRefId>, -) { +) -> (ExpressionStore, ExpressionStoreSourceMap, GenericParams, Box<[TypeBound]>, Option<TypeRefId>) +{ let mut expr_collector = ExprCollector::signature(db, module, alias.file_id); let bounds = alias .value @@ -308,7 +302,7 @@ pub(crate) fn lower_function( ) -> ( ExpressionStore, ExpressionStoreSourceMap, - Arc<GenericParams>, + GenericParams, Box<[TypeRefId]>, Option<TypeRefId>, bool, @@ -420,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/expr_store/lower/generics.rs b/crates/hir-def/src/expr_store/lower/generics.rs index 03de7937ba..7c7b697164 100644 --- a/crates/hir-def/src/expr_store/lower/generics.rs +++ b/crates/hir-def/src/expr_store/lower/generics.rs @@ -3,15 +3,12 @@ //! generic parameters. See also the `Generics` type and the `generics_of` query //! in rustc. -use std::sync::LazyLock; - use either::Either; use hir_expand::name::{AsName, Name}; use intern::sym; use la_arena::Arena; use syntax::ast::{self, HasName, HasTypeBounds}; use thin_vec::ThinVec; -use triomphe::Arc; use crate::{ GenericDefId, TypeOrConstParamId, TypeParamId, @@ -84,28 +81,16 @@ impl GenericParamsCollector { ) } - pub(crate) fn finish(self) -> Arc<GenericParams> { - let Self { mut lifetimes, mut type_or_consts, mut where_predicates, parent: _ } = self; - - if lifetimes.is_empty() && type_or_consts.is_empty() && where_predicates.is_empty() { - static EMPTY: LazyLock<Arc<GenericParams>> = LazyLock::new(|| { - Arc::new(GenericParams { - lifetimes: Arena::new(), - type_or_consts: Arena::new(), - where_predicates: Box::default(), - }) - }); - return Arc::clone(&EMPTY); - } + pub(crate) fn finish(self) -> GenericParams { + let Self { mut lifetimes, mut type_or_consts, where_predicates, parent: _ } = self; lifetimes.shrink_to_fit(); type_or_consts.shrink_to_fit(); - where_predicates.shrink_to_fit(); - Arc::new(GenericParams { + GenericParams { type_or_consts, lifetimes, where_predicates: where_predicates.into_boxed_slice(), - }) + } } fn lower_param_list(&mut self, ec: &mut ExprCollector<'_>, params: ast::GenericParamList) { diff --git a/crates/hir-def/src/expr_store/pretty.rs b/crates/hir-def/src/expr_store/pretty.rs index 405ebe9b7b..39e0153ded 100644 --- a/crates/hir-def/src/expr_store/pretty.rs +++ b/crates/hir-def/src/expr_store/pretty.rs @@ -1212,7 +1212,7 @@ impl Printer<'_> { } pub(crate) fn print_type_param(&mut self, param: TypeParamId) { - let generic_params = self.db.generic_params(param.parent()); + let generic_params = GenericParams::of(self.db, param.parent()); match generic_params[param.local_id()].name() { Some(name) => w!(self, "{}", name.display(self.db, self.edition)), @@ -1221,7 +1221,7 @@ impl Printer<'_> { } pub(crate) fn print_lifetime_param(&mut self, param: LifetimeParamId) { - let generic_params = self.db.generic_params(param.parent); + let generic_params = GenericParams::of(self.db, param.parent); w!(self, "{}", generic_params[param.local_id].name.display(self.db, self.edition)) } diff --git a/crates/hir-def/src/expr_store/scope.rs b/crates/hir-def/src/expr_store/scope.rs index 2250cf5f16..22a3a7b079 100644 --- a/crates/hir-def/src/expr_store/scope.rs +++ b/crates/hir-def/src/expr_store/scope.rs @@ -64,7 +64,7 @@ impl ExprScopes { #[salsa::tracked(returns(ref))] pub fn sig_expr_scopes(db: &dyn DefDatabase, def: GenericDefId) -> ExprScopes { - let (_, store) = GenericParams::of(db, def); + let (_, store) = GenericParams::with_store(db, def); let roots = store.signature_const_expr_roots(); let mut scopes = ExprScopes::new_store(store, roots); scopes.shrink_to_fit(); 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/hir/generics.rs b/crates/hir-def/src/hir/generics.rs index 41767131fc..43dd7d1c54 100644 --- a/crates/hir-def/src/hir/generics.rs +++ b/crates/hir-def/src/hir/generics.rs @@ -5,7 +5,6 @@ use hir_expand::name::Name; use la_arena::{Arena, Idx, RawIdx}; use stdx::impl_from; use thin_vec::ThinVec; -use triomphe::Arc; use crate::{ AdtId, ConstParamId, GenericDefId, LifetimeParamId, TypeOrConstParamId, TypeParamId, @@ -146,7 +145,7 @@ pub enum GenericParamDataRef<'a> { } /// Data about the generic parameters of a function, struct, impl, etc. -#[derive(Clone, PartialEq, Eq, Debug, Hash)] +#[derive(PartialEq, Eq, Debug, Hash, Default)] pub struct GenericParams { pub(crate) type_or_consts: Arena<TypeOrConstParamData>, pub(crate) lifetimes: Arena<LifetimeParamData>, @@ -178,12 +177,10 @@ pub enum WherePredicate { ForLifetime { lifetimes: ThinVec<Name>, target: TypeRefId, bound: TypeBound }, } -static EMPTY: LazyLock<Arc<GenericParams>> = LazyLock::new(|| { - Arc::new(GenericParams { - type_or_consts: Arena::default(), - lifetimes: Arena::default(), - where_predicates: Box::default(), - }) +static EMPTY: LazyLock<GenericParams> = LazyLock::new(|| GenericParams { + type_or_consts: Arena::default(), + lifetimes: Arena::default(), + where_predicates: Box::default(), }); impl GenericParams { @@ -191,47 +188,50 @@ impl GenericParams { pub const SELF_PARAM_ID_IN_SELF: la_arena::Idx<TypeOrConstParamData> = LocalTypeOrConstParamId::from_raw(RawIdx::from_u32(0)); - pub fn new(db: &dyn DefDatabase, def: GenericDefId) -> Arc<GenericParams> { - Self::of(db, def).0 + pub fn of(db: &dyn DefDatabase, def: GenericDefId) -> &GenericParams { + Self::with_store(db, def).0 } - pub fn of(db: &dyn DefDatabase, def: GenericDefId) -> (Arc<GenericParams>, &ExpressionStore) { + pub fn with_store( + db: &dyn DefDatabase, + def: GenericDefId, + ) -> (&GenericParams, &ExpressionStore) { match def { GenericDefId::AdtId(AdtId::EnumId(id)) => { let sig = EnumSignature::of(db, id); - (sig.generic_params.clone(), &sig.store) + (&sig.generic_params, &sig.store) } GenericDefId::AdtId(AdtId::StructId(id)) => { let sig = StructSignature::of(db, id); - (sig.generic_params.clone(), &sig.store) + (&sig.generic_params, &sig.store) } GenericDefId::AdtId(AdtId::UnionId(id)) => { let sig = UnionSignature::of(db, id); - (sig.generic_params.clone(), &sig.store) + (&sig.generic_params, &sig.store) + } + GenericDefId::ConstId(id) => { + let sig = ConstSignature::of(db, id); + (&EMPTY, &sig.store) } GenericDefId::FunctionId(id) => { let sig = FunctionSignature::of(db, id); - (sig.generic_params.clone(), &sig.store) + (&sig.generic_params, &sig.store) } GenericDefId::ImplId(id) => { let sig = ImplSignature::of(db, id); - (sig.generic_params.clone(), &sig.store) + (&sig.generic_params, &sig.store) + } + GenericDefId::StaticId(id) => { + let sig = StaticSignature::of(db, id); + (&EMPTY, &sig.store) } GenericDefId::TraitId(id) => { let sig = TraitSignature::of(db, id); - (sig.generic_params.clone(), &sig.store) + (&sig.generic_params, &sig.store) } GenericDefId::TypeAliasId(id) => { let sig = TypeAliasSignature::of(db, id); - (sig.generic_params.clone(), &sig.store) - } - GenericDefId::ConstId(id) => { - let sig = ConstSignature::of(db, id); - (EMPTY.clone(), &sig.store) - } - GenericDefId::StaticId(id) => { - let sig = StaticSignature::of(db, id); - (EMPTY.clone(), &sig.store) + (&sig.generic_params, &sig.store) } } } @@ -239,43 +239,43 @@ impl GenericParams { pub fn with_source_map( db: &dyn DefDatabase, def: GenericDefId, - ) -> (Arc<GenericParams>, &ExpressionStore, &ExpressionStoreSourceMap) { + ) -> (&GenericParams, &ExpressionStore, &ExpressionStoreSourceMap) { match def { GenericDefId::AdtId(AdtId::EnumId(id)) => { let (sig, sm) = EnumSignature::with_source_map(db, id); - (sig.generic_params.clone(), &sig.store, sm) + (&sig.generic_params, &sig.store, sm) } GenericDefId::AdtId(AdtId::StructId(id)) => { let (sig, sm) = StructSignature::with_source_map(db, id); - (sig.generic_params.clone(), &sig.store, sm) + (&sig.generic_params, &sig.store, sm) } GenericDefId::AdtId(AdtId::UnionId(id)) => { let (sig, sm) = UnionSignature::with_source_map(db, id); - (sig.generic_params.clone(), &sig.store, sm) + (&sig.generic_params, &sig.store, sm) } GenericDefId::ConstId(id) => { let (sig, sm) = ConstSignature::with_source_map(db, id); - (EMPTY.clone(), &sig.store, sm) + (&EMPTY, &sig.store, sm) } GenericDefId::FunctionId(id) => { let (sig, sm) = FunctionSignature::with_source_map(db, id); - (sig.generic_params.clone(), &sig.store, sm) + (&sig.generic_params, &sig.store, sm) } GenericDefId::ImplId(id) => { let (sig, sm) = ImplSignature::with_source_map(db, id); - (sig.generic_params.clone(), &sig.store, sm) + (&sig.generic_params, &sig.store, sm) } GenericDefId::StaticId(id) => { let (sig, sm) = StaticSignature::with_source_map(db, id); - (EMPTY.clone(), &sig.store, sm) + (&EMPTY, &sig.store, sm) } GenericDefId::TraitId(id) => { let (sig, sm) = TraitSignature::with_source_map(db, id); - (sig.generic_params.clone(), &sig.store, sm) + (&sig.generic_params, &sig.store, sm) } GenericDefId::TypeAliasId(id) => { let (sig, sm) = TypeAliasSignature::with_source_map(db, id); - (sig.generic_params.clone(), &sig.store, sm) + (&sig.generic_params, &sig.store, sm) } } } 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 9ffa80346c..dee7800e84 100644 --- a/crates/hir-def/src/resolver.rs +++ b/crates/hir-def/src/resolver.rs @@ -13,7 +13,6 @@ use rustc_hash::FxHashSet; use smallvec::{SmallVec, smallvec}; use span::SyntaxContext; use syntax::ast::HasName; -use triomphe::Arc; use crate::{ AdtId, AstIdLoc, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, @@ -87,7 +86,7 @@ enum Scope<'db> { BlockScope(ModuleItemMap<'db>), /// Brings the generic parameters of an item into scope as well as the `Self` type alias / /// generic for ADTs and impls. - GenericParams { def: GenericDefId, params: Arc<GenericParams> }, + GenericParams { def: GenericDefId, params: &'db GenericParams }, /// Local bindings ExprScope(ExprScope<'db>), /// Macro definition inside bodies that affects all paths after it in the same block. @@ -725,14 +724,14 @@ impl<'db> Resolver<'db> { pub fn generic_params(&self) -> Option<&GenericParams> { self.scopes().find_map(|scope| match scope { - Scope::GenericParams { params, .. } => Some(&**params), + &Scope::GenericParams { params, .. } => Some(params), _ => None, }) } - pub fn all_generic_params(&self) -> impl Iterator<Item = (&GenericParams, &GenericDefId)> { + pub fn all_generic_params(&self) -> impl Iterator<Item = (&GenericParams, GenericDefId)> { self.scopes().filter_map(|scope| match scope { - Scope::GenericParams { params, def } => Some((&**params, def)), + &Scope::GenericParams { params, def } => Some((params, def)), _ => None, }) } @@ -1021,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 { @@ -1031,7 +1030,7 @@ impl<'db> Scope<'db> { for (local_id, param) in params.iter_type_or_consts() { if let Some(name) = ¶m.name() { let id = TypeOrConstParamId { parent, local_id }; - let data = &db.generic_params(parent)[local_id]; + let data = &GenericParams::of(db, parent)[local_id]; acc.add( name, ScopeDef::GenericParam(match data { @@ -1115,7 +1114,7 @@ impl<'db> Resolver<'db> { db: &'db dyn DefDatabase, def: GenericDefId, ) -> Resolver<'db> { - let params = db.generic_params(def); + let params = GenericParams::of(db, def); self.push_scope(Scope::GenericParams { def, params }) } diff --git a/crates/hir-def/src/signatures.rs b/crates/hir-def/src/signatures.rs index 7862049f99..c16ca6d0b4 100644 --- a/crates/hir-def/src/signatures.rs +++ b/crates/hir-def/src/signatures.rs @@ -43,7 +43,7 @@ fn as_name_opt(name: Option<ast::Name>) -> Name { #[derive(Debug, PartialEq, Eq)] pub struct StructSignature { pub name: Name, - pub generic_params: Arc<GenericParams>, + pub generic_params: GenericParams, pub store: ExpressionStore, pub flags: StructFlags, pub shape: FieldsShape, @@ -153,7 +153,7 @@ fn adt_shape(adt_kind: ast::StructKind) -> FieldsShape { #[derive(Debug, PartialEq, Eq)] pub struct UnionSignature { pub name: Name, - pub generic_params: Arc<GenericParams>, + pub generic_params: GenericParams, pub store: ExpressionStore, pub flags: StructFlags, } @@ -217,7 +217,7 @@ bitflags! { #[derive(Debug, PartialEq, Eq)] pub struct EnumSignature { pub name: Name, - pub generic_params: Arc<GenericParams>, + pub generic_params: GenericParams, pub store: ExpressionStore, pub flags: EnumFlags, } @@ -290,7 +290,7 @@ bitflags::bitflags! { #[derive(Debug, PartialEq, Eq)] pub struct ConstSignature { pub name: Option<Name>, - // generic_params: Arc<GenericParams>, + // generic_params: GenericParams, pub store: ExpressionStore, pub type_ref: TypeRefId, pub flags: ConstFlags, @@ -358,7 +358,7 @@ bitflags::bitflags! { pub struct StaticSignature { pub name: Name, - // generic_params: Arc<GenericParams>, + // generic_params: GenericParams, pub store: ExpressionStore, pub type_ref: TypeRefId, pub flags: StaticFlags, @@ -429,7 +429,7 @@ bitflags::bitflags! { #[derive(Debug, PartialEq, Eq)] pub struct ImplSignature { - pub generic_params: Arc<GenericParams>, + pub generic_params: GenericParams, pub store: ExpressionStore, pub self_ty: TypeRefId, pub target_trait: Option<TraitRef>, @@ -502,7 +502,7 @@ bitflags::bitflags! { #[derive(Debug, PartialEq, Eq)] pub struct TraitSignature { pub name: Name, - pub generic_params: Arc<GenericParams>, + pub generic_params: GenericParams, pub store: ExpressionStore, pub flags: TraitFlags, } @@ -586,7 +586,7 @@ bitflags! { #[derive(Debug, PartialEq, Eq)] pub struct FunctionSignature { pub name: Name, - pub generic_params: Arc<GenericParams>, + pub generic_params: GenericParams, pub store: ExpressionStore, pub params: Box<[TypeRefId]>, pub ret_type: Option<TypeRefId>, @@ -762,7 +762,7 @@ bitflags! { #[derive(Debug, PartialEq, Eq)] pub struct TypeAliasSignature { pub name: Name, - pub generic_params: Arc<GenericParams>, + pub generic_params: GenericParams, pub store: ExpressionStore, pub bounds: Box<[TypeBound]>, pub ty: Option<TypeRefId>, diff --git a/crates/hir-def/src/src.rs b/crates/hir-def/src/src.rs index 6fe016f1e6..e33fd95908 100644 --- a/crates/hir-def/src/src.rs +++ b/crates/hir-def/src/src.rs @@ -7,7 +7,7 @@ use syntax::{AstNode, AstPtr, ast}; use crate::{ AstIdLoc, GenericDefId, LocalFieldId, LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, - UseId, VariantId, attrs::AttrFlags, db::DefDatabase, + UseId, VariantId, attrs::AttrFlags, db::DefDatabase, hir::generics::GenericParams, }; pub trait HasSource { @@ -76,7 +76,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId { &self, db: &dyn DefDatabase, ) -> InFile<ArenaMap<LocalTypeOrConstParamId, Self::Value>> { - let generic_params = db.generic_params(*self); + let generic_params = GenericParams::of(db, *self); let mut idx_iter = generic_params.iter_type_or_consts().map(|(idx, _)| idx); let (file_id, generic_params_list) = self.file_id_and_params_of(db); @@ -110,7 +110,7 @@ impl HasChildSource<LocalLifetimeParamId> for GenericDefId { &self, db: &dyn DefDatabase, ) -> InFile<ArenaMap<LocalLifetimeParamId, Self::Value>> { - let generic_params = db.generic_params(*self); + let generic_params = GenericParams::of(db, *self); let idx_iter = generic_params.iter_lt().map(|(idx, _)| idx); let (file_id, generic_params_list) = self.file_id_and_params_of(db); 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 5a93c2b536..92629b7a05 100644 --- a/crates/hir-ty/src/builtin_derive.rs +++ b/crates/hir-ty/src/builtin_derive.rs @@ -80,7 +80,7 @@ pub(crate) fn generics_of<'db>(interner: DbInterner<'db>, id: BuiltinDeriveImplI pub fn generic_params_count(db: &dyn HirDatabase, id: BuiltinDeriveImplId) -> usize { let loc = id.loc(db); - let adt_params = GenericParams::new(db, loc.adt.into()); + let adt_params = GenericParams::of(db, loc.adt.into()); let extra_params_count = match loc.trait_ { BuiltinDeriveImplTrait::Copy | BuiltinDeriveImplTrait::Clone @@ -128,12 +128,12 @@ pub fn impl_trait<'db>( )) } BuiltinDeriveImplTrait::CoerceUnsized | BuiltinDeriveImplTrait::DispatchFromDyn => { - let generic_params = GenericParams::new(db, loc.adt.into()); + let generic_params = GenericParams::of(db, loc.adt.into()); let interner = DbInterner::new_no_crate(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( @@ -152,7 +152,7 @@ pub fn impl_trait<'db>( #[salsa::tracked(returns(ref))] pub fn predicates<'db>(db: &'db dyn HirDatabase, impl_: BuiltinDeriveImplId) -> GenericPredicates { let loc = impl_.loc(db); - let generic_params = GenericParams::new(db, loc.adt.into()); + let generic_params = GenericParams::of(db, loc.adt.into()); let interner = DbInterner::new_with(db, loc.module(db).krate(db)); let adt_predicates = GenericPredicates::query(db, loc.adt.into()); let trait_id = loc @@ -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/display.rs b/crates/hir-ty/src/display.rs index 54cd750de6..d680588645 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -14,7 +14,7 @@ use hir_def::{ Lookup, ModuleDefId, ModuleId, TraitId, expr_store::{ExpressionStore, path::Path}, find_path::{self, PrefixKind}, - hir::generics::{TypeOrConstParamData, TypeParamProvenance, WherePredicate}, + hir::generics::{GenericParams, TypeOrConstParamData, TypeParamProvenance, WherePredicate}, item_scope::ItemInNs, item_tree::FieldsShape, lang_item::LangItems, @@ -2141,7 +2141,7 @@ impl<'db> HirDisplayWithExpressionStore<'db> for LifetimeRefId { LifetimeRef::Placeholder => write!(f, "'_"), LifetimeRef::Error => write!(f, "'{{error}}"), &LifetimeRef::Param(lifetime_param_id) => { - let generic_params = f.db.generic_params(lifetime_param_id.parent); + let generic_params = GenericParams::of(f.db, lifetime_param_id.parent); write!( f, "{}", @@ -2157,7 +2157,7 @@ impl<'db> HirDisplayWithExpressionStore<'db> for TypeRefId { match &store[*self] { TypeRef::Never => write!(f, "!")?, TypeRef::TypeParam(param) => { - let generic_params = f.db.generic_params(param.parent()); + let generic_params = GenericParams::of(f.db, param.parent()); match generic_params[param.local_id()].name() { Some(name) => write!(f, "{}", name.display(f.db, f.edition()))?, None => { diff --git a/crates/hir-ty/src/dyn_compatibility.rs b/crates/hir-ty/src/dyn_compatibility.rs index d8093b3eb1..4c300affd8 100644 --- a/crates/hir-ty/src/dyn_compatibility.rs +++ b/crates/hir-ty/src/dyn_compatibility.rs @@ -5,7 +5,7 @@ use std::ops::ControlFlow; use hir_def::{ AssocItemId, ConstId, FunctionId, GenericDefId, HasModule, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, - hir::generics::LocalTypeOrConstParamId, + hir::generics::{GenericParams, LocalTypeOrConstParamId}, nameres::crate_def_map, signatures::{FunctionSignature, TraitFlags, TraitSignature}, }; @@ -300,7 +300,7 @@ where if def_map.is_unstable_feature_enabled(&intern::sym::generic_associated_type_extended) { ControlFlow::Continue(()) } else { - let generic_params = db.generic_params(item.into()); + let generic_params = GenericParams::of(db, item.into()); if !generic_params.is_empty() { cb(DynCompatibilityViolation::GAT(it)) } else { @@ -351,7 +351,7 @@ where cb(mvc)?; } - let generic_params = db.generic_params(func.into()); + let generic_params = GenericParams::of(db, func.into()); if generic_params.len_type_or_consts() > 0 { cb(MethodViolationCode::Generic)?; } diff --git a/crates/hir-ty/src/generics.rs b/crates/hir-ty/src/generics.rs index 57fe4d749b..822942eec3 100644 --- a/crates/hir-ty/src/generics.rs +++ b/crates/hir-ty/src/generics.rs @@ -20,18 +20,17 @@ use hir_def::{ }, }; use itertools::chain; -use triomphe::Arc; pub fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics<'_> { let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def))); - let (params, store) = GenericParams::of(db, def); + let (params, store) = GenericParams::with_store(db, def); let has_trait_self_param = params.trait_self_param().is_some(); Generics { def, params, parent_generics, has_trait_self_param, store } } #[derive(Clone, Debug)] pub struct Generics<'db> { def: GenericDefId, - params: Arc<GenericParams>, + params: &'db GenericParams, store: &'db ExpressionStore, parent_generics: Option<Box<Generics<'db>>>, has_trait_self_param: bool, diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index 3ed563315e..5eee025f2c 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -1590,7 +1590,7 @@ pub(crate) fn const_param_ty_with_diagnostics<'db>( _: (), def: ConstParamId, ) -> (StoredTy, Diagnostics) { - let (parent_data, store) = GenericParams::of(db, def.parent()); + let (parent_data, store) = GenericParams::with_store(db, def.parent()); let data = &parent_data[def.local_id()]; let resolver = def.parent().resolver(db); let interner = DbInterner::new_no_crate(db); diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index e058a25420..05b9ea5d74 100644 --- a/crates/hir-ty/src/method_resolution.rs +++ b/crates/hir-ty/src/method_resolution.rs @@ -18,7 +18,7 @@ use hir_def::{ attrs::AttrFlags, builtin_derive::BuiltinDeriveImplMethod, expr_store::{Body, path::GenericArgs as HirGenericArgs}, - hir::ExprId, + hir::{ExprId, generics::GenericParams}, lang_item::LangItems, nameres::{DefMap, block_def_map, crate_def_map}, resolver::Resolver, @@ -397,7 +397,7 @@ pub fn is_dyn_method<'db>( let ItemContainerId::TraitId(trait_id) = func.loc(db).container else { return None; }; - let trait_params = db.generic_params(trait_id.into()).len(); + let trait_params = GenericParams::of(db, trait_id.into()).len(); let fn_params = fn_subst.len() - trait_params; let trait_ref = TraitRef::new_from_args( interner, @@ -433,7 +433,7 @@ pub(crate) fn lookup_impl_method_query<'db>( let ItemContainerId::TraitId(trait_id) = func.loc(db).container else { return (Either::Left(func), fn_subst); }; - let trait_params = db.generic_params(trait_id.into()).len(); + let trait_params = GenericParams::of(db, trait_id.into()).len(); let trait_ref = TraitRef::new_from_args( interner, trait_id.into(), diff --git a/crates/hir-ty/src/method_resolution/probe.rs b/crates/hir-ty/src/method_resolution/probe.rs index e2a53cc830..8c76bfbc07 100644 --- a/crates/hir-ty/src/method_resolution/probe.rs +++ b/crates/hir-ty/src/method_resolution/probe.rs @@ -5,6 +5,7 @@ use std::{cell::RefCell, convert::Infallible, ops::ControlFlow}; use hir_def::{ AssocItemId, FunctionId, GenericParamId, ImplId, ItemContainerId, TraitId, + hir::generics::GenericParams, signatures::{FunctionSignature, TraitFlags, TraitSignature}, }; use hir_expand::name::Name; @@ -2010,7 +2011,7 @@ impl<'a, 'db, Choice: ProbeChoice<'db>> ProbeContext<'a, 'db, Choice> { // we are given do not include type/lifetime parameters for the // method yet. So create fresh variables here for those too, // if there are any. - let generics = self.db().generic_params(method.into()); + let generics = GenericParams::of(self.db(), method.into()); let xform_fn_sig = if generics.is_empty() { fn_sig.instantiate(self.interner(), args) diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 8d85e2412f..675fc371c6 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -9,7 +9,7 @@ use hir_def::{ expr_store::{Body, ExpressionStore, HygieneId, path::Path}, hir::{ ArithOp, Array, BinaryOp, BindingAnnotation, BindingId, ExprId, LabelId, Literal, MatchArm, - Pat, PatId, RecordFieldPat, RecordLitField, RecordSpread, + Pat, PatId, RecordFieldPat, RecordLitField, RecordSpread, generics::GenericParams, }, item_tree::FieldsShape, lang_item::LangItems, @@ -203,13 +203,13 @@ impl MirLowerError { MirLowerError::GenericArgNotProvided(id, subst) => { let param_name = match *id { GenericParamId::TypeParamId(id) => { - db.generic_params(id.parent())[id.local_id()].name().cloned() + GenericParams::of(db, id.parent())[id.local_id()].name().cloned() } GenericParamId::ConstParamId(id) => { - db.generic_params(id.parent())[id.local_id()].name().cloned() + GenericParams::of(db, id.parent())[id.local_id()].name().cloned() } GenericParamId::LifetimeParamId(id) => { - Some(db.generic_params(id.parent)[id.local_id].name.clone()) + Some(GenericParams::of(db, id.parent)[id.local_id].name.clone()) } }; writeln!( diff --git a/crates/hir-ty/src/next_solver/generics.rs b/crates/hir-ty/src/next_solver/generics.rs index a8288b4e82..f31de21796 100644 --- a/crates/hir-ty/src/next_solver/generics.rs +++ b/crates/hir-ty/src/next_solver/generics.rs @@ -55,7 +55,7 @@ pub(crate) fn generics(interner: DbInterner<'_>, def: SolverDefId) -> Generics { let (parent, own_params) = match (def.try_into(), def) { (Ok(def), _) => ( parent_generic_def(db, def), - own_params_for_generic_params(def, &db.generic_params(def)), + own_params_for_generic_params(def, GenericParams::of(db, def)), ), (_, SolverDefId::InternedOpaqueTyId(id)) => { match db.lookup_intern_impl_trait_id(id) { diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index 09b1585866..192cdb70ae 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -4,7 +4,7 @@ use std::ops::ControlFlow; use hir_def::{ AdtId, HasModule, TypeParamId, - hir::generics::{TypeOrConstParamData, TypeParamProvenance}, + hir::generics::{GenericParams, TypeOrConstParamData, TypeParamProvenance}, }; use hir_def::{TraitId, type_ref::Rawness}; use intern::{Interned, InternedRef, impl_internable}; @@ -690,7 +690,7 @@ impl<'db> Ty<'db> { ), TyKind::Param(param) => { // FIXME: We shouldn't use `param.id` here. - let generic_params = db.generic_params(param.id.parent()); + let generic_params = GenericParams::of(db, param.id.parent()); let param_data = &generic_params[param.id.local_id()]; match param_data { TypeOrConstParamData::TypeParamData(p) => match p.provenance { diff --git a/crates/hir-ty/src/representability.rs b/crates/hir-ty/src/representability.rs index 7e40f2d7ac..bae204c4ef 100644 --- a/crates/hir-ty/src/representability.rs +++ b/crates/hir-ty/src/representability.rs @@ -1,6 +1,6 @@ //! Detecting whether a type is infinitely-sized. -use hir_def::{AdtId, VariantId}; +use hir_def::{AdtId, VariantId, hir::generics::GenericParams}; use rustc_type_ir::inherent::{AdtDef, IntoKind}; use crate::{ @@ -88,7 +88,7 @@ fn representability_adt_ty<'db>( } fn params_in_repr(db: &dyn HirDatabase, def_id: AdtId) -> Box<[bool]> { - let generics = db.generic_params(def_id.into()); + let generics = GenericParams::of(db, def_id.into()); let mut params_in_repr = (0..generics.len_lifetimes() + generics.len_type_or_consts()) .map(|_| false) .collect::<Box<[bool]>>(); 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/attrs.rs b/crates/hir/src/attrs.rs index cfb95e07c3..4efb7fcb6f 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -7,6 +7,7 @@ use hir_def::{ TraitId, TypeOrConstParamId, attrs::{AttrFlags, Docs, IsInnerDoc}, expr_store::path::Path, + hir::generics::GenericParams, item_scope::ItemInNs, per_ns::Namespace, resolver::{HasResolver, Resolver, TypeNs}, @@ -377,7 +378,7 @@ fn resolve_assoc_or_field( let ty = match base_def { TypeNs::SelfType(id) => Impl::from(id).self_ty(db), TypeNs::GenericParam(param) => { - let generic_params = db.generic_params(param.parent()); + let generic_params = GenericParams::of(db, param.parent()); if generic_params[param.local_id()].is_trait_self() { // `Self::assoc` in traits should refer to the trait itself. let parent_trait = |container| match container { diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 826b8d5f80..ef885f0be8 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -41,7 +41,7 @@ fn write_builtin_derive_impl_method<'db>( ) -> Result { let db = f.db; let loc = impl_.loc(db); - let (adt_params, _adt_params_store) = GenericParams::of(db, loc.adt.into()); + let adt_params = GenericParams::of(db, loc.adt.into()); if f.show_container_bounds() && !adt_params.is_empty() { f.write_str("impl")?; @@ -97,22 +97,22 @@ impl<'db> HirDisplay<'db> for Function { // Write container (trait or impl) let container_params = match container { ItemContainerId::TraitId(trait_) => { - let (params, params_store) = GenericParams::of(f.db, trait_.into()); + let (params, params_store) = GenericParams::with_store(f.db, trait_.into()); 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 } } ItemContainerId::ImplId(impl_) => { - let (params, params_store) = GenericParams::of(f.db, impl_.into()); + let (params, params_store) = GenericParams::with_store(f.db, impl_.into()); 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(()) } @@ -572,7 +572,7 @@ impl<'db> HirDisplay<'db> for TypeOrConstParam { impl<'db> HirDisplay<'db> for TypeParam { fn hir_fmt(&self, f: &mut HirFormatter<'_, 'db>) -> Result { - let params = f.db.generic_params(self.id.parent()); + let params = GenericParams::of(f.db, self.id.parent()); let param_data = ¶ms[self.id.local_id()]; let krate = self.id.parent().krate(f.db).id; let ty = self.ty(f.db).ty; @@ -660,7 +660,7 @@ fn write_generic_params_or_args<'db>( f: &mut HirFormatter<'_, 'db>, include_defaults: bool, ) -> Result { - let (params, store) = GenericParams::of(f.db, def); + let (params, store) = GenericParams::with_store(f.db, def); if params.iter_lt().next().is_none() && params.iter_type_or_consts().all(|it| it.1.const_param().is_none()) && params @@ -718,13 +718,13 @@ fn write_generic_params_or_args<'db>( } fn write_where_clause<'db>(def: GenericDefId, f: &mut HirFormatter<'_, 'db>) -> Result<bool> { - let (params, store) = GenericParams::of(f.db, def); - if !has_disaplayable_predicates(f.db, ¶ms, store) { + let (params, store) = GenericParams::with_store(f.db, def); + 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) } @@ -739,7 +739,7 @@ fn has_disaplayable_predicates( pred, WherePredicate::TypeBound { target, .. } if matches!(store[*target], - TypeRef::TypeParam(id) if db.generic_params(id.parent())[id.local_id()].name().is_none() + TypeRef::TypeParam(id) if GenericParams::of(db,id.parent())[id.local_id()].name().is_none() ) ) }) @@ -755,7 +755,7 @@ fn write_where_predicates<'db>( // unnamed type targets are displayed inline with the argument itself, e.g. `f: impl Y`. let is_unnamed_type_target = |target: TypeRefId| { matches!(store[target], - TypeRef::TypeParam(id) if f.db.generic_params(id.parent())[id.local_id()].name().is_none() + TypeRef::TypeParam(id) if GenericParams::of(f.db,id.parent())[id.local_id()].name().is_none() ) }; diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 4d4482b1af..67527150bd 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -58,7 +58,7 @@ use hir_def::{ expr_store::{ExpressionStore, ExpressionStoreDiagnostics, ExpressionStoreSourceMap}, hir::{ BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, LabelId, Pat, - generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, + generics::{GenericParams, LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, }, item_tree::ImportAlias, lang_item::LangItemTarget, @@ -3275,7 +3275,7 @@ impl Trait { db: &dyn HirDatabase, count_required_only: bool, ) -> usize { - db.generic_params(self.id.into()) + GenericParams::of(db,self.id.into()) .iter_type_or_consts() .filter(|(_, ty)| !matches!(ty, TypeOrConstParamData::TypeParamData(ty) if ty.provenance != TypeParamProvenance::TypeParamList)) .filter(|(_, ty)| !count_required_only || !ty.has_default()) @@ -4065,7 +4065,7 @@ impl GenericDef { // Let's pretend builtin derive impls don't have generic parameters. return Vec::new(); }; - let generics = db.generic_params(id); + let generics = GenericParams::of(db, id); let ty_params = generics.iter_type_or_consts().map(|(local_id, _)| { let toc = TypeOrConstParam { id: TypeOrConstParamId { parent: id, local_id } }; match toc.split(db) { @@ -4085,7 +4085,7 @@ impl GenericDef { // Let's pretend builtin derive impls don't have generic parameters. return Vec::new(); }; - let generics = db.generic_params(id); + let generics = GenericParams::of(db, id); generics .iter_lt() .map(|(local_id, _)| LifetimeParam { id: LifetimeParamId { parent: id, local_id } }) @@ -4097,7 +4097,7 @@ impl GenericDef { // Let's pretend builtin derive impls don't have generic parameters. return Vec::new(); }; - let generics = db.generic_params(id); + let generics = GenericParams::of(db, id); generics .iter_type_or_consts() .map(|(local_id, _)| TypeOrConstParam { @@ -4127,7 +4127,7 @@ impl GenericDef { pub fn diagnostics<'db>(self, db: &'db dyn HirDatabase, acc: &mut Vec<AnyDiagnostic<'db>>) { let Some(def) = self.id() else { return }; - let generics = db.generic_params(def); + let generics = GenericParams::of(db, def); if generics.is_empty() && generics.has_no_predicates() { return; @@ -4223,7 +4223,7 @@ impl<'db> GenericSubstitution<'db> { _ => None, }) .map(|container| { - db.generic_params(container) + GenericParams::of(db, container) .iter_type_or_consts() .filter_map(|param| match param.1 { TypeOrConstParamData::TypeParamData(param) => Some(param.name.clone()), @@ -4231,7 +4231,7 @@ impl<'db> GenericSubstitution<'db> { }) .collect::<Vec<_>>() }); - let generics = db.generic_params(self.def); + let generics = GenericParams::of(db, self.def); let type_params = generics.iter_type_or_consts().filter_map(|param| match param.1 { TypeOrConstParamData::TypeParamData(param) => Some(param.name.clone()), TypeOrConstParamData::ConstParamData(_) => None, @@ -4653,7 +4653,7 @@ impl TypeParam { /// Is this type parameter implicitly introduced (eg. `Self` in a trait or an `impl Trait` /// argument)? pub fn is_implicit(self, db: &dyn HirDatabase) -> bool { - let params = db.generic_params(self.id.parent()); + let params = GenericParams::of(db, self.id.parent()); let data = ¶ms[self.id.local_id()]; match data.type_param().unwrap().provenance { TypeParamProvenance::TypeParamList => false, @@ -4708,7 +4708,7 @@ pub struct LifetimeParam { impl LifetimeParam { pub fn name(self, db: &dyn HirDatabase) -> Name { - let params = db.generic_params(self.id.parent); + let params = GenericParams::of(db, self.id.parent); params[self.id.local_id].name.clone() } @@ -4732,7 +4732,7 @@ impl ConstParam { } pub fn name(self, db: &dyn HirDatabase) -> Name { - let params = db.generic_params(self.id.parent()); + let params = GenericParams::of(db, self.id.parent()); match params[self.id.local_id()].name() { Some(it) => it.clone(), None => { @@ -4779,7 +4779,7 @@ pub struct TypeOrConstParam { impl TypeOrConstParam { pub fn name(self, db: &dyn HirDatabase) -> Name { - let params = db.generic_params(self.id.parent); + let params = GenericParams::of(db, self.id.parent); match params[self.id.local_id].name() { Some(n) => n.clone(), _ => Name::missing(), @@ -4795,7 +4795,7 @@ impl TypeOrConstParam { } pub fn split(self, db: &dyn HirDatabase) -> Either<ConstParam, TypeParam> { - let params = db.generic_params(self.id.parent); + let params = GenericParams::of(db, self.id.parent); match ¶ms[self.id.local_id] { TypeOrConstParamData::TypeParamData(_) => { Either::Right(TypeParam { id: TypeParamId::from_unchecked(self.id) }) @@ -4814,7 +4814,7 @@ impl TypeOrConstParam { } pub fn as_type_param(self, db: &dyn HirDatabase) -> Option<TypeParam> { - let params = db.generic_params(self.id.parent); + let params = GenericParams::of(db, self.id.parent); match ¶ms[self.id.local_id] { TypeOrConstParamData::TypeParamData(_) => { Some(TypeParam { id: TypeParamId::from_unchecked(self.id) }) @@ -4824,7 +4824,7 @@ impl TypeOrConstParam { } pub fn as_const_param(self, db: &dyn HirDatabase) -> Option<ConstParam> { - let params = db.generic_params(self.id.parent); + let params = GenericParams::of(db, self.id.parent); match ¶ms[self.id.local_id] { TypeOrConstParamData::TypeParamData(_) => None, TypeOrConstParamData::ConstParamData(_) => { @@ -7229,7 +7229,7 @@ fn generic_args_from_tys<'db>( } fn has_non_default_type_params(db: &dyn HirDatabase, generic_def: GenericDefId) -> bool { - let params = db.generic_params(generic_def); + let params = GenericParams::of(db, generic_def); let defaults = db.generic_defaults(generic_def); params .iter_type_or_consts() diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index bd77347e93..1b41c78892 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -55,7 +55,6 @@ use syntax::{ SyntaxKind, SyntaxNode, TextRange, TextSize, ast::{self, AstNode, RangeItem, RangeOp}, }; -use triomphe::Arc; use crate::{ Adt, AnyFunctionId, AssocItem, BindingMode, BuiltinAttr, BuiltinType, Callable, Const, @@ -94,7 +93,7 @@ pub(crate) enum BodyOrSig<'db> { source_map: &'db ExpressionStoreSourceMap, infer: Option<&'db InferenceResult>, #[expect(dead_code)] - generics: Arc<GenericParams>, + generics: &'db GenericParams, }, } @@ -882,7 +881,7 @@ impl<'db> SourceAnalyzer<'db> { let name = name.as_name(); self.resolver .all_generic_params() - .find_map(|(params, parent)| params.find_type_by_name(&name, *parent)) + .find_map(|(params, parent)| params.find_type_by_name(&name, parent)) .map(crate::TypeParam::from) } 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(()) => { diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 43e73175c8..7541a41b20 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -18,7 +18,7 @@ use hir::{ use hir_def::{ DefWithBodyId, ExpressionStoreOwnerId, GenericDefId, SyntheticSyntax, expr_store::{Body, BodySourceMap, ExpressionStore}, - hir::{ExprId, PatId}, + hir::{ExprId, PatId, generics::GenericParams}, }; use hir_ty::InferenceResult; use ide::{ @@ -394,7 +394,7 @@ impl flags::AnalysisStats { let mut fail = 0; for &a in adts { let interner = DbInterner::new_no_crate(db); - let generic_params = db.generic_params(a.into()); + let generic_params = GenericParams::of(db, a.into()); if generic_params.iter_type_or_consts().next().is_some() || generic_params.iter_lt().next().is_some() { |