aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/infer/expr.rs6
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs37
2 files changed, 19 insertions, 24 deletions
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> {
462 }; 462 };
463 match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) { 463 match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) {
464 TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| { 464 TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| {
465 substs.as_slice(&Interner).get(idx).map(|a| a.assert_ty_ref(&Interner)).cloned() 465 substs
466 .as_slice(&Interner)
467 .get(idx)
468 .map(|a| a.assert_ty_ref(&Interner))
469 .cloned()
466 }), 470 }),
467 TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => { 471 TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => {
468 let local_id = self.db.struct_data(*s).variant_data.field(name)?; 472 let local_id = self.db.struct_data(*s).variant_data.field(name)?;
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index f2c9a0d4b..b6a3cec6d 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -2,13 +2,13 @@
2//! representation of the various objects Chalk deals with (types, goals etc.). 2//! representation of the various objects Chalk deals with (types, goals etc.).
3 3
4use super::tls; 4use super::tls;
5use crate::GenericArg;
5use base_db::salsa::InternId; 6use base_db::salsa::InternId;
6use chalk_ir::{Goal, GoalData}; 7use chalk_ir::{Goal, GoalData};
7use hir_def::{ 8use hir_def::{
8 intern::{impl_internable, InternStorage, Internable, Interned}, 9 intern::{impl_internable, InternStorage, Internable, Interned},
9 TypeAliasId, 10 TypeAliasId,
10}; 11};
11use crate::GenericArg;
12use smallvec::SmallVec; 12use smallvec::SmallVec;
13use std::{fmt, sync::Arc}; 13use std::{fmt, sync::Arc};
14 14
@@ -31,15 +31,6 @@ pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>;
31pub(crate) type Variances = chalk_ir::Variances<Interner>; 31pub(crate) type Variances = chalk_ir::Variances<Interner>;
32 32
33#[derive(PartialEq, Eq, Hash, Debug)] 33#[derive(PartialEq, Eq, Hash, Debug)]
34pub struct InternedVariableKindsInner(Vec<chalk_ir::VariableKind<Interner>>);
35
36#[derive(PartialEq, Eq, Hash, Debug)]
37pub struct InternedSubstitutionInner(SmallVec<[GenericArg; 2]>);
38
39#[derive(PartialEq, Eq, Hash, Debug)]
40pub struct InternedTypeInner(chalk_ir::TyData<Interner>);
41
42#[derive(PartialEq, Eq, Hash, Debug)]
43pub struct InternedWrapper<T>(T); 34pub struct InternedWrapper<T>(T);
44 35
45impl<T> std::ops::Deref for InternedWrapper<T> { 36impl<T> std::ops::Deref for InternedWrapper<T> {
@@ -51,9 +42,9 @@ impl<T> std::ops::Deref for InternedWrapper<T> {
51} 42}
52 43
53impl_internable!( 44impl_internable!(
54 InternedVariableKindsInner, 45 InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>,
55 InternedSubstitutionInner, 46 InternedWrapper<SmallVec<[GenericArg; 2]>>,
56 InternedTypeInner, 47 InternedWrapper<chalk_ir::TyData<Interner>>,
57 InternedWrapper<chalk_ir::LifetimeData<Interner>>, 48 InternedWrapper<chalk_ir::LifetimeData<Interner>>,
58 InternedWrapper<chalk_ir::ConstData<Interner>>, 49 InternedWrapper<chalk_ir::ConstData<Interner>>,
59 InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Interner>>>, 50 InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Interner>>>,
@@ -63,19 +54,21 @@ impl_internable!(
63); 54);
64 55
65impl chalk_ir::interner::Interner for Interner { 56impl chalk_ir::interner::Interner for Interner {
66 type InternedType = Interned<InternedTypeInner>; 57 type InternedType = Interned<InternedWrapper<chalk_ir::TyData<Interner>>>;
67 type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>; 58 type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>;
68 type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>; 59 type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>;
69 type InternedConcreteConst = (); 60 type InternedConcreteConst = ();
70 type InternedGenericArg = chalk_ir::GenericArgData<Self>; 61 type InternedGenericArg = chalk_ir::GenericArgData<Self>;
71 type InternedGoal = Arc<GoalData<Self>>; 62 type InternedGoal = Arc<GoalData<Self>>;
72 type InternedGoals = Vec<Goal<Self>>; 63 type InternedGoals = Vec<Goal<Self>>;
73 type InternedSubstitution = Interned<InternedSubstitutionInner>; 64 type InternedSubstitution = Interned<InternedWrapper<SmallVec<[GenericArg; 2]>>>;
74 type InternedProgramClause = chalk_ir::ProgramClauseData<Self>; 65 type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
75 type InternedProgramClauses = Interned<InternedWrapper<Vec<chalk_ir::ProgramClause<Self>>>>; 66 type InternedProgramClauses = Interned<InternedWrapper<Vec<chalk_ir::ProgramClause<Self>>>>;
76 type InternedQuantifiedWhereClauses = Interned<InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Self>>>>; 67 type InternedQuantifiedWhereClauses =
77 type InternedVariableKinds = Interned<InternedVariableKindsInner>; 68 Interned<InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Self>>>>;
78 type InternedCanonicalVarKinds = Interned<InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Self>>>>; 69 type InternedVariableKinds = Interned<InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>>;
70 type InternedCanonicalVarKinds =
71 Interned<InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Self>>>>;
79 type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>; 72 type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
80 type InternedVariances = Interned<InternedWrapper<Vec<chalk_ir::Variance>>>; 73 type InternedVariances = Interned<InternedWrapper<Vec<chalk_ir::Variance>>>;
81 type DefId = InternId; 74 type DefId = InternId;
@@ -230,7 +223,7 @@ impl chalk_ir::interner::Interner for Interner {
230 223
231 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType { 224 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
232 let flags = kind.compute_flags(self); 225 let flags = kind.compute_flags(self);
233 Interned::new(InternedTypeInner(chalk_ir::TyData { kind, flags })) 226 Interned::new(InternedWrapper(chalk_ir::TyData { kind, flags }))
234 } 227 }
235 228
236 fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> { 229 fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> {
@@ -302,7 +295,7 @@ impl chalk_ir::interner::Interner for Interner {
302 &self, 295 &self,
303 data: impl IntoIterator<Item = Result<GenericArg, E>>, 296 data: impl IntoIterator<Item = Result<GenericArg, E>>,
304 ) -> Result<Self::InternedSubstitution, E> { 297 ) -> Result<Self::InternedSubstitution, E> {
305 Ok(Interned::new(InternedSubstitutionInner(data.into_iter().collect::<Result<SmallVec<_>, _>>()?))) 298 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
306 } 299 }
307 300
308 fn substitution_data<'a>( 301 fn substitution_data<'a>(
@@ -358,9 +351,7 @@ impl chalk_ir::interner::Interner for Interner {
358 &self, 351 &self,
359 data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>, 352 data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
360 ) -> Result<Self::InternedVariableKinds, E> { 353 ) -> Result<Self::InternedVariableKinds, E> {
361 Ok(Interned::new(InternedVariableKindsInner( 354 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
362 data.into_iter().collect::<Result<Vec<_>, E>>()?,
363 )))
364 } 355 }
365 356
366 fn variable_kinds_data<'a>( 357 fn variable_kinds_data<'a>(