From c12f7b610be49901190cde994dfe4f594150dbf9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 17 Jun 2020 12:24:05 +0200 Subject: Lower generics --- crates/ra_hir_def/src/generics.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_def/src/generics.rs') diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 09a5241f7..ed4f60c66 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -42,7 +42,7 @@ pub enum TypeParamProvenance { } /// Data about the generic parameters of a function, struct, impl, etc. -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Clone, PartialEq, Eq, Debug, Default)] pub struct GenericParams { pub types: Arena, // lifetimes: Arena, @@ -156,7 +156,12 @@ impl GenericParams { (generics, InFile::new(file_id, sm)) } - fn fill(&mut self, lower_ctx: &LowerCtx, sm: &mut SourceMap, node: &dyn TypeParamsOwner) { + pub(crate) fn fill( + &mut self, + lower_ctx: &LowerCtx, + sm: &mut SourceMap, + node: &dyn TypeParamsOwner, + ) { if let Some(params) = node.type_param_list() { self.fill_params(lower_ctx, sm, params) } @@ -165,7 +170,7 @@ impl GenericParams { } } - fn fill_bounds( + pub(crate) fn fill_bounds( &mut self, lower_ctx: &LowerCtx, node: &dyn ast::TypeBoundsOwner, @@ -229,7 +234,7 @@ impl GenericParams { .push(WherePredicate { target: WherePredicateTarget::TypeRef(type_ref), bound }); } - fn fill_implicit_impl_trait_args(&mut self, type_ref: &TypeRef) { + pub(crate) fn fill_implicit_impl_trait_args(&mut self, type_ref: &TypeRef) { type_ref.walk(&mut |type_ref| { if let TypeRef::ImplTrait(bounds) = type_ref { let param = TypeParamData { -- cgit v1.2.3 From ffa0435050ae57c5171c19224ca6e9f8a4e3435d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 22 Jun 2020 19:15:54 +0200 Subject: Make generics and attr queries use ItemTree Now it's fast --- crates/ra_hir_def/src/generics.rs | 49 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/generics.rs') diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index ed4f60c66..c4b9f626f 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -74,8 +74,53 @@ impl GenericParams { def: GenericDefId, ) -> Arc { let _p = profile("generic_params_query"); - let (params, _source_map) = GenericParams::new(db, def); - Arc::new(params) + + let generics = match def { + GenericDefId::FunctionId(id) => { + let id = id.lookup(db).id; + let tree = db.item_tree(id.file_id); + let item = &tree[id.value]; + item.generic_params.clone() + } + GenericDefId::AdtId(AdtId::StructId(id)) => { + let id = id.lookup(db).id; + let tree = db.item_tree(id.file_id); + let item = &tree[id.value]; + item.generic_params.clone() + } + GenericDefId::AdtId(AdtId::EnumId(id)) => { + let id = id.lookup(db).id; + let tree = db.item_tree(id.file_id); + let item = &tree[id.value]; + item.generic_params.clone() + } + GenericDefId::AdtId(AdtId::UnionId(id)) => { + let id = id.lookup(db).id; + let tree = db.item_tree(id.file_id); + let item = &tree[id.value]; + item.generic_params.clone() + } + GenericDefId::TraitId(id) => { + let id = id.lookup(db).id; + let tree = db.item_tree(id.file_id); + let item = &tree[id.value]; + item.generic_params.clone() + } + GenericDefId::TypeAliasId(id) => { + let id = id.lookup(db).id; + let tree = db.item_tree(id.file_id); + let item = &tree[id.value]; + item.generic_params.clone() + } + GenericDefId::ImplId(id) => { + let id = id.lookup(db).id; + let tree = db.item_tree(id.file_id); + let item = &tree[id.value]; + item.generic_params.clone() + } + GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => GenericParams::default(), + }; + Arc::new(generics) } fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile) { -- cgit v1.2.3 From abdba92334f800d236c65e543377f75327f7307a Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 24 Jun 2020 15:54:35 +0200 Subject: Don't allocate empty generics --- crates/ra_hir_def/src/generics.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir_def/src/generics.rs') diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index c4b9f626f..6a0f493a7 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -80,43 +80,43 @@ impl GenericParams { let id = id.lookup(db).id; let tree = db.item_tree(id.file_id); let item = &tree[id.value]; - item.generic_params.clone() + tree[item.generic_params].clone() } GenericDefId::AdtId(AdtId::StructId(id)) => { let id = id.lookup(db).id; let tree = db.item_tree(id.file_id); let item = &tree[id.value]; - item.generic_params.clone() + tree[item.generic_params].clone() } GenericDefId::AdtId(AdtId::EnumId(id)) => { let id = id.lookup(db).id; let tree = db.item_tree(id.file_id); let item = &tree[id.value]; - item.generic_params.clone() + tree[item.generic_params].clone() } GenericDefId::AdtId(AdtId::UnionId(id)) => { let id = id.lookup(db).id; let tree = db.item_tree(id.file_id); let item = &tree[id.value]; - item.generic_params.clone() + tree[item.generic_params].clone() } GenericDefId::TraitId(id) => { let id = id.lookup(db).id; let tree = db.item_tree(id.file_id); let item = &tree[id.value]; - item.generic_params.clone() + tree[item.generic_params].clone() } GenericDefId::TypeAliasId(id) => { let id = id.lookup(db).id; let tree = db.item_tree(id.file_id); let item = &tree[id.value]; - item.generic_params.clone() + tree[item.generic_params].clone() } GenericDefId::ImplId(id) => { let id = id.lookup(db).id; let tree = db.item_tree(id.file_id); let item = &tree[id.value]; - item.generic_params.clone() + tree[item.generic_params].clone() } GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => GenericParams::default(), }; -- cgit v1.2.3