diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-16 16:42:58 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-16 16:42:58 +0000 |
commit | adcc89137d3feea8f19fad461bbde6f4bce048e5 (patch) | |
tree | 160af959553ce57fdfcbc0a6c79bafcc3611aeea /crates/ra_hir_ty/src/lib.rs | |
parent | 648df02953a6ebf87a5876668eceba208687e8a7 (diff) | |
parent | 9faea2364dee4fbc9391ad233c570b70256ef002 (diff) |
Merge #3584
3584: Switch to dynamic dispatch r=matklad a=matklad
Benches are in https://github.com/rust-analyzer/rust-analyzer/issues/1987#issuecomment-598807185
TL;DR:
* 33% faster release build
* slightly worse/same perf
* no changes for debug build
* slightly smaller binary
cc @flodiebold I genuinely don't know if it is a good idea or not.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/lib.rs')
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 4127f1a8d..6c5469ecd 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -152,7 +152,7 @@ pub struct TypeCtorId(salsa::InternId); | |||
152 | impl_intern_key!(TypeCtorId); | 152 | impl_intern_key!(TypeCtorId); |
153 | 153 | ||
154 | impl TypeCtor { | 154 | impl TypeCtor { |
155 | pub fn num_ty_params(self, db: &impl HirDatabase) -> usize { | 155 | pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize { |
156 | match self { | 156 | match self { |
157 | TypeCtor::Bool | 157 | TypeCtor::Bool |
158 | | TypeCtor::Char | 158 | | TypeCtor::Char |
@@ -167,15 +167,15 @@ impl TypeCtor { | |||
167 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure | 167 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure |
168 | => 1, | 168 | => 1, |
169 | TypeCtor::Adt(adt) => { | 169 | TypeCtor::Adt(adt) => { |
170 | let generic_params = generics(db, adt.into()); | 170 | let generic_params = generics(db.upcast(), adt.into()); |
171 | generic_params.len() | 171 | generic_params.len() |
172 | } | 172 | } |
173 | TypeCtor::FnDef(callable) => { | 173 | TypeCtor::FnDef(callable) => { |
174 | let generic_params = generics(db, callable.into()); | 174 | let generic_params = generics(db.upcast(), callable.into()); |
175 | generic_params.len() | 175 | generic_params.len() |
176 | } | 176 | } |
177 | TypeCtor::AssociatedType(type_alias) => { | 177 | TypeCtor::AssociatedType(type_alias) => { |
178 | let generic_params = generics(db, type_alias.into()); | 178 | let generic_params = generics(db.upcast(), type_alias.into()); |
179 | generic_params.len() | 179 | generic_params.len() |
180 | } | 180 | } |
181 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, | 181 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, |
@@ -183,7 +183,7 @@ impl TypeCtor { | |||
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | pub fn krate(self, db: &impl HirDatabase) -> Option<CrateId> { | 186 | pub fn krate(self, db: &dyn HirDatabase) -> Option<CrateId> { |
187 | match self { | 187 | match self { |
188 | TypeCtor::Bool | 188 | TypeCtor::Bool |
189 | | TypeCtor::Char | 189 | | TypeCtor::Char |
@@ -199,9 +199,11 @@ impl TypeCtor { | |||
199 | | TypeCtor::Tuple { .. } => None, | 199 | | TypeCtor::Tuple { .. } => None, |
200 | // Closure's krate is irrelevant for coherence I would think? | 200 | // Closure's krate is irrelevant for coherence I would think? |
201 | TypeCtor::Closure { .. } => None, | 201 | TypeCtor::Closure { .. } => None, |
202 | TypeCtor::Adt(adt) => Some(adt.module(db).krate), | 202 | TypeCtor::Adt(adt) => Some(adt.module(db.upcast()).krate), |
203 | TypeCtor::FnDef(callable) => Some(callable.krate(db)), | 203 | TypeCtor::FnDef(callable) => Some(callable.krate(db)), |
204 | TypeCtor::AssociatedType(type_alias) => Some(type_alias.lookup(db).module(db).krate), | 204 | TypeCtor::AssociatedType(type_alias) => { |
205 | Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate) | ||
206 | } | ||
205 | } | 207 | } |
206 | } | 208 | } |
207 | 209 | ||
@@ -246,12 +248,12 @@ pub struct ProjectionTy { | |||
246 | } | 248 | } |
247 | 249 | ||
248 | impl ProjectionTy { | 250 | impl ProjectionTy { |
249 | pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { | 251 | pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { |
250 | TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } | 252 | TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } |
251 | } | 253 | } |
252 | 254 | ||
253 | fn trait_(&self, db: &impl HirDatabase) -> TraitId { | 255 | fn trait_(&self, db: &dyn HirDatabase) -> TraitId { |
254 | match self.associated_ty.lookup(db).container { | 256 | match self.associated_ty.lookup(db.upcast()).container { |
255 | AssocContainerId::TraitId(it) => it, | 257 | AssocContainerId::TraitId(it) => it, |
256 | _ => panic!("projection ty without parent trait"), | 258 | _ => panic!("projection ty without parent trait"), |
257 | } | 259 | } |
@@ -372,8 +374,8 @@ impl Substs { | |||
372 | } | 374 | } |
373 | 375 | ||
374 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). | 376 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). |
375 | pub fn type_params(db: &impl HirDatabase, def: impl Into<GenericDefId>) -> Substs { | 377 | pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substs { |
376 | let params = generics(db, def.into()); | 378 | let params = generics(db.upcast(), def.into()); |
377 | Substs::type_params_for_generics(¶ms) | 379 | Substs::type_params_for_generics(¶ms) |
378 | } | 380 | } |
379 | 381 | ||
@@ -382,9 +384,9 @@ impl Substs { | |||
382 | Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect()) | 384 | Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect()) |
383 | } | 385 | } |
384 | 386 | ||
385 | pub fn build_for_def(db: &impl HirDatabase, def: impl Into<GenericDefId>) -> SubstsBuilder { | 387 | pub fn build_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> SubstsBuilder { |
386 | let def = def.into(); | 388 | let def = def.into(); |
387 | let params = generics(db, def); | 389 | let params = generics(db.upcast(), def); |
388 | let param_count = params.len(); | 390 | let param_count = params.len(); |
389 | Substs::builder(param_count) | 391 | Substs::builder(param_count) |
390 | } | 392 | } |
@@ -393,7 +395,7 @@ impl Substs { | |||
393 | Substs::builder(generic_params.len()) | 395 | Substs::builder(generic_params.len()) |
394 | } | 396 | } |
395 | 397 | ||
396 | pub fn build_for_type_ctor(db: &impl HirDatabase, type_ctor: TypeCtor) -> SubstsBuilder { | 398 | pub fn build_for_type_ctor(db: &dyn HirDatabase, type_ctor: TypeCtor) -> SubstsBuilder { |
397 | Substs::builder(type_ctor.num_ty_params(db)) | 399 | Substs::builder(type_ctor.num_ty_params(db)) |
398 | } | 400 | } |
399 | 401 | ||
@@ -538,7 +540,7 @@ impl GenericPredicate { | |||
538 | } | 540 | } |
539 | } | 541 | } |
540 | 542 | ||
541 | pub fn trait_ref(&self, db: &impl HirDatabase) -> Option<TraitRef> { | 543 | pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> { |
542 | match self { | 544 | match self { |
543 | GenericPredicate::Implemented(tr) => Some(tr.clone()), | 545 | GenericPredicate::Implemented(tr) => Some(tr.clone()), |
544 | GenericPredicate::Projection(proj) => Some(proj.projection_ty.trait_ref(db)), | 546 | GenericPredicate::Projection(proj) => Some(proj.projection_ty.trait_ref(db)), |
@@ -693,7 +695,7 @@ impl Ty { | |||
693 | } | 695 | } |
694 | } | 696 | } |
695 | 697 | ||
696 | fn callable_sig(&self, db: &impl HirDatabase) -> Option<FnSig> { | 698 | fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> { |
697 | match self { | 699 | match self { |
698 | Ty::Apply(a_ty) => match a_ty.ctor { | 700 | Ty::Apply(a_ty) => match a_ty.ctor { |
699 | TypeCtor::FnPtr { .. } => Some(FnSig::from_fn_ptr_substs(&a_ty.parameters)), | 701 | TypeCtor::FnPtr { .. } => Some(FnSig::from_fn_ptr_substs(&a_ty.parameters)), |