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/traits/chalk/interner.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'crates/hir_ty/src/traits/chalk/interner.rs') diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index 7a3bd41d4..17e056f03 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs @@ -3,11 +3,12 @@ use super::tls; use base_db::salsa::InternId; -use chalk_ir::{GenericArg, Goal, GoalData}; +use chalk_ir::{Goal, GoalData}; use hir_def::{ intern::{impl_internable, InternStorage, Internable, Interned}, TypeAliasId, }; +use crate::GenericArg; use smallvec::SmallVec; use std::{fmt, sync::Arc}; @@ -32,7 +33,13 @@ pub(crate) type Variances = chalk_ir::Variances; #[derive(PartialEq, Eq, Hash, Debug)] pub struct InternedVariableKindsInner(Vec>); -impl_internable!(InternedVariableKindsInner,); +#[derive(PartialEq, Eq, Hash, Debug)] +pub struct InternedSubstitutionInner(SmallVec<[GenericArg; 2]>); + +impl_internable!( + InternedVariableKindsInner, + InternedSubstitutionInner, +); impl chalk_ir::interner::Interner for Interner { type InternedType = Arc>; @@ -42,7 +49,7 @@ impl chalk_ir::interner::Interner for Interner { type InternedGenericArg = chalk_ir::GenericArgData; type InternedGoal = Arc>; type InternedGoals = Vec>; - type InternedSubstitution = SmallVec<[GenericArg; 2]>; + type InternedSubstitution = Interned; type InternedProgramClause = Arc>; type InternedProgramClauses = Arc<[chalk_ir::ProgramClause]>; type InternedQuantifiedWhereClauses = Vec>; @@ -107,7 +114,7 @@ impl chalk_ir::interner::Interner for Interner { } fn debug_generic_arg( - parameter: &GenericArg, + parameter: &GenericArg, fmt: &mut fmt::Formatter<'_>, ) -> Option { tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) @@ -272,16 +279,16 @@ impl chalk_ir::interner::Interner for Interner { fn intern_substitution( &self, - data: impl IntoIterator, E>>, + data: impl IntoIterator>, ) -> Result { - data.into_iter().collect() + Ok(Interned::new(InternedSubstitutionInner(data.into_iter().collect::, _>>()?))) } fn substitution_data<'a>( &self, substitution: &'a Self::InternedSubstitution, - ) -> &'a [GenericArg] { - substitution + ) -> &'a [GenericArg] { + &substitution.as_ref().0 } fn intern_program_clause( -- cgit v1.2.3