diff options
author | Jonas Schievink <[email protected]> | 2021-04-01 18:46:43 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-04-01 18:46:43 +0100 |
commit | b00266b79f0e2c2a5e332b30f7e6aba83b5e6e5a (patch) | |
tree | c7e591ec8a1ec6b401a8a7ea00115120a4789db5 /crates/hir_def/src/data.rs | |
parent | 25201b2dad7b4b0d41494e238ebf643ad7ad8cd6 (diff) |
Global TypeRef/TraitRef interning
Diffstat (limited to 'crates/hir_def/src/data.rs')
-rw-r--r-- | crates/hir_def/src/data.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index 214bcc648..31f994681 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs | |||
@@ -9,6 +9,7 @@ use crate::{ | |||
9 | attr::Attrs, | 9 | attr::Attrs, |
10 | body::Expander, | 10 | body::Expander, |
11 | db::DefDatabase, | 11 | db::DefDatabase, |
12 | intern::Interned, | ||
12 | item_tree::{AssocItem, FunctionQualifier, ItemTreeId, ModItem, Param}, | 13 | item_tree::{AssocItem, FunctionQualifier, ItemTreeId, ModItem, Param}, |
13 | type_ref::{TraitRef, TypeBound, TypeRef}, | 14 | type_ref::{TraitRef, TypeBound, TypeRef}, |
14 | visibility::RawVisibility, | 15 | visibility::RawVisibility, |
@@ -19,8 +20,8 @@ use crate::{ | |||
19 | #[derive(Debug, Clone, PartialEq, Eq)] | 20 | #[derive(Debug, Clone, PartialEq, Eq)] |
20 | pub struct FunctionData { | 21 | pub struct FunctionData { |
21 | pub name: Name, | 22 | pub name: Name, |
22 | pub params: Vec<TypeRef>, | 23 | pub params: Vec<Interned<TypeRef>>, |
23 | pub ret_type: TypeRef, | 24 | pub ret_type: Interned<TypeRef>, |
24 | pub attrs: Attrs, | 25 | pub attrs: Attrs, |
25 | /// True if the first param is `self`. This is relevant to decide whether this | 26 | /// True if the first param is `self`. This is relevant to decide whether this |
26 | /// can be called as a method. | 27 | /// can be called as a method. |
@@ -57,11 +58,11 @@ impl FunctionData { | |||
57 | params: enabled_params | 58 | params: enabled_params |
58 | .clone() | 59 | .clone() |
59 | .filter_map(|id| match &item_tree[id] { | 60 | .filter_map(|id| match &item_tree[id] { |
60 | Param::Normal(ty) => Some(item_tree[*ty].clone()), | 61 | Param::Normal(ty) => Some(ty.clone()), |
61 | Param::Varargs => None, | 62 | Param::Varargs => None, |
62 | }) | 63 | }) |
63 | .collect(), | 64 | .collect(), |
64 | ret_type: item_tree[func.ret_type].clone(), | 65 | ret_type: func.ret_type.clone(), |
65 | attrs: item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()), | 66 | attrs: item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()), |
66 | has_self_param: func.has_self_param, | 67 | has_self_param: func.has_self_param, |
67 | has_body: func.has_body, | 68 | has_body: func.has_body, |
@@ -76,7 +77,7 @@ impl FunctionData { | |||
76 | #[derive(Debug, Clone, PartialEq, Eq)] | 77 | #[derive(Debug, Clone, PartialEq, Eq)] |
77 | pub struct TypeAliasData { | 78 | pub struct TypeAliasData { |
78 | pub name: Name, | 79 | pub name: Name, |
79 | pub type_ref: Option<TypeRef>, | 80 | pub type_ref: Option<Interned<TypeRef>>, |
80 | pub visibility: RawVisibility, | 81 | pub visibility: RawVisibility, |
81 | pub is_extern: bool, | 82 | pub is_extern: bool, |
82 | /// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl). | 83 | /// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl). |
@@ -94,7 +95,7 @@ impl TypeAliasData { | |||
94 | 95 | ||
95 | Arc::new(TypeAliasData { | 96 | Arc::new(TypeAliasData { |
96 | name: typ.name.clone(), | 97 | name: typ.name.clone(), |
97 | type_ref: typ.type_ref.map(|id| item_tree[id].clone()), | 98 | type_ref: typ.type_ref.clone(), |
98 | visibility: item_tree[typ.visibility].clone(), | 99 | visibility: item_tree[typ.visibility].clone(), |
99 | is_extern: typ.is_extern, | 100 | is_extern: typ.is_extern, |
100 | bounds: typ.bounds.to_vec(), | 101 | bounds: typ.bounds.to_vec(), |
@@ -156,8 +157,8 @@ impl TraitData { | |||
156 | 157 | ||
157 | #[derive(Debug, Clone, PartialEq, Eq)] | 158 | #[derive(Debug, Clone, PartialEq, Eq)] |
158 | pub struct ImplData { | 159 | pub struct ImplData { |
159 | pub target_trait: Option<TraitRef>, | 160 | pub target_trait: Option<Interned<TraitRef>>, |
160 | pub self_ty: TypeRef, | 161 | pub self_ty: Interned<TypeRef>, |
161 | pub items: Vec<AssocItemId>, | 162 | pub items: Vec<AssocItemId>, |
162 | pub is_negative: bool, | 163 | pub is_negative: bool, |
163 | } | 164 | } |
@@ -169,8 +170,8 @@ impl ImplData { | |||
169 | 170 | ||
170 | let item_tree = impl_loc.id.item_tree(db); | 171 | let item_tree = impl_loc.id.item_tree(db); |
171 | let impl_def = &item_tree[impl_loc.id.value]; | 172 | let impl_def = &item_tree[impl_loc.id.value]; |
172 | let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone()); | 173 | let target_trait = impl_def.target_trait.clone(); |
173 | let self_ty = item_tree[impl_def.self_ty].clone(); | 174 | let self_ty = impl_def.self_ty.clone(); |
174 | let is_negative = impl_def.is_negative; | 175 | let is_negative = impl_def.is_negative; |
175 | let module_id = impl_loc.container; | 176 | let module_id = impl_loc.container; |
176 | let container = AssocContainerId::ImplId(id); | 177 | let container = AssocContainerId::ImplId(id); |
@@ -195,7 +196,7 @@ impl ImplData { | |||
195 | pub struct ConstData { | 196 | pub struct ConstData { |
196 | /// const _: () = (); | 197 | /// const _: () = (); |
197 | pub name: Option<Name>, | 198 | pub name: Option<Name>, |
198 | pub type_ref: TypeRef, | 199 | pub type_ref: Interned<TypeRef>, |
199 | pub visibility: RawVisibility, | 200 | pub visibility: RawVisibility, |
200 | } | 201 | } |
201 | 202 | ||
@@ -207,7 +208,7 @@ impl ConstData { | |||
207 | 208 | ||
208 | Arc::new(ConstData { | 209 | Arc::new(ConstData { |
209 | name: konst.name.clone(), | 210 | name: konst.name.clone(), |
210 | type_ref: item_tree[konst.type_ref].clone(), | 211 | type_ref: konst.type_ref.clone(), |
211 | visibility: item_tree[konst.visibility].clone(), | 212 | visibility: item_tree[konst.visibility].clone(), |
212 | }) | 213 | }) |
213 | } | 214 | } |
@@ -216,7 +217,7 @@ impl ConstData { | |||
216 | #[derive(Debug, Clone, PartialEq, Eq)] | 217 | #[derive(Debug, Clone, PartialEq, Eq)] |
217 | pub struct StaticData { | 218 | pub struct StaticData { |
218 | pub name: Option<Name>, | 219 | pub name: Option<Name>, |
219 | pub type_ref: TypeRef, | 220 | pub type_ref: Interned<TypeRef>, |
220 | pub visibility: RawVisibility, | 221 | pub visibility: RawVisibility, |
221 | pub mutable: bool, | 222 | pub mutable: bool, |
222 | pub is_extern: bool, | 223 | pub is_extern: bool, |
@@ -230,7 +231,7 @@ impl StaticData { | |||
230 | 231 | ||
231 | Arc::new(StaticData { | 232 | Arc::new(StaticData { |
232 | name: Some(statik.name.clone()), | 233 | name: Some(statik.name.clone()), |
233 | type_ref: item_tree[statik.type_ref].clone(), | 234 | type_ref: statik.type_ref.clone(), |
234 | visibility: item_tree[statik.visibility].clone(), | 235 | visibility: item_tree[statik.visibility].clone(), |
235 | mutable: statik.mutable, | 236 | mutable: statik.mutable, |
236 | is_extern: statik.is_extern, | 237 | is_extern: statik.is_extern, |