diff options
author | Florian Diebold <[email protected]> | 2021-04-08 20:15:01 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-08 21:49:10 +0100 |
commit | 37ff15ad835ee4ba6d231cac8b1adbd301aec20b (patch) | |
tree | d33b6ca6fc37c3eaf19980926fa2dd0d59e66b43 /crates/hir_ty/src/traits/chalk | |
parent | 417473aa3d53fb1a094031251af37ecd71e0cc09 (diff) |
Cleanup
Diffstat (limited to 'crates/hir_ty/src/traits/chalk')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/interner.rs | 37 |
1 files changed, 14 insertions, 23 deletions
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 | ||
4 | use super::tls; | 4 | use super::tls; |
5 | use crate::GenericArg; | ||
5 | use base_db::salsa::InternId; | 6 | use base_db::salsa::InternId; |
6 | use chalk_ir::{Goal, GoalData}; | 7 | use chalk_ir::{Goal, GoalData}; |
7 | use hir_def::{ | 8 | use hir_def::{ |
8 | intern::{impl_internable, InternStorage, Internable, Interned}, | 9 | intern::{impl_internable, InternStorage, Internable, Interned}, |
9 | TypeAliasId, | 10 | TypeAliasId, |
10 | }; | 11 | }; |
11 | use crate::GenericArg; | ||
12 | use smallvec::SmallVec; | 12 | use smallvec::SmallVec; |
13 | use std::{fmt, sync::Arc}; | 13 | use std::{fmt, sync::Arc}; |
14 | 14 | ||
@@ -31,15 +31,6 @@ pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; | |||
31 | pub(crate) type Variances = chalk_ir::Variances<Interner>; | 31 | pub(crate) type Variances = chalk_ir::Variances<Interner>; |
32 | 32 | ||
33 | #[derive(PartialEq, Eq, Hash, Debug)] | 33 | #[derive(PartialEq, Eq, Hash, Debug)] |
34 | pub struct InternedVariableKindsInner(Vec<chalk_ir::VariableKind<Interner>>); | ||
35 | |||
36 | #[derive(PartialEq, Eq, Hash, Debug)] | ||
37 | pub struct InternedSubstitutionInner(SmallVec<[GenericArg; 2]>); | ||
38 | |||
39 | #[derive(PartialEq, Eq, Hash, Debug)] | ||
40 | pub struct InternedTypeInner(chalk_ir::TyData<Interner>); | ||
41 | |||
42 | #[derive(PartialEq, Eq, Hash, Debug)] | ||
43 | pub struct InternedWrapper<T>(T); | 34 | pub struct InternedWrapper<T>(T); |
44 | 35 | ||
45 | impl<T> std::ops::Deref for InternedWrapper<T> { | 36 | impl<T> std::ops::Deref for InternedWrapper<T> { |
@@ -51,9 +42,9 @@ impl<T> std::ops::Deref for InternedWrapper<T> { | |||
51 | } | 42 | } |
52 | 43 | ||
53 | impl_internable!( | 44 | impl_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 | ||
65 | impl chalk_ir::interner::Interner for Interner { | 56 | impl 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>( |