diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/db.rs | 3 | ||||
-rw-r--r-- | crates/hir_def/src/generics.rs | 37 | ||||
-rw-r--r-- | crates/hir_def/src/intern.rs | 10 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 61 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 8 | ||||
-rw-r--r-- | crates/hir_def/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/resolver.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/utils.rs | 3 |
8 files changed, 46 insertions, 81 deletions
diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs index 068b2ee38..9b7a213a1 100644 --- a/crates/hir_def/src/db.rs +++ b/crates/hir_def/src/db.rs | |||
@@ -13,6 +13,7 @@ use crate::{ | |||
13 | data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData}, | 13 | data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData}, |
14 | generics::GenericParams, | 14 | generics::GenericParams, |
15 | import_map::ImportMap, | 15 | import_map::ImportMap, |
16 | intern::Interned, | ||
16 | item_tree::ItemTree, | 17 | item_tree::ItemTree, |
17 | lang_item::{LangItemTarget, LangItems}, | 18 | lang_item::{LangItemTarget, LangItems}, |
18 | nameres::DefMap, | 19 | nameres::DefMap, |
@@ -113,7 +114,7 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { | |||
113 | fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>; | 114 | fn expr_scopes(&self, def: DefWithBodyId) -> Arc<ExprScopes>; |
114 | 115 | ||
115 | #[salsa::invoke(GenericParams::generic_params_query)] | 116 | #[salsa::invoke(GenericParams::generic_params_query)] |
116 | fn generic_params(&self, def: GenericDefId) -> Arc<GenericParams>; | 117 | fn generic_params(&self, def: GenericDefId) -> Interned<GenericParams>; |
117 | 118 | ||
118 | #[salsa::invoke(Attrs::variants_attrs_query)] | 119 | #[salsa::invoke(Attrs::variants_attrs_query)] |
119 | fn variants_attrs(&self, def: EnumId) -> Arc<ArenaMap<LocalEnumVariantId, Attrs>>; | 120 | fn variants_attrs(&self, def: EnumId) -> Arc<ArenaMap<LocalEnumVariantId, Attrs>>; |
diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index d55c189d4..de5acced8 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs | |||
@@ -2,7 +2,6 @@ | |||
2 | //! structs, impls, traits, etc. This module provides a common HIR for these | 2 | //! structs, impls, traits, etc. This module provides a common HIR for these |
3 | //! generic parameters. See also the `Generics` type and the `generics_of` query | 3 | //! generic parameters. See also the `Generics` type and the `generics_of` query |
4 | //! in rustc. | 4 | //! in rustc. |
5 | use std::sync::Arc; | ||
6 | 5 | ||
7 | use base_db::FileId; | 6 | use base_db::FileId; |
8 | use either::Either; | 7 | use either::Either; |
@@ -27,7 +26,7 @@ use crate::{ | |||
27 | }; | 26 | }; |
28 | 27 | ||
29 | /// Data about a generic type parameter (to a function, struct, impl, ...). | 28 | /// Data about a generic type parameter (to a function, struct, impl, ...). |
30 | #[derive(Clone, PartialEq, Eq, Debug)] | 29 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
31 | pub struct TypeParamData { | 30 | pub struct TypeParamData { |
32 | pub name: Option<Name>, | 31 | pub name: Option<Name>, |
33 | pub default: Option<Interned<TypeRef>>, | 32 | pub default: Option<Interned<TypeRef>>, |
@@ -35,19 +34,19 @@ pub struct TypeParamData { | |||
35 | } | 34 | } |
36 | 35 | ||
37 | /// Data about a generic lifetime parameter (to a function, struct, impl, ...). | 36 | /// Data about a generic lifetime parameter (to a function, struct, impl, ...). |
38 | #[derive(Clone, PartialEq, Eq, Debug)] | 37 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
39 | pub struct LifetimeParamData { | 38 | pub struct LifetimeParamData { |
40 | pub name: Name, | 39 | pub name: Name, |
41 | } | 40 | } |
42 | 41 | ||
43 | /// Data about a generic const parameter (to a function, struct, impl, ...). | 42 | /// Data about a generic const parameter (to a function, struct, impl, ...). |
44 | #[derive(Clone, PartialEq, Eq, Debug)] | 43 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
45 | pub struct ConstParamData { | 44 | pub struct ConstParamData { |
46 | pub name: Name, | 45 | pub name: Name, |
47 | pub ty: Interned<TypeRef>, | 46 | pub ty: Interned<TypeRef>, |
48 | } | 47 | } |
49 | 48 | ||
50 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] | 49 | #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] |
51 | pub enum TypeParamProvenance { | 50 | pub enum TypeParamProvenance { |
52 | TypeParamList, | 51 | TypeParamList, |
53 | TraitSelf, | 52 | TraitSelf, |
@@ -55,7 +54,7 @@ pub enum TypeParamProvenance { | |||
55 | } | 54 | } |
56 | 55 | ||
57 | /// Data about the generic parameters of a function, struct, impl, etc. | 56 | /// Data about the generic parameters of a function, struct, impl, etc. |
58 | #[derive(Clone, PartialEq, Eq, Debug, Default)] | 57 | #[derive(Clone, PartialEq, Eq, Debug, Default, Hash)] |
59 | pub struct GenericParams { | 58 | pub struct GenericParams { |
60 | pub types: Arena<TypeParamData>, | 59 | pub types: Arena<TypeParamData>, |
61 | pub lifetimes: Arena<LifetimeParamData>, | 60 | pub lifetimes: Arena<LifetimeParamData>, |
@@ -67,14 +66,14 @@ pub struct GenericParams { | |||
67 | /// where clauses like `where T: Foo + Bar` are turned into multiple of these. | 66 | /// where clauses like `where T: Foo + Bar` are turned into multiple of these. |
68 | /// It might still result in multiple actual predicates though, because of | 67 | /// It might still result in multiple actual predicates though, because of |
69 | /// associated type bindings like `Iterator<Item = u32>`. | 68 | /// associated type bindings like `Iterator<Item = u32>`. |
70 | #[derive(Clone, PartialEq, Eq, Debug)] | 69 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
71 | pub enum WherePredicate { | 70 | pub enum WherePredicate { |
72 | TypeBound { target: WherePredicateTypeTarget, bound: TypeBound }, | 71 | TypeBound { target: WherePredicateTypeTarget, bound: TypeBound }, |
73 | Lifetime { target: LifetimeRef, bound: LifetimeRef }, | 72 | Lifetime { target: LifetimeRef, bound: LifetimeRef }, |
74 | ForLifetime { lifetimes: Box<[Name]>, target: WherePredicateTypeTarget, bound: TypeBound }, | 73 | ForLifetime { lifetimes: Box<[Name]>, target: WherePredicateTypeTarget, bound: TypeBound }, |
75 | } | 74 | } |
76 | 75 | ||
77 | #[derive(Clone, PartialEq, Eq, Debug)] | 76 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
78 | pub enum WherePredicateTypeTarget { | 77 | pub enum WherePredicateTypeTarget { |
79 | TypeRef(Interned<TypeRef>), | 78 | TypeRef(Interned<TypeRef>), |
80 | /// For desugared where predicates that can directly refer to a type param. | 79 | /// For desugared where predicates that can directly refer to a type param. |
@@ -92,7 +91,7 @@ impl GenericParams { | |||
92 | pub(crate) fn generic_params_query( | 91 | pub(crate) fn generic_params_query( |
93 | db: &dyn DefDatabase, | 92 | db: &dyn DefDatabase, |
94 | def: GenericDefId, | 93 | def: GenericDefId, |
95 | ) -> Arc<GenericParams> { | 94 | ) -> Interned<GenericParams> { |
96 | let _p = profile::span("generic_params_query"); | 95 | let _p = profile::span("generic_params_query"); |
97 | 96 | ||
98 | let generics = match def { | 97 | let generics = match def { |
@@ -100,47 +99,49 @@ impl GenericParams { | |||
100 | let id = id.lookup(db).id; | 99 | let id = id.lookup(db).id; |
101 | let tree = id.item_tree(db); | 100 | let tree = id.item_tree(db); |
102 | let item = &tree[id.value]; | 101 | let item = &tree[id.value]; |
103 | tree[item.generic_params].clone() | 102 | item.generic_params.clone() |
104 | } | 103 | } |
105 | GenericDefId::AdtId(AdtId::StructId(id)) => { | 104 | GenericDefId::AdtId(AdtId::StructId(id)) => { |
106 | let id = id.lookup(db).id; | 105 | let id = id.lookup(db).id; |
107 | let tree = id.item_tree(db); | 106 | let tree = id.item_tree(db); |
108 | let item = &tree[id.value]; | 107 | let item = &tree[id.value]; |
109 | tree[item.generic_params].clone() | 108 | item.generic_params.clone() |
110 | } | 109 | } |
111 | GenericDefId::AdtId(AdtId::EnumId(id)) => { | 110 | GenericDefId::AdtId(AdtId::EnumId(id)) => { |
112 | let id = id.lookup(db).id; | 111 | let id = id.lookup(db).id; |
113 | let tree = id.item_tree(db); | 112 | let tree = id.item_tree(db); |
114 | let item = &tree[id.value]; | 113 | let item = &tree[id.value]; |
115 | tree[item.generic_params].clone() | 114 | item.generic_params.clone() |
116 | } | 115 | } |
117 | GenericDefId::AdtId(AdtId::UnionId(id)) => { | 116 | GenericDefId::AdtId(AdtId::UnionId(id)) => { |
118 | let id = id.lookup(db).id; | 117 | let id = id.lookup(db).id; |
119 | let tree = id.item_tree(db); | 118 | let tree = id.item_tree(db); |
120 | let item = &tree[id.value]; | 119 | let item = &tree[id.value]; |
121 | tree[item.generic_params].clone() | 120 | item.generic_params.clone() |
122 | } | 121 | } |
123 | GenericDefId::TraitId(id) => { | 122 | GenericDefId::TraitId(id) => { |
124 | let id = id.lookup(db).id; | 123 | let id = id.lookup(db).id; |
125 | let tree = id.item_tree(db); | 124 | let tree = id.item_tree(db); |
126 | let item = &tree[id.value]; | 125 | let item = &tree[id.value]; |
127 | tree[item.generic_params].clone() | 126 | item.generic_params.clone() |
128 | } | 127 | } |
129 | GenericDefId::TypeAliasId(id) => { | 128 | GenericDefId::TypeAliasId(id) => { |
130 | let id = id.lookup(db).id; | 129 | let id = id.lookup(db).id; |
131 | let tree = id.item_tree(db); | 130 | let tree = id.item_tree(db); |
132 | let item = &tree[id.value]; | 131 | let item = &tree[id.value]; |
133 | tree[item.generic_params].clone() | 132 | item.generic_params.clone() |
134 | } | 133 | } |
135 | GenericDefId::ImplId(id) => { | 134 | GenericDefId::ImplId(id) => { |
136 | let id = id.lookup(db).id; | 135 | let id = id.lookup(db).id; |
137 | let tree = id.item_tree(db); | 136 | let tree = id.item_tree(db); |
138 | let item = &tree[id.value]; | 137 | let item = &tree[id.value]; |
139 | tree[item.generic_params].clone() | 138 | item.generic_params.clone() |
139 | } | ||
140 | GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => { | ||
141 | Interned::new(GenericParams::default()) | ||
140 | } | 142 | } |
141 | GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => GenericParams::default(), | ||
142 | }; | 143 | }; |
143 | Arc::new(generics) | 144 | generics |
144 | } | 145 | } |
145 | 146 | ||
146 | fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { | 147 | fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { |
diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs index d163f633f..2467e9299 100644 --- a/crates/hir_def/src/intern.rs +++ b/crates/hir_def/src/intern.rs | |||
@@ -14,6 +14,8 @@ use dashmap::{lock::RwLockWriteGuard, DashMap, SharedValue}; | |||
14 | use once_cell::sync::OnceCell; | 14 | use once_cell::sync::OnceCell; |
15 | use rustc_hash::FxHasher; | 15 | use rustc_hash::FxHasher; |
16 | 16 | ||
17 | use crate::generics::GenericParams; | ||
18 | |||
17 | type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>; | 19 | type InternMap<T> = DashMap<Arc<T>, (), BuildHasherDefault<FxHasher>>; |
18 | type Guard<T> = | 20 | type Guard<T> = |
19 | RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>; | 21 | RwLockWriteGuard<'static, HashMap<Arc<T>, SharedValue<()>, BuildHasherDefault<FxHasher>>>; |
@@ -194,4 +196,10 @@ macro_rules! impl_internable { | |||
194 | )+ }; | 196 | )+ }; |
195 | } | 197 | } |
196 | 198 | ||
197 | impl_internable!(crate::type_ref::TypeRef, crate::type_ref::TraitRef, crate::path::ModPath, str); | 199 | impl_internable!( |
200 | crate::type_ref::TypeRef, | ||
201 | crate::type_ref::TraitRef, | ||
202 | crate::path::ModPath, | ||
203 | GenericParams, | ||
204 | str | ||
205 | ); | ||
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 739906778..240662486 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -58,13 +58,6 @@ impl fmt::Debug for RawVisibilityId { | |||
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
62 | pub struct GenericParamsId(u32); | ||
63 | |||
64 | impl GenericParamsId { | ||
65 | pub const EMPTY: Self = GenericParamsId(u32::max_value()); | ||
66 | } | ||
67 | |||
68 | /// The item tree of a source file. | 61 | /// The item tree of a source file. |
69 | #[derive(Debug, Default, Eq, PartialEq)] | 62 | #[derive(Debug, Default, Eq, PartialEq)] |
70 | pub struct ItemTree { | 63 | pub struct ItemTree { |
@@ -146,7 +139,6 @@ impl ItemTree { | |||
146 | macro_rules, | 139 | macro_rules, |
147 | macro_defs, | 140 | macro_defs, |
148 | vis, | 141 | vis, |
149 | generics, | ||
150 | inner_items, | 142 | inner_items, |
151 | } = &mut **data; | 143 | } = &mut **data; |
152 | 144 | ||
@@ -170,7 +162,6 @@ impl ItemTree { | |||
170 | macro_defs.shrink_to_fit(); | 162 | macro_defs.shrink_to_fit(); |
171 | 163 | ||
172 | vis.arena.shrink_to_fit(); | 164 | vis.arena.shrink_to_fit(); |
173 | generics.arena.shrink_to_fit(); | ||
174 | 165 | ||
175 | inner_items.shrink_to_fit(); | 166 | inner_items.shrink_to_fit(); |
176 | } | 167 | } |
@@ -242,32 +233,6 @@ static VIS_PRIV: RawVisibility = RawVisibility::Module(ModPath::from_kind(PathKi | |||
242 | static VIS_PUB_CRATE: RawVisibility = RawVisibility::Module(ModPath::from_kind(PathKind::Crate)); | 233 | static VIS_PUB_CRATE: RawVisibility = RawVisibility::Module(ModPath::from_kind(PathKind::Crate)); |
243 | 234 | ||
244 | #[derive(Default, Debug, Eq, PartialEq)] | 235 | #[derive(Default, Debug, Eq, PartialEq)] |
245 | struct GenericParamsStorage { | ||
246 | arena: Arena<GenericParams>, | ||
247 | } | ||
248 | |||
249 | impl GenericParamsStorage { | ||
250 | fn alloc(&mut self, params: GenericParams) -> GenericParamsId { | ||
251 | if params.types.is_empty() | ||
252 | && params.lifetimes.is_empty() | ||
253 | && params.consts.is_empty() | ||
254 | && params.where_predicates.is_empty() | ||
255 | { | ||
256 | return GenericParamsId::EMPTY; | ||
257 | } | ||
258 | |||
259 | GenericParamsId(self.arena.alloc(params).into_raw().into()) | ||
260 | } | ||
261 | } | ||
262 | |||
263 | static EMPTY_GENERICS: GenericParams = GenericParams { | ||
264 | types: Arena::new(), | ||
265 | lifetimes: Arena::new(), | ||
266 | consts: Arena::new(), | ||
267 | where_predicates: Vec::new(), | ||
268 | }; | ||
269 | |||
270 | #[derive(Default, Debug, Eq, PartialEq)] | ||
271 | struct ItemTreeData { | 236 | struct ItemTreeData { |
272 | imports: Arena<Import>, | 237 | imports: Arena<Import>, |
273 | extern_crates: Arena<ExternCrate>, | 238 | extern_crates: Arena<ExternCrate>, |
@@ -289,7 +254,6 @@ struct ItemTreeData { | |||
289 | macro_defs: Arena<MacroDef>, | 254 | macro_defs: Arena<MacroDef>, |
290 | 255 | ||
291 | vis: ItemVisibilities, | 256 | vis: ItemVisibilities, |
292 | generics: GenericParamsStorage, | ||
293 | 257 | ||
294 | inner_items: FxHashMap<FileAstId<ast::BlockExpr>, SmallVec<[ModItem; 1]>>, | 258 | inner_items: FxHashMap<FileAstId<ast::BlockExpr>, SmallVec<[ModItem; 1]>>, |
295 | } | 259 | } |
@@ -508,17 +472,6 @@ impl Index<RawVisibilityId> for ItemTree { | |||
508 | } | 472 | } |
509 | } | 473 | } |
510 | 474 | ||
511 | impl Index<GenericParamsId> for ItemTree { | ||
512 | type Output = GenericParams; | ||
513 | |||
514 | fn index(&self, index: GenericParamsId) -> &Self::Output { | ||
515 | match index { | ||
516 | GenericParamsId::EMPTY => &EMPTY_GENERICS, | ||
517 | _ => &self.data().generics.arena[Idx::from_raw(index.0.into())], | ||
518 | } | ||
519 | } | ||
520 | } | ||
521 | |||
522 | impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree { | 475 | impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree { |
523 | type Output = N; | 476 | type Output = N; |
524 | fn index(&self, id: FileItemTreeId<N>) -> &N { | 477 | fn index(&self, id: FileItemTreeId<N>) -> &N { |
@@ -555,7 +508,7 @@ pub struct ExternCrate { | |||
555 | pub struct Function { | 508 | pub struct Function { |
556 | pub name: Name, | 509 | pub name: Name, |
557 | pub visibility: RawVisibilityId, | 510 | pub visibility: RawVisibilityId, |
558 | pub generic_params: GenericParamsId, | 511 | pub generic_params: Interned<GenericParams>, |
559 | pub abi: Option<Interned<str>>, | 512 | pub abi: Option<Interned<str>>, |
560 | pub params: IdRange<Param>, | 513 | pub params: IdRange<Param>, |
561 | pub ret_type: Interned<TypeRef>, | 514 | pub ret_type: Interned<TypeRef>, |
@@ -590,7 +543,7 @@ impl FnFlags { | |||
590 | pub struct Struct { | 543 | pub struct Struct { |
591 | pub name: Name, | 544 | pub name: Name, |
592 | pub visibility: RawVisibilityId, | 545 | pub visibility: RawVisibilityId, |
593 | pub generic_params: GenericParamsId, | 546 | pub generic_params: Interned<GenericParams>, |
594 | pub fields: Fields, | 547 | pub fields: Fields, |
595 | pub ast_id: FileAstId<ast::Struct>, | 548 | pub ast_id: FileAstId<ast::Struct>, |
596 | pub kind: StructDefKind, | 549 | pub kind: StructDefKind, |
@@ -610,7 +563,7 @@ pub enum StructDefKind { | |||
610 | pub struct Union { | 563 | pub struct Union { |
611 | pub name: Name, | 564 | pub name: Name, |
612 | pub visibility: RawVisibilityId, | 565 | pub visibility: RawVisibilityId, |
613 | pub generic_params: GenericParamsId, | 566 | pub generic_params: Interned<GenericParams>, |
614 | pub fields: Fields, | 567 | pub fields: Fields, |
615 | pub ast_id: FileAstId<ast::Union>, | 568 | pub ast_id: FileAstId<ast::Union>, |
616 | } | 569 | } |
@@ -619,7 +572,7 @@ pub struct Union { | |||
619 | pub struct Enum { | 572 | pub struct Enum { |
620 | pub name: Name, | 573 | pub name: Name, |
621 | pub visibility: RawVisibilityId, | 574 | pub visibility: RawVisibilityId, |
622 | pub generic_params: GenericParamsId, | 575 | pub generic_params: Interned<GenericParams>, |
623 | pub variants: IdRange<Variant>, | 576 | pub variants: IdRange<Variant>, |
624 | pub ast_id: FileAstId<ast::Enum>, | 577 | pub ast_id: FileAstId<ast::Enum>, |
625 | } | 578 | } |
@@ -648,7 +601,7 @@ pub struct Static { | |||
648 | pub struct Trait { | 601 | pub struct Trait { |
649 | pub name: Name, | 602 | pub name: Name, |
650 | pub visibility: RawVisibilityId, | 603 | pub visibility: RawVisibilityId, |
651 | pub generic_params: GenericParamsId, | 604 | pub generic_params: Interned<GenericParams>, |
652 | pub is_auto: bool, | 605 | pub is_auto: bool, |
653 | pub is_unsafe: bool, | 606 | pub is_unsafe: bool, |
654 | pub bounds: Box<[TypeBound]>, | 607 | pub bounds: Box<[TypeBound]>, |
@@ -658,7 +611,7 @@ pub struct Trait { | |||
658 | 611 | ||
659 | #[derive(Debug, Clone, Eq, PartialEq)] | 612 | #[derive(Debug, Clone, Eq, PartialEq)] |
660 | pub struct Impl { | 613 | pub struct Impl { |
661 | pub generic_params: GenericParamsId, | 614 | pub generic_params: Interned<GenericParams>, |
662 | pub target_trait: Option<Interned<TraitRef>>, | 615 | pub target_trait: Option<Interned<TraitRef>>, |
663 | pub self_ty: Interned<TypeRef>, | 616 | pub self_ty: Interned<TypeRef>, |
664 | pub is_negative: bool, | 617 | pub is_negative: bool, |
@@ -672,7 +625,7 @@ pub struct TypeAlias { | |||
672 | pub visibility: RawVisibilityId, | 625 | pub visibility: RawVisibilityId, |
673 | /// Bounds on the type alias itself. Only valid in trait declarations, eg. `type Assoc: Copy;`. | 626 | /// Bounds on the type alias itself. Only valid in trait declarations, eg. `type Assoc: Copy;`. |
674 | pub bounds: Box<[TypeBound]>, | 627 | pub bounds: Box<[TypeBound]>, |
675 | pub generic_params: GenericParamsId, | 628 | pub generic_params: Interned<GenericParams>, |
676 | pub type_ref: Option<Interned<TypeRef>>, | 629 | pub type_ref: Option<Interned<TypeRef>>, |
677 | pub is_extern: bool, | 630 | pub is_extern: bool, |
678 | pub ast_id: FileAstId<ast::TypeAlias>, | 631 | pub ast_id: FileAstId<ast::TypeAlias>, |
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 0c8112dda..c5629af24 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -434,7 +434,7 @@ impl Ctx { | |||
434 | let mut res = Function { | 434 | let mut res = Function { |
435 | name, | 435 | name, |
436 | visibility, | 436 | visibility, |
437 | generic_params: GenericParamsId::EMPTY, | 437 | generic_params: Interned::new(GenericParams::default()), |
438 | abi, | 438 | abi, |
439 | params, | 439 | params, |
440 | ret_type: Interned::new(ret_type), | 440 | ret_type: Interned::new(ret_type), |
@@ -682,7 +682,7 @@ impl Ctx { | |||
682 | &mut self, | 682 | &mut self, |
683 | owner: GenericsOwner<'_>, | 683 | owner: GenericsOwner<'_>, |
684 | node: &impl ast::GenericParamsOwner, | 684 | node: &impl ast::GenericParamsOwner, |
685 | ) -> GenericParamsId { | 685 | ) -> Interned<GenericParams> { |
686 | // Generics are part of item headers and may contain inner items we need to collect. | 686 | // Generics are part of item headers and may contain inner items we need to collect. |
687 | if let Some(params) = node.generic_param_list() { | 687 | if let Some(params) = node.generic_param_list() { |
688 | self.collect_inner_items(params.syntax()); | 688 | self.collect_inner_items(params.syntax()); |
@@ -698,7 +698,7 @@ impl Ctx { | |||
698 | &mut self, | 698 | &mut self, |
699 | owner: GenericsOwner<'_>, | 699 | owner: GenericsOwner<'_>, |
700 | node: &impl ast::GenericParamsOwner, | 700 | node: &impl ast::GenericParamsOwner, |
701 | ) -> GenericParamsId { | 701 | ) -> Interned<GenericParams> { |
702 | let mut sm = &mut Default::default(); | 702 | let mut sm = &mut Default::default(); |
703 | let mut generics = GenericParams::default(); | 703 | let mut generics = GenericParams::default(); |
704 | match owner { | 704 | match owner { |
@@ -740,7 +740,7 @@ impl Ctx { | |||
740 | } | 740 | } |
741 | 741 | ||
742 | generics.shrink_to_fit(); | 742 | generics.shrink_to_fit(); |
743 | self.data().generics.alloc(generics) | 743 | Interned::new(generics) |
744 | } | 744 | } |
745 | 745 | ||
746 | fn lower_type_bounds(&mut self, node: &impl ast::TypeBoundsOwner) -> Vec<TypeBound> { | 746 | fn lower_type_bounds(&mut self, node: &impl ast::TypeBoundsOwner) -> Vec<TypeBound> { |
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index f408e510a..be9a5e1a0 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs | |||
@@ -27,6 +27,7 @@ pub mod dyn_map; | |||
27 | pub mod keys; | 27 | pub mod keys; |
28 | 28 | ||
29 | pub mod item_tree; | 29 | pub mod item_tree; |
30 | pub mod intern; | ||
30 | 31 | ||
31 | pub mod adt; | 32 | pub mod adt; |
32 | pub mod data; | 33 | pub mod data; |
@@ -49,7 +50,6 @@ pub mod import_map; | |||
49 | 50 | ||
50 | #[cfg(test)] | 51 | #[cfg(test)] |
51 | mod test_db; | 52 | mod test_db; |
52 | mod intern; | ||
53 | 53 | ||
54 | use std::{ | 54 | use std::{ |
55 | hash::{Hash, Hasher}, | 55 | hash::{Hash, Hasher}, |
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index a73585ee7..0391cc49b 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs | |||
@@ -14,6 +14,7 @@ use crate::{ | |||
14 | db::DefDatabase, | 14 | db::DefDatabase, |
15 | expr::{ExprId, LabelId, PatId}, | 15 | expr::{ExprId, LabelId, PatId}, |
16 | generics::GenericParams, | 16 | generics::GenericParams, |
17 | intern::Interned, | ||
17 | item_scope::{BuiltinShadowMode, BUILTIN_SCOPE}, | 18 | item_scope::{BuiltinShadowMode, BUILTIN_SCOPE}, |
18 | nameres::DefMap, | 19 | nameres::DefMap, |
19 | path::{ModPath, PathKind}, | 20 | path::{ModPath, PathKind}, |
@@ -50,7 +51,7 @@ enum Scope { | |||
50 | /// All the items and imported names of a module | 51 | /// All the items and imported names of a module |
51 | ModuleScope(ModuleItemMap), | 52 | ModuleScope(ModuleItemMap), |
52 | /// Brings the generic parameters of an item into scope | 53 | /// Brings the generic parameters of an item into scope |
53 | GenericParams { def: GenericDefId, params: Arc<GenericParams> }, | 54 | GenericParams { def: GenericDefId, params: Interned<GenericParams> }, |
54 | /// Brings `Self` in `impl` block into scope | 55 | /// Brings `Self` in `impl` block into scope |
55 | ImplDefScope(ImplId), | 56 | ImplDefScope(ImplId), |
56 | /// Brings `Self` in enum, struct and union definitions into scope | 57 | /// Brings `Self` in enum, struct and union definitions into scope |
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs index c85c328af..df0ea4368 100644 --- a/crates/hir_ty/src/utils.rs +++ b/crates/hir_ty/src/utils.rs | |||
@@ -9,6 +9,7 @@ use hir_def::{ | |||
9 | generics::{ | 9 | generics::{ |
10 | GenericParams, TypeParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget, | 10 | GenericParams, TypeParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget, |
11 | }, | 11 | }, |
12 | intern::Interned, | ||
12 | path::Path, | 13 | path::Path, |
13 | resolver::{HasResolver, TypeNs}, | 14 | resolver::{HasResolver, TypeNs}, |
14 | type_ref::TypeRef, | 15 | type_ref::TypeRef, |
@@ -158,7 +159,7 @@ pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics { | |||
158 | #[derive(Debug)] | 159 | #[derive(Debug)] |
159 | pub(crate) struct Generics { | 160 | pub(crate) struct Generics { |
160 | def: GenericDefId, | 161 | def: GenericDefId, |
161 | pub(crate) params: Arc<GenericParams>, | 162 | pub(crate) params: Interned<GenericParams>, |
162 | parent_generics: Option<Box<Generics>>, | 163 | parent_generics: Option<Box<Generics>>, |
163 | } | 164 | } |
164 | 165 | ||