From be03db0e3a75533f34d48c3014d532919b30a9e9 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 8 Apr 2021 18:25:18 +0200 Subject: Intern Substitutions (Costs a bit of performance, reduces memory usage on RA by ~10%.) --- crates/hir_ty/src/infer/expr.rs | 2 +- crates/hir_ty/src/infer/pat.rs | 4 ++-- crates/hir_ty/src/infer/path.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/hir_ty/src/infer') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index cbbfa8b5c..ee6763926 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -462,7 +462,7 @@ impl<'a> InferenceContext<'a> { }; match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) { TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| { - substs.interned().get(idx).map(|a| a.assert_ty_ref(&Interner)).cloned() + substs.as_slice(&Interner).get(idx).map(|a| a.assert_ty_ref(&Interner)).cloned() }), TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => { let local_id = self.db.struct_data(*s).variant_data.field(name)?; diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index a41e8e116..aea354cde 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -122,7 +122,7 @@ impl<'a> InferenceContext<'a> { let ty = match &body[pat] { &Pat::Tuple { ref args, ellipsis } => { let expectations = match expected.as_tuple() { - Some(parameters) => &*parameters.interned().as_slice(), + Some(parameters) => &*parameters.as_slice(&Interner), _ => &[], }; @@ -242,7 +242,7 @@ impl<'a> InferenceContext<'a> { let (inner_ty, alloc_ty) = match expected.as_adt() { Some((adt, subst)) if adt == box_adt => ( subst.at(&Interner, 0).assert_ty_ref(&Interner).clone(), - subst.interned().get(1).and_then(|a| a.ty(&Interner).cloned()), + subst.as_slice(&Interner).get(1).and_then(|a| a.ty(&Interner).cloned()), ), _ => (self.result.standard_types.unknown.clone(), None), }; diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index f8955aa32..495282eba 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs @@ -101,7 +101,7 @@ impl<'a> InferenceContext<'a> { let substs = ctx.substs_from_path(path, typable, true); let ty = TyBuilder::value_ty(self.db, typable) .use_parent_substs(&parent_substs) - .fill(substs.interned()[parent_substs.len(&Interner)..].iter().cloned()) + .fill(substs.as_slice(&Interner)[parent_substs.len(&Interner)..].iter().cloned()) .build(); Some(ty) } -- cgit v1.2.3 From 37ff15ad835ee4ba6d231cac8b1adbd301aec20b Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 8 Apr 2021 21:15:01 +0200 Subject: Cleanup --- crates/hir_ty/src/infer/expr.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/hir_ty/src/infer') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index ee6763926..7961f4a52 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -462,7 +462,11 @@ impl<'a> InferenceContext<'a> { }; match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) { TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| { - substs.as_slice(&Interner).get(idx).map(|a| a.assert_ty_ref(&Interner)).cloned() + substs + .as_slice(&Interner) + .get(idx) + .map(|a| a.assert_ty_ref(&Interner)) + .cloned() }), TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => { let local_id = self.db.struct_data(*s).variant_data.field(name)?; -- cgit v1.2.3