diff options
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 85 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/interner.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 287 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/tls.rs | 9 |
4 files changed, 134 insertions, 249 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 565672b6b..232cf9cd0 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -17,29 +17,31 @@ use super::ChalkContext; | |||
17 | use crate::{ | 17 | use crate::{ |
18 | db::HirDatabase, | 18 | db::HirDatabase, |
19 | display::HirDisplay, | 19 | display::HirDisplay, |
20 | from_assoc_type_id, | ||
20 | method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, | 21 | method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, |
22 | to_assoc_type_id, | ||
21 | utils::generics, | 23 | utils::generics, |
22 | BoundVar, CallableDefId, CallableSig, DebruijnIndex, GenericPredicate, ProjectionPredicate, | 24 | BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, GenericPredicate, |
23 | ProjectionTy, Substs, TraitRef, Ty, | 25 | ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TyKind, |
24 | }; | 26 | }; |
25 | use mapping::{ | 27 | use mapping::{ |
26 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsAssocType, | 28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, |
27 | TypeAliasAsValue, | ||
28 | }; | 29 | }; |
29 | 30 | ||
31 | pub use self::interner::Interner; | ||
30 | pub(crate) use self::interner::*; | 32 | pub(crate) use self::interner::*; |
31 | 33 | ||
32 | pub(super) mod tls; | 34 | pub(super) mod tls; |
33 | mod interner; | 35 | mod interner; |
34 | mod mapping; | 36 | mod mapping; |
35 | 37 | ||
36 | pub(super) trait ToChalk { | 38 | pub(crate) trait ToChalk { |
37 | type Chalk; | 39 | type Chalk; |
38 | fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk; | 40 | fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk; |
39 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self; | 41 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self; |
40 | } | 42 | } |
41 | 43 | ||
42 | pub(super) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T | 44 | pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T |
43 | where | 45 | where |
44 | T: ToChalk<Chalk = ChalkT>, | 46 | T: ToChalk<Chalk = ChalkT>, |
45 | { | 47 | { |
@@ -90,7 +92,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
90 | ty: &Ty, | 92 | ty: &Ty, |
91 | binders: &CanonicalVarKinds<Interner>, | 93 | binders: &CanonicalVarKinds<Interner>, |
92 | ) -> Option<chalk_ir::TyVariableKind> { | 94 | ) -> Option<chalk_ir::TyVariableKind> { |
93 | if let Ty::BoundVar(bv) = ty { | 95 | if let TyKind::BoundVar(bv) = ty.interned(&Interner) { |
94 | let binders = binders.as_slice(&Interner); | 96 | let binders = binders.as_slice(&Interner); |
95 | if bv.debruijn == DebruijnIndex::INNERMOST { | 97 | if bv.debruijn == DebruijnIndex::INNERMOST { |
96 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { | 98 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { |
@@ -175,10 +177,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
175 | } | 177 | } |
176 | 178 | ||
177 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { | 179 | fn opaque_ty_data(&self, id: chalk_ir::OpaqueTyId<Interner>) -> Arc<OpaqueTyDatum> { |
178 | let interned_id = crate::db::InternedOpaqueTyId::from(id); | 180 | let full_id = self.db.lookup_intern_impl_trait_id(id.into()); |
179 | let full_id = self.db.lookup_intern_impl_trait_id(interned_id); | ||
180 | let bound = match full_id { | 181 | let bound = match full_id { |
181 | crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 182 | crate::ImplTraitId::ReturnTypeImplTrait(func, idx) => { |
182 | let datas = self | 183 | let datas = self |
183 | .db | 184 | .db |
184 | .return_type_impl_traits(func) | 185 | .return_type_impl_traits(func) |
@@ -200,7 +201,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
200 | let num_vars = datas.num_binders; | 201 | let num_vars = datas.num_binders; |
201 | make_binders(bound, num_vars) | 202 | make_binders(bound, num_vars) |
202 | } | 203 | } |
203 | crate::OpaqueTyId::AsyncBlockTypeImplTrait(..) => { | 204 | crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => { |
204 | if let Some((future_trait, future_output)) = self | 205 | if let Some((future_trait, future_output)) = self |
205 | .db | 206 | .db |
206 | .lang_item(self.krate, "future_trait".into()) | 207 | .lang_item(self.krate, "future_trait".into()) |
@@ -220,21 +221,25 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
220 | let impl_bound = GenericPredicate::Implemented(TraitRef { | 221 | let impl_bound = GenericPredicate::Implemented(TraitRef { |
221 | trait_: future_trait, | 222 | trait_: future_trait, |
222 | // Self type as the first parameter. | 223 | // Self type as the first parameter. |
223 | substs: Substs::single(Ty::BoundVar(BoundVar { | 224 | substs: Substs::single( |
224 | debruijn: DebruijnIndex::INNERMOST, | 225 | TyKind::BoundVar(BoundVar { |
225 | index: 0, | 226 | debruijn: DebruijnIndex::INNERMOST, |
226 | })), | 227 | index: 0, |
228 | }) | ||
229 | .intern(&Interner), | ||
230 | ), | ||
227 | }); | 231 | }); |
228 | let proj_bound = GenericPredicate::Projection(ProjectionPredicate { | 232 | let proj_bound = GenericPredicate::Projection(ProjectionPredicate { |
229 | // The parameter of the opaque type. | 233 | // The parameter of the opaque type. |
230 | ty: Ty::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }), | 234 | ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }) |
235 | .intern(&Interner), | ||
231 | projection_ty: ProjectionTy { | 236 | projection_ty: ProjectionTy { |
232 | associated_ty: future_output, | 237 | associated_ty_id: to_assoc_type_id(future_output), |
233 | // Self type as the first parameter. | 238 | // Self type as the first parameter. |
234 | parameters: Substs::single(Ty::BoundVar(BoundVar::new( | 239 | substitution: Substs::single( |
235 | DebruijnIndex::INNERMOST, | 240 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) |
236 | 0, | 241 | .intern(&Interner), |
237 | ))), | 242 | ), |
238 | }, | 243 | }, |
239 | }); | 244 | }); |
240 | let bound = OpaqueTyDatumBound { | 245 | let bound = OpaqueTyDatumBound { |
@@ -263,7 +268,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
263 | 268 | ||
264 | fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> { | 269 | fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> { |
265 | // FIXME: actually provide the hidden type; it is relevant for auto traits | 270 | // FIXME: actually provide the hidden type; it is relevant for auto traits |
266 | Ty::Unknown.to_chalk(self.db) | 271 | TyKind::Unknown.intern(&Interner).to_chalk(self.db) |
267 | } | 272 | } |
268 | 273 | ||
269 | fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { | 274 | fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { |
@@ -378,7 +383,7 @@ pub(crate) fn associated_ty_data_query( | |||
378 | id: AssocTypeId, | 383 | id: AssocTypeId, |
379 | ) -> Arc<AssociatedTyDatum> { | 384 | ) -> Arc<AssociatedTyDatum> { |
380 | debug!("associated_ty_data {:?}", id); | 385 | debug!("associated_ty_data {:?}", id); |
381 | let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(db, id).0; | 386 | let type_alias: TypeAliasId = from_assoc_type_id(id); |
382 | let trait_ = match type_alias.lookup(db.upcast()).container { | 387 | let trait_ = match type_alias.lookup(db.upcast()).container { |
383 | AssocContainerId::TraitId(t) => t, | 388 | AssocContainerId::TraitId(t) => t, |
384 | _ => panic!("associated type not in trait"), | 389 | _ => panic!("associated type not in trait"), |
@@ -391,11 +396,12 @@ pub(crate) fn associated_ty_data_query( | |||
391 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); | 396 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); |
392 | let ctx = crate::TyLoweringContext::new(db, &resolver) | 397 | let ctx = crate::TyLoweringContext::new(db, &resolver) |
393 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); | 398 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); |
394 | let self_ty = Ty::BoundVar(crate::BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)); | 399 | let self_ty = |
400 | TyKind::BoundVar(BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)).intern(&Interner); | ||
395 | let bounds = type_alias_data | 401 | let bounds = type_alias_data |
396 | .bounds | 402 | .bounds |
397 | .iter() | 403 | .iter() |
398 | .flat_map(|bound| GenericPredicate::from_type_bound(&ctx, bound, self_ty.clone())) | 404 | .flat_map(|bound| ctx.lower_type_bound(bound, self_ty.clone())) |
399 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) | 405 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) |
400 | .map(|bound| make_binders(bound.shifted_in(&Interner), 0)) | 406 | .map(|bound| make_binders(bound.shifted_in(&Interner), 0)) |
401 | .collect(); | 407 | .collect(); |
@@ -432,10 +438,8 @@ pub(crate) fn trait_datum_query( | |||
432 | fundamental: false, | 438 | fundamental: false, |
433 | }; | 439 | }; |
434 | let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); | 440 | let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); |
435 | let associated_ty_ids = trait_data | 441 | let associated_ty_ids = |
436 | .associated_types() | 442 | trait_data.associated_types().map(|type_alias| to_assoc_type_id(type_alias)).collect(); |
437 | .map(|type_alias| TypeAliasAsAssocType(type_alias).to_chalk(db)) | ||
438 | .collect(); | ||
439 | let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; | 443 | let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; |
440 | let well_known = | 444 | let well_known = |
441 | lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); | 445 | lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); |
@@ -487,19 +491,14 @@ pub(crate) fn struct_datum_query( | |||
487 | struct_id: AdtId, | 491 | struct_id: AdtId, |
488 | ) -> Arc<StructDatum> { | 492 | ) -> Arc<StructDatum> { |
489 | debug!("struct_datum {:?}", struct_id); | 493 | debug!("struct_datum {:?}", struct_id); |
490 | let type_ctor = Ty::Adt(struct_id, Substs::empty()); | ||
491 | let chalk_ir::AdtId(adt_id) = struct_id; | 494 | let chalk_ir::AdtId(adt_id) = struct_id; |
492 | debug!("struct {:?} = {:?}", struct_id, type_ctor); | ||
493 | let num_params = generics(db.upcast(), adt_id.into()).len(); | 495 | let num_params = generics(db.upcast(), adt_id.into()).len(); |
494 | let upstream = adt_id.module(db.upcast()).krate() != krate; | 496 | let upstream = adt_id.module(db.upcast()).krate() != krate; |
495 | let where_clauses = type_ctor | 497 | let where_clauses = { |
496 | .as_generic_def() | 498 | let generic_params = generics(db.upcast(), adt_id.into()); |
497 | .map(|generic_def| { | 499 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
498 | let generic_params = generics(db.upcast(), generic_def); | 500 | convert_where_clauses(db, adt_id.into(), &bound_vars) |
499 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 501 | }; |
500 | convert_where_clauses(db, generic_def, &bound_vars) | ||
501 | }) | ||
502 | .unwrap_or_else(Vec::new); | ||
503 | let flags = rust_ir::AdtFlags { | 502 | let flags = rust_ir::AdtFlags { |
504 | upstream, | 503 | upstream, |
505 | // FIXME set fundamental and phantom_data flags correctly | 504 | // FIXME set fundamental and phantom_data flags correctly |
@@ -622,7 +621,7 @@ fn type_alias_associated_ty_value( | |||
622 | let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; | 621 | let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; |
623 | let value = rust_ir::AssociatedTyValue { | 622 | let value = rust_ir::AssociatedTyValue { |
624 | impl_id: impl_id.to_chalk(db), | 623 | impl_id: impl_id.to_chalk(db), |
625 | associated_ty_id: TypeAliasAsAssocType(assoc_ty).to_chalk(db), | 624 | associated_ty_id: to_assoc_type_id(assoc_ty), |
626 | value: make_binders(value_bound, ty.num_binders), | 625 | value: make_binders(value_bound, ty.num_binders), |
627 | }; | 626 | }; |
628 | Arc::new(value) | 627 | Arc::new(value) |
@@ -716,14 +715,14 @@ impl From<crate::db::InternedOpaqueTyId> for OpaqueTyId { | |||
716 | } | 715 | } |
717 | } | 716 | } |
718 | 717 | ||
719 | impl From<chalk_ir::ClosureId<Interner>> for crate::db::ClosureId { | 718 | impl From<chalk_ir::ClosureId<Interner>> for crate::db::InternedClosureId { |
720 | fn from(id: chalk_ir::ClosureId<Interner>) -> Self { | 719 | fn from(id: chalk_ir::ClosureId<Interner>) -> Self { |
721 | Self::from_intern_id(id.0) | 720 | Self::from_intern_id(id.0) |
722 | } | 721 | } |
723 | } | 722 | } |
724 | 723 | ||
725 | impl From<crate::db::ClosureId> for chalk_ir::ClosureId<Interner> { | 724 | impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> { |
726 | fn from(id: crate::db::ClosureId) -> Self { | 725 | fn from(id: crate::db::InternedClosureId) -> Self { |
727 | chalk_ir::ClosureId(id.as_intern_id()) | 726 | chalk_ir::ClosureId(id.as_intern_id()) |
728 | } | 727 | } |
729 | } | 728 | } |
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index 54bd1c724..1dc3f497d 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs | |||
@@ -12,7 +12,6 @@ pub struct Interner; | |||
12 | 12 | ||
13 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | 13 | pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>; |
14 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; | 14 | pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>; |
15 | pub(crate) type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | ||
16 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; | 15 | pub(crate) type TraitId = chalk_ir::TraitId<Interner>; |
17 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; | 16 | pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>; |
18 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; | 17 | pub(crate) type AdtId = chalk_ir::AdtId<Interner>; |
@@ -21,7 +20,6 @@ pub(crate) type ImplId = chalk_ir::ImplId<Interner>; | |||
21 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; | 20 | pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>; |
22 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; | 21 | pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>; |
23 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; | 22 | pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>; |
24 | pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>; | ||
25 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; | 23 | pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>; |
26 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; | 24 | pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; |
27 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; | 25 | pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 3a08b67e9..6a8b6752e 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -3,10 +3,7 @@ | |||
3 | //! Chalk (in both directions); plus some helper functions for more specialized | 3 | //! Chalk (in both directions); plus some helper functions for more specialized |
4 | //! conversions. | 4 | //! conversions. |
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData}; |
7 | cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, | ||
8 | UniverseIndex, | ||
9 | }; | ||
10 | use chalk_solve::rust_ir; | 7 | use chalk_solve::rust_ir; |
11 | 8 | ||
12 | use base_db::salsa::InternKey; | 9 | use base_db::salsa::InternKey; |
@@ -14,10 +11,11 @@ use hir_def::{AssocContainerId, GenericDefId, Lookup, TypeAliasId}; | |||
14 | 11 | ||
15 | use crate::{ | 12 | use crate::{ |
16 | db::HirDatabase, | 13 | db::HirDatabase, |
14 | from_assoc_type_id, | ||
17 | primitive::UintTy, | 15 | primitive::UintTy, |
18 | traits::{Canonical, Obligation}, | 16 | traits::{Canonical, Obligation}, |
19 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, | 17 | AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, |
20 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, TraitRef, Ty, | 18 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, |
21 | }; | 19 | }; |
22 | 20 | ||
23 | use super::interner::*; | 21 | use super::interner::*; |
@@ -26,71 +24,60 @@ use super::*; | |||
26 | impl ToChalk for Ty { | 24 | impl ToChalk for Ty { |
27 | type Chalk = chalk_ir::Ty<Interner>; | 25 | type Chalk = chalk_ir::Ty<Interner>; |
28 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { | 26 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { |
29 | match self { | 27 | match self.into_inner() { |
30 | Ty::Ref(m, parameters) => ref_to_chalk(db, m, parameters), | 28 | TyKind::Ref(m, ty) => ref_to_chalk(db, m, ty), |
31 | Ty::Array(parameters) => array_to_chalk(db, parameters), | 29 | TyKind::Array(ty) => array_to_chalk(db, ty), |
32 | Ty::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { | 30 | TyKind::Function(FnPointer { sig, substs, .. }) => { |
33 | let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); | 31 | let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); |
34 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 32 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
35 | num_binders: 0, | 33 | num_binders: 0, |
36 | sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic }, | 34 | sig, |
37 | substitution, | 35 | substitution, |
38 | }) | 36 | }) |
39 | .intern(&Interner) | 37 | .intern(&Interner) |
40 | } | 38 | } |
41 | Ty::AssociatedType(type_alias, substs) => { | 39 | TyKind::AssociatedType(assoc_type_id, substs) => { |
42 | let assoc_type = TypeAliasAsAssocType(type_alias); | ||
43 | let assoc_type_id = assoc_type.to_chalk(db); | ||
44 | let substitution = substs.to_chalk(db); | 40 | let substitution = substs.to_chalk(db); |
45 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) | 41 | chalk_ir::TyKind::AssociatedType(assoc_type_id, substitution).intern(&Interner) |
46 | } | 42 | } |
47 | 43 | ||
48 | Ty::OpaqueType(impl_trait_id, substs) => { | 44 | TyKind::OpaqueType(id, substs) => { |
49 | let id = impl_trait_id.to_chalk(db); | ||
50 | let substitution = substs.to_chalk(db); | 45 | let substitution = substs.to_chalk(db); |
51 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) | 46 | chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) |
52 | } | 47 | } |
53 | 48 | ||
54 | Ty::ForeignType(type_alias) => { | 49 | TyKind::ForeignType(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner), |
55 | let foreign_type = TypeAliasAsForeignType(type_alias); | ||
56 | let foreign_type_id = foreign_type.to_chalk(db); | ||
57 | chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner) | ||
58 | } | ||
59 | 50 | ||
60 | Ty::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), | 51 | TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), |
61 | 52 | ||
62 | Ty::Tuple(cardinality, substs) => { | 53 | TyKind::Tuple(cardinality, substs) => { |
63 | let substitution = substs.to_chalk(db); | 54 | let substitution = substs.to_chalk(db); |
64 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) | 55 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) |
65 | } | 56 | } |
66 | Ty::Raw(mutability, substs) => { | 57 | TyKind::Raw(mutability, ty) => { |
67 | let ty = substs[0].clone().to_chalk(db); | 58 | let ty = ty.to_chalk(db); |
68 | chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) | 59 | chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) |
69 | } | 60 | } |
70 | Ty::Slice(substs) => { | 61 | TyKind::Slice(ty) => chalk_ir::TyKind::Slice(ty.to_chalk(db)).intern(&Interner), |
71 | chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner) | 62 | TyKind::Str => chalk_ir::TyKind::Str.intern(&Interner), |
72 | } | 63 | TyKind::FnDef(id, substs) => { |
73 | Ty::Str => chalk_ir::TyKind::Str.intern(&Interner), | ||
74 | Ty::FnDef(callable_def, substs) => { | ||
75 | let id = callable_def.to_chalk(db); | ||
76 | let substitution = substs.to_chalk(db); | 64 | let substitution = substs.to_chalk(db); |
77 | chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) | 65 | chalk_ir::TyKind::FnDef(id, substitution).intern(&Interner) |
78 | } | 66 | } |
79 | Ty::Never => chalk_ir::TyKind::Never.intern(&Interner), | 67 | TyKind::Never => chalk_ir::TyKind::Never.intern(&Interner), |
80 | 68 | ||
81 | Ty::Closure(def, expr, substs) => { | 69 | TyKind::Closure(closure_id, substs) => { |
82 | let closure_id = db.intern_closure((def, expr)); | ||
83 | let substitution = substs.to_chalk(db); | 70 | let substitution = substs.to_chalk(db); |
84 | chalk_ir::TyKind::Closure(closure_id.into(), substitution).intern(&Interner) | 71 | chalk_ir::TyKind::Closure(closure_id, substitution).intern(&Interner) |
85 | } | 72 | } |
86 | 73 | ||
87 | Ty::Adt(adt_id, substs) => { | 74 | TyKind::Adt(adt_id, substs) => { |
88 | let substitution = substs.to_chalk(db); | 75 | let substitution = substs.to_chalk(db); |
89 | chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) | 76 | chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) |
90 | } | 77 | } |
91 | Ty::Alias(AliasTy::Projection(proj_ty)) => { | 78 | TyKind::Alias(AliasTy::Projection(proj_ty)) => { |
92 | let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); | 79 | let associated_ty_id = proj_ty.associated_ty_id; |
93 | let substitution = proj_ty.parameters.to_chalk(db); | 80 | let substitution = proj_ty.substitution.to_chalk(db); |
94 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { | 81 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { |
95 | associated_ty_id, | 82 | associated_ty_id, |
96 | substitution, | 83 | substitution, |
@@ -98,17 +85,17 @@ impl ToChalk for Ty { | |||
98 | .cast(&Interner) | 85 | .cast(&Interner) |
99 | .intern(&Interner) | 86 | .intern(&Interner) |
100 | } | 87 | } |
101 | Ty::Placeholder(id) => { | 88 | TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { |
102 | let interned_id = db.intern_type_param_id(id); | 89 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
103 | PlaceholderIndex { | 90 | let substitution = opaque_ty.substitution.to_chalk(db); |
104 | ui: UniverseIndex::ROOT, | 91 | chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id, substitution }) |
105 | idx: interned_id.as_intern_id().as_usize(), | 92 | .cast(&Interner) |
106 | } | 93 | .intern(&Interner) |
107 | .to_ty::<Interner>(&Interner) | 94 | } |
108 | } | 95 | TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner), |
109 | Ty::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), | 96 | TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
110 | Ty::InferenceVar(..) => panic!("uncanonicalized infer ty"), | 97 | TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), |
111 | Ty::Dyn(predicates) => { | 98 | TyKind::Dyn(predicates) => { |
112 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( | 99 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( |
113 | &Interner, | 100 | &Interner, |
114 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), | 101 | predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), |
@@ -119,43 +106,30 @@ impl ToChalk for Ty { | |||
119 | }; | 106 | }; |
120 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 107 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
121 | } | 108 | } |
122 | Ty::Alias(AliasTy::Opaque(opaque_ty)) => { | 109 | TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner), |
123 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | ||
124 | let substitution = opaque_ty.parameters.to_chalk(db); | ||
125 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | ||
126 | opaque_ty_id, | ||
127 | substitution, | ||
128 | })) | ||
129 | .intern(&Interner) | ||
130 | } | ||
131 | Ty::Unknown => chalk_ir::TyKind::Error.intern(&Interner), | ||
132 | } | 110 | } |
133 | } | 111 | } |
134 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { | 112 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { |
135 | match chalk.data(&Interner).kind.clone() { | 113 | match chalk.data(&Interner).kind.clone() { |
136 | chalk_ir::TyKind::Error => Ty::Unknown, | 114 | chalk_ir::TyKind::Error => TyKind::Unknown, |
137 | chalk_ir::TyKind::Array(ty, _size) => Ty::Array(Substs::single(from_chalk(db, ty))), | 115 | chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(from_chalk(db, ty)), |
138 | chalk_ir::TyKind::Placeholder(idx) => { | 116 | chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx), |
139 | assert_eq!(idx.ui, UniverseIndex::ROOT); | ||
140 | let interned_id = crate::db::GlobalTypeParamId::from_intern_id( | ||
141 | crate::salsa::InternId::from(idx.idx), | ||
142 | ); | ||
143 | Ty::Placeholder(db.lookup_intern_type_param_id(interned_id)) | ||
144 | } | ||
145 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { | 117 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { |
146 | let associated_ty = | 118 | let associated_ty = proj.associated_ty_id; |
147 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; | ||
148 | let parameters = from_chalk(db, proj.substitution); | 119 | let parameters = from_chalk(db, proj.substitution); |
149 | Ty::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) | 120 | TyKind::Alias(AliasTy::Projection(ProjectionTy { |
121 | associated_ty_id: associated_ty, | ||
122 | substitution: parameters, | ||
123 | })) | ||
150 | } | 124 | } |
151 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 125 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
152 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 126 | let opaque_ty_id = opaque_ty.opaque_ty_id; |
153 | let parameters = from_chalk(db, opaque_ty.substitution); | 127 | let parameters = from_chalk(db, opaque_ty.substitution); |
154 | Ty::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) | 128 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, substitution: parameters })) |
155 | } | 129 | } |
156 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 130 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
157 | num_binders, | 131 | num_binders, |
158 | sig: chalk_ir::FnSig { variadic, .. }, | 132 | sig, |
159 | substitution, | 133 | substitution, |
160 | .. | 134 | .. |
161 | }) => { | 135 | }) => { |
@@ -164,14 +138,10 @@ impl ToChalk for Ty { | |||
164 | db, | 138 | db, |
165 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), | 139 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), |
166 | ); | 140 | ); |
167 | Ty::Function(FnPointer { | 141 | TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs }) |
168 | num_args: (substs.len() - 1), | ||
169 | sig: FnSig { variadic }, | ||
170 | substs, | ||
171 | }) | ||
172 | } | 142 | } |
173 | chalk_ir::TyKind::BoundVar(idx) => Ty::BoundVar(idx), | 143 | chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), |
174 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, | 144 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, |
175 | chalk_ir::TyKind::Dyn(where_clauses) => { | 145 | chalk_ir::TyKind::Dyn(where_clauses) => { |
176 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); | 146 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); |
177 | let predicates = where_clauses | 147 | let predicates = where_clauses |
@@ -180,49 +150,41 @@ impl ToChalk for Ty { | |||
180 | .iter(&Interner) | 150 | .iter(&Interner) |
181 | .map(|c| from_chalk(db, c.clone())) | 151 | .map(|c| from_chalk(db, c.clone())) |
182 | .collect(); | 152 | .collect(); |
183 | Ty::Dyn(predicates) | 153 | TyKind::Dyn(predicates) |
184 | } | 154 | } |
185 | 155 | ||
186 | chalk_ir::TyKind::Adt(adt_id, subst) => Ty::Adt(adt_id, from_chalk(db, subst)), | 156 | chalk_ir::TyKind::Adt(adt_id, subst) => TyKind::Adt(adt_id, from_chalk(db, subst)), |
187 | chalk_ir::TyKind::AssociatedType(type_id, subst) => Ty::AssociatedType( | 157 | chalk_ir::TyKind::AssociatedType(type_id, subst) => { |
188 | from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0, | 158 | TyKind::AssociatedType(type_id, from_chalk(db, subst)) |
189 | from_chalk(db, subst), | 159 | } |
190 | ), | ||
191 | 160 | ||
192 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { | 161 | chalk_ir::TyKind::OpaqueType(opaque_type_id, subst) => { |
193 | Ty::OpaqueType(from_chalk(db, opaque_type_id), from_chalk(db, subst)) | 162 | TyKind::OpaqueType(opaque_type_id, from_chalk(db, subst)) |
194 | } | 163 | } |
195 | 164 | ||
196 | chalk_ir::TyKind::Scalar(scalar) => Ty::Scalar(scalar), | 165 | chalk_ir::TyKind::Scalar(scalar) => TyKind::Scalar(scalar), |
197 | chalk_ir::TyKind::Tuple(cardinality, subst) => { | 166 | chalk_ir::TyKind::Tuple(cardinality, subst) => { |
198 | Ty::Tuple(cardinality, from_chalk(db, subst)) | 167 | TyKind::Tuple(cardinality, from_chalk(db, subst)) |
199 | } | 168 | } |
200 | chalk_ir::TyKind::Raw(mutability, ty) => { | 169 | chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)), |
201 | Ty::Raw(mutability, Substs::single(from_chalk(db, ty))) | 170 | chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)), |
202 | } | ||
203 | chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))), | ||
204 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { | 171 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { |
205 | Ty::Ref(mutability, Substs::single(from_chalk(db, ty))) | 172 | TyKind::Ref(mutability, from_chalk(db, ty)) |
206 | } | 173 | } |
207 | chalk_ir::TyKind::Str => Ty::Str, | 174 | chalk_ir::TyKind::Str => TyKind::Str, |
208 | chalk_ir::TyKind::Never => Ty::Never, | 175 | chalk_ir::TyKind::Never => TyKind::Never, |
209 | 176 | ||
210 | chalk_ir::TyKind::FnDef(fn_def_id, subst) => { | 177 | chalk_ir::TyKind::FnDef(fn_def_id, subst) => { |
211 | Ty::FnDef(from_chalk(db, fn_def_id), from_chalk(db, subst)) | 178 | TyKind::FnDef(fn_def_id, from_chalk(db, subst)) |
212 | } | 179 | } |
213 | 180 | ||
214 | chalk_ir::TyKind::Closure(id, subst) => { | 181 | chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)), |
215 | let id: crate::db::ClosureId = id.into(); | ||
216 | let (def, expr) = db.lookup_intern_closure(id); | ||
217 | Ty::Closure(def, expr, from_chalk(db, subst)) | ||
218 | } | ||
219 | 182 | ||
220 | chalk_ir::TyKind::Foreign(foreign_def_id) => { | 183 | chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), |
221 | Ty::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0) | ||
222 | } | ||
223 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME | 184 | chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME |
224 | chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME | 185 | chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME |
225 | } | 186 | } |
187 | .intern(&Interner) | ||
226 | } | 188 | } |
227 | } | 189 | } |
228 | 190 | ||
@@ -231,17 +193,17 @@ impl ToChalk for Ty { | |||
231 | fn ref_to_chalk( | 193 | fn ref_to_chalk( |
232 | db: &dyn HirDatabase, | 194 | db: &dyn HirDatabase, |
233 | mutability: chalk_ir::Mutability, | 195 | mutability: chalk_ir::Mutability, |
234 | subst: Substs, | 196 | ty: Ty, |
235 | ) -> chalk_ir::Ty<Interner> { | 197 | ) -> chalk_ir::Ty<Interner> { |
236 | let arg = subst[0].clone().to_chalk(db); | 198 | let arg = ty.to_chalk(db); |
237 | let lifetime = LifetimeData::Static.intern(&Interner); | 199 | let lifetime = LifetimeData::Static.intern(&Interner); |
238 | chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) | 200 | chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) |
239 | } | 201 | } |
240 | 202 | ||
241 | /// We currently don't model constants, but Chalk does. So, we have to insert a | 203 | /// We currently don't model constants, but Chalk does. So, we have to insert a |
242 | /// fake constant here, because Chalks built-in logic may expect it to be there. | 204 | /// fake constant here, because Chalks built-in logic may expect it to be there. |
243 | fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty<Interner> { | 205 | fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> { |
244 | let arg = subst[0].clone().to_chalk(db); | 206 | let arg = ty.to_chalk(db); |
245 | let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner); | 207 | let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner); |
246 | let const_ = chalk_ir::ConstData { | 208 | let const_ = chalk_ir::ConstData { |
247 | ty: usize_ty, | 209 | ty: usize_ty, |
@@ -298,21 +260,6 @@ impl ToChalk for hir_def::TraitId { | |||
298 | } | 260 | } |
299 | } | 261 | } |
300 | 262 | ||
301 | impl ToChalk for OpaqueTyId { | ||
302 | type Chalk = chalk_ir::OpaqueTyId<Interner>; | ||
303 | |||
304 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::OpaqueTyId<Interner> { | ||
305 | db.intern_impl_trait_id(self).into() | ||
306 | } | ||
307 | |||
308 | fn from_chalk( | ||
309 | db: &dyn HirDatabase, | ||
310 | opaque_ty_id: chalk_ir::OpaqueTyId<Interner>, | ||
311 | ) -> OpaqueTyId { | ||
312 | db.lookup_intern_impl_trait_id(opaque_ty_id.into()) | ||
313 | } | ||
314 | } | ||
315 | |||
316 | impl ToChalk for hir_def::ImplId { | 263 | impl ToChalk for hir_def::ImplId { |
317 | type Chalk = ImplId; | 264 | type Chalk = ImplId; |
318 | 265 | ||
@@ -337,34 +284,6 @@ impl ToChalk for CallableDefId { | |||
337 | } | 284 | } |
338 | } | 285 | } |
339 | 286 | ||
340 | pub(crate) struct TypeAliasAsAssocType(pub(crate) TypeAliasId); | ||
341 | |||
342 | impl ToChalk for TypeAliasAsAssocType { | ||
343 | type Chalk = AssocTypeId; | ||
344 | |||
345 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { | ||
346 | chalk_ir::AssocTypeId(self.0.as_intern_id()) | ||
347 | } | ||
348 | |||
349 | fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType { | ||
350 | TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0)) | ||
351 | } | ||
352 | } | ||
353 | |||
354 | pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId); | ||
355 | |||
356 | impl ToChalk for TypeAliasAsForeignType { | ||
357 | type Chalk = ForeignDefId; | ||
358 | |||
359 | fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId { | ||
360 | chalk_ir::ForeignDefId(self.0.as_intern_id()) | ||
361 | } | ||
362 | |||
363 | fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType { | ||
364 | TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0)) | ||
365 | } | ||
366 | } | ||
367 | |||
368 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); | 287 | pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId); |
369 | 288 | ||
370 | impl ToChalk for TypeAliasAsValue { | 289 | impl ToChalk for TypeAliasAsValue { |
@@ -446,8 +365,8 @@ impl ToChalk for ProjectionTy { | |||
446 | 365 | ||
447 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { | 366 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { |
448 | chalk_ir::ProjectionTy { | 367 | chalk_ir::ProjectionTy { |
449 | associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db), | 368 | associated_ty_id: self.associated_ty_id, |
450 | substitution: self.parameters.to_chalk(db), | 369 | substitution: self.substitution.to_chalk(db), |
451 | } | 370 | } |
452 | } | 371 | } |
453 | 372 | ||
@@ -456,12 +375,8 @@ impl ToChalk for ProjectionTy { | |||
456 | projection_ty: chalk_ir::ProjectionTy<Interner>, | 375 | projection_ty: chalk_ir::ProjectionTy<Interner>, |
457 | ) -> ProjectionTy { | 376 | ) -> ProjectionTy { |
458 | ProjectionTy { | 377 | ProjectionTy { |
459 | associated_ty: from_chalk::<TypeAliasAsAssocType, _>( | 378 | associated_ty_id: projection_ty.associated_ty_id, |
460 | db, | 379 | substitution: from_chalk(db, projection_ty.substitution), |
461 | projection_ty.associated_ty_id, | ||
462 | ) | ||
463 | .0, | ||
464 | parameters: from_chalk(db, projection_ty.substitution), | ||
465 | } | 380 | } |
466 | } | 381 | } |
467 | } | 382 | } |
@@ -536,31 +451,6 @@ where | |||
536 | } | 451 | } |
537 | } | 452 | } |
538 | 453 | ||
539 | impl ToChalk for Arc<TraitEnvironment> { | ||
540 | type Chalk = chalk_ir::Environment<Interner>; | ||
541 | |||
542 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Environment<Interner> { | ||
543 | let mut clauses = Vec::new(); | ||
544 | for pred in &self.predicates { | ||
545 | if pred.is_error() { | ||
546 | // for env, we just ignore errors | ||
547 | continue; | ||
548 | } | ||
549 | let program_clause: chalk_ir::ProgramClause<Interner> = | ||
550 | pred.clone().to_chalk(db).cast(&Interner); | ||
551 | clauses.push(program_clause.into_from_env_clause(&Interner)); | ||
552 | } | ||
553 | chalk_ir::Environment::new(&Interner).add_clauses(&Interner, clauses) | ||
554 | } | ||
555 | |||
556 | fn from_chalk( | ||
557 | _db: &dyn HirDatabase, | ||
558 | _env: chalk_ir::Environment<Interner>, | ||
559 | ) -> Arc<TraitEnvironment> { | ||
560 | unimplemented!() | ||
561 | } | ||
562 | } | ||
563 | |||
564 | impl<T: ToChalk> ToChalk for InEnvironment<T> | 454 | impl<T: ToChalk> ToChalk for InEnvironment<T> |
565 | where | 455 | where |
566 | T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>, | 456 | T::Chalk: chalk_ir::interner::HasInterner<Interner = Interner>, |
@@ -569,19 +459,16 @@ where | |||
569 | 459 | ||
570 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { | 460 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { |
571 | chalk_ir::InEnvironment { | 461 | chalk_ir::InEnvironment { |
572 | environment: self.environment.to_chalk(db), | 462 | environment: self.environment.env.clone(), |
573 | goal: self.value.to_chalk(db), | 463 | goal: self.value.to_chalk(db), |
574 | } | 464 | } |
575 | } | 465 | } |
576 | 466 | ||
577 | fn from_chalk( | 467 | fn from_chalk( |
578 | db: &dyn HirDatabase, | 468 | _db: &dyn HirDatabase, |
579 | in_env: chalk_ir::InEnvironment<T::Chalk>, | 469 | _in_env: chalk_ir::InEnvironment<T::Chalk>, |
580 | ) -> InEnvironment<T> { | 470 | ) -> InEnvironment<T> { |
581 | InEnvironment { | 471 | unimplemented!() |
582 | environment: from_chalk(db, in_env.environment), | ||
583 | value: from_chalk(db, in_env.goal), | ||
584 | } | ||
585 | } | 472 | } |
586 | } | 473 | } |
587 | 474 | ||
@@ -639,22 +526,24 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
639 | Some(rust_ir::InlineBound::TraitBound(trait_bound)) | 526 | Some(rust_ir::InlineBound::TraitBound(trait_bound)) |
640 | } | 527 | } |
641 | GenericPredicate::Projection(proj) => { | 528 | GenericPredicate::Projection(proj) => { |
642 | if &proj.projection_ty.parameters[0] != self_ty { | 529 | if &proj.projection_ty.substitution[0] != self_ty { |
643 | return None; | 530 | return None; |
644 | } | 531 | } |
645 | let trait_ = match proj.projection_ty.associated_ty.lookup(db.upcast()).container { | 532 | let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty_id) |
533 | .lookup(db.upcast()) | ||
534 | .container | ||
535 | { | ||
646 | AssocContainerId::TraitId(t) => t, | 536 | AssocContainerId::TraitId(t) => t, |
647 | _ => panic!("associated type not in trait"), | 537 | _ => panic!("associated type not in trait"), |
648 | }; | 538 | }; |
649 | let args_no_self = proj.projection_ty.parameters[1..] | 539 | let args_no_self = proj.projection_ty.substitution[1..] |
650 | .iter() | 540 | .iter() |
651 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) | 541 | .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) |
652 | .collect(); | 542 | .collect(); |
653 | let alias_eq_bound = rust_ir::AliasEqBound { | 543 | let alias_eq_bound = rust_ir::AliasEqBound { |
654 | value: proj.ty.clone().to_chalk(db), | 544 | value: proj.ty.clone().to_chalk(db), |
655 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, | 545 | trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, |
656 | associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty) | 546 | associated_ty_id: proj.projection_ty.associated_ty_id, |
657 | .to_chalk(db), | ||
658 | parameters: Vec::new(), // FIXME we don't support generic associated types yet | 547 | parameters: Vec::new(), // FIXME we don't support generic associated types yet |
659 | }; | 548 | }; |
660 | Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) | 549 | Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) |
diff --git a/crates/hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/traits/chalk/tls.rs index 75b16172e..8892a63a9 100644 --- a/crates/hir_ty/src/traits/chalk/tls.rs +++ b/crates/hir_ty/src/traits/chalk/tls.rs | |||
@@ -4,8 +4,8 @@ use std::fmt; | |||
4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; | 4 | use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; |
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use super::{from_chalk, Interner, TypeAliasAsAssocType}; | 7 | use super::{from_chalk, Interner}; |
8 | use crate::{db::HirDatabase, CallableDefId}; | 8 | use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId}; |
9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; | 9 | use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; |
10 | 10 | ||
11 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; | 11 | pub(crate) use unsafe_tls::{set_current_program, with_current_program}; |
@@ -41,7 +41,7 @@ impl DebugContext<'_> { | |||
41 | id: super::AssocTypeId, | 41 | id: super::AssocTypeId, |
42 | fmt: &mut fmt::Formatter<'_>, | 42 | fmt: &mut fmt::Formatter<'_>, |
43 | ) -> Result<(), fmt::Error> { | 43 | ) -> Result<(), fmt::Error> { |
44 | let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(self.0, id).0; | 44 | let type_alias: TypeAliasId = from_assoc_type_id(id); |
45 | let type_alias_data = self.0.type_alias_data(type_alias); | 45 | let type_alias_data = self.0.type_alias_data(type_alias); |
46 | let trait_ = match type_alias.lookup(self.0.upcast()).container { | 46 | let trait_ = match type_alias.lookup(self.0.upcast()).container { |
47 | AssocContainerId::TraitId(t) => t, | 47 | AssocContainerId::TraitId(t) => t, |
@@ -75,8 +75,7 @@ impl DebugContext<'_> { | |||
75 | projection_ty: &chalk_ir::ProjectionTy<Interner>, | 75 | projection_ty: &chalk_ir::ProjectionTy<Interner>, |
76 | fmt: &mut fmt::Formatter<'_>, | 76 | fmt: &mut fmt::Formatter<'_>, |
77 | ) -> Result<(), fmt::Error> { | 77 | ) -> Result<(), fmt::Error> { |
78 | let type_alias: TypeAliasId = | 78 | let type_alias = from_assoc_type_id(projection_ty.associated_ty_id); |
79 | from_chalk::<TypeAliasAsAssocType, _>(self.0, projection_ty.associated_ty_id).0; | ||
80 | let type_alias_data = self.0.type_alias_data(type_alias); | 79 | let type_alias_data = self.0.type_alias_data(type_alias); |
81 | let trait_ = match type_alias.lookup(self.0.upcast()).container { | 80 | let trait_ = match type_alias.lookup(self.0.upcast()).container { |
82 | AssocContainerId::TraitId(t) => t, | 81 | AssocContainerId::TraitId(t) => t, |