aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits/chalk/interner.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits/chalk/interner.rs')
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs23
1 files changed, 15 insertions, 8 deletions
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 @@
3 3
4use super::tls; 4use super::tls;
5use base_db::salsa::InternId; 5use base_db::salsa::InternId;
6use chalk_ir::{GenericArg, Goal, GoalData}; 6use chalk_ir::{Goal, GoalData};
7use hir_def::{ 7use hir_def::{
8 intern::{impl_internable, InternStorage, Internable, Interned}, 8 intern::{impl_internable, InternStorage, Internable, Interned},
9 TypeAliasId, 9 TypeAliasId,
10}; 10};
11use crate::GenericArg;
11use smallvec::SmallVec; 12use smallvec::SmallVec;
12use std::{fmt, sync::Arc}; 13use std::{fmt, sync::Arc};
13 14
@@ -32,7 +33,13 @@ pub(crate) type Variances = chalk_ir::Variances<Interner>;
32#[derive(PartialEq, Eq, Hash, Debug)] 33#[derive(PartialEq, Eq, Hash, Debug)]
33pub struct InternedVariableKindsInner(Vec<chalk_ir::VariableKind<Interner>>); 34pub struct InternedVariableKindsInner(Vec<chalk_ir::VariableKind<Interner>>);
34 35
35impl_internable!(InternedVariableKindsInner,); 36#[derive(PartialEq, Eq, Hash, Debug)]
37pub struct InternedSubstitutionInner(SmallVec<[GenericArg; 2]>);
38
39impl_internable!(
40 InternedVariableKindsInner,
41 InternedSubstitutionInner,
42);
36 43
37impl chalk_ir::interner::Interner for Interner { 44impl chalk_ir::interner::Interner for Interner {
38 type InternedType = Arc<chalk_ir::TyData<Self>>; 45 type InternedType = Arc<chalk_ir::TyData<Self>>;
@@ -42,7 +49,7 @@ impl chalk_ir::interner::Interner for Interner {
42 type InternedGenericArg = chalk_ir::GenericArgData<Self>; 49 type InternedGenericArg = chalk_ir::GenericArgData<Self>;
43 type InternedGoal = Arc<GoalData<Self>>; 50 type InternedGoal = Arc<GoalData<Self>>;
44 type InternedGoals = Vec<Goal<Self>>; 51 type InternedGoals = Vec<Goal<Self>>;
45 type InternedSubstitution = SmallVec<[GenericArg<Self>; 2]>; 52 type InternedSubstitution = Interned<InternedSubstitutionInner>;
46 type InternedProgramClause = Arc<chalk_ir::ProgramClauseData<Self>>; 53 type InternedProgramClause = Arc<chalk_ir::ProgramClauseData<Self>>;
47 type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>; 54 type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>;
48 type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>; 55 type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
@@ -107,7 +114,7 @@ impl chalk_ir::interner::Interner for Interner {
107 } 114 }
108 115
109 fn debug_generic_arg( 116 fn debug_generic_arg(
110 parameter: &GenericArg<Interner>, 117 parameter: &GenericArg,
111 fmt: &mut fmt::Formatter<'_>, 118 fmt: &mut fmt::Formatter<'_>,
112 ) -> Option<fmt::Result> { 119 ) -> Option<fmt::Result> {
113 tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) 120 tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt)))
@@ -272,16 +279,16 @@ impl chalk_ir::interner::Interner for Interner {
272 279
273 fn intern_substitution<E>( 280 fn intern_substitution<E>(
274 &self, 281 &self,
275 data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>, 282 data: impl IntoIterator<Item = Result<GenericArg, E>>,
276 ) -> Result<Self::InternedSubstitution, E> { 283 ) -> Result<Self::InternedSubstitution, E> {
277 data.into_iter().collect() 284 Ok(Interned::new(InternedSubstitutionInner(data.into_iter().collect::<Result<SmallVec<_>, _>>()?)))
278 } 285 }
279 286
280 fn substitution_data<'a>( 287 fn substitution_data<'a>(
281 &self, 288 &self,
282 substitution: &'a Self::InternedSubstitution, 289 substitution: &'a Self::InternedSubstitution,
283 ) -> &'a [GenericArg<Self>] { 290 ) -> &'a [GenericArg] {
284 substitution 291 &substitution.as_ref().0
285 } 292 }
286 293
287 fn intern_program_clause( 294 fn intern_program_clause(