aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r--crates/hir_ty/src/traits/chalk.rs89
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs43
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs212
3 files changed, 164 insertions, 180 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 011bef6f6..090f6492b 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3 3
4use log::debug; 4use log::debug;
5 5
6use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg}; 6use chalk_ir::{fold::shift::Shift, CanonicalVarKinds};
7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; 7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
8 8
9use base_db::{salsa::InternKey, CrateId}; 9use base_db::{salsa::InternKey, CrateId};
@@ -22,7 +22,7 @@ use crate::{
22 to_assoc_type_id, to_chalk_trait_id, 22 to_assoc_type_id, to_chalk_trait_id,
23 utils::generics, 23 utils::generics,
24 AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, 24 AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution,
25 TraitRef, Ty, TyKind, WhereClause, 25 TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause,
26}; 26};
27use mapping::{ 27use mapping::{
28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, 28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
@@ -80,7 +80,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
80 fn impls_for_trait( 80 fn impls_for_trait(
81 &self, 81 &self,
82 trait_id: TraitId, 82 trait_id: TraitId,
83 parameters: &[GenericArg<Interner>], 83 parameters: &[chalk_ir::GenericArg<Interner>],
84 binders: &CanonicalVarKinds<Interner>, 84 binders: &CanonicalVarKinds<Interner>,
85 ) -> Vec<ImplId> { 85 ) -> Vec<ImplId> {
86 debug!("impls_for_trait {:?}", trait_id); 86 debug!("impls_for_trait {:?}", trait_id);
@@ -92,7 +92,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
92 ty: &Ty, 92 ty: &Ty,
93 binders: &CanonicalVarKinds<Interner>, 93 binders: &CanonicalVarKinds<Interner>,
94 ) -> Option<chalk_ir::TyVariableKind> { 94 ) -> Option<chalk_ir::TyVariableKind> {
95 if let TyKind::BoundVar(bv) = ty.interned(&Interner) { 95 if let TyKind::BoundVar(bv) = ty.kind(&Interner) {
96 let binders = binders.as_slice(&Interner); 96 let binders = binders.as_slice(&Interner);
97 if bv.debruijn == DebruijnIndex::INNERMOST { 97 if bv.debruijn == DebruijnIndex::INNERMOST {
98 if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { 98 if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind {
@@ -184,16 +184,21 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
184 .db 184 .db
185 .return_type_impl_traits(func) 185 .return_type_impl_traits(func)
186 .expect("impl trait id without impl traits"); 186 .expect("impl trait id without impl traits");
187 let data = &datas.value.impl_traits[idx as usize]; 187 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders();
188 let data = &datas.impl_traits[idx as usize];
188 let bound = OpaqueTyDatumBound { 189 let bound = OpaqueTyDatumBound {
189 bounds: make_binders( 190 bounds: make_binders(
190 data.bounds.value.iter().cloned().map(|b| b.to_chalk(self.db)).collect(), 191 data.bounds
192 .skip_binders()
193 .iter()
194 .cloned()
195 .map(|b| b.to_chalk(self.db))
196 .collect(),
191 1, 197 1,
192 ), 198 ),
193 where_clauses: make_binders(vec![], 0), 199 where_clauses: make_binders(vec![], 0),
194 }; 200 };
195 let num_vars = datas.num_binders; 201 chalk_ir::Binders::new(binders, bound)
196 make_binders(bound, num_vars)
197 } 202 }
198 crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => { 203 crate::ImplTraitId::AsyncBlockTypeImplTrait(..) => {
199 if let Some((future_trait, future_output)) = self 204 if let Some((future_trait, future_output)) = self
@@ -215,7 +220,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
215 let impl_bound = WhereClause::Implemented(TraitRef { 220 let impl_bound = WhereClause::Implemented(TraitRef {
216 trait_id: to_chalk_trait_id(future_trait), 221 trait_id: to_chalk_trait_id(future_trait),
217 // Self type as the first parameter. 222 // Self type as the first parameter.
218 substitution: Substitution::single( 223 substitution: Substitution::from1(
224 &Interner,
219 TyKind::BoundVar(BoundVar { 225 TyKind::BoundVar(BoundVar {
220 debruijn: DebruijnIndex::INNERMOST, 226 debruijn: DebruijnIndex::INNERMOST,
221 index: 0, 227 index: 0,
@@ -227,7 +233,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
227 alias: AliasTy::Projection(ProjectionTy { 233 alias: AliasTy::Projection(ProjectionTy {
228 associated_ty_id: to_assoc_type_id(future_output), 234 associated_ty_id: to_assoc_type_id(future_output),
229 // Self type as the first parameter. 235 // Self type as the first parameter.
230 substitution: Substitution::single( 236 substitution: Substitution::from1(
237 &Interner,
231 TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) 238 TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
232 .intern(&Interner), 239 .intern(&Interner),
233 ), 240 ),
@@ -239,8 +246,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
239 let bound = OpaqueTyDatumBound { 246 let bound = OpaqueTyDatumBound {
240 bounds: make_binders( 247 bounds: make_binders(
241 vec![ 248 vec![
242 wrap_in_empty_binders(impl_bound).to_chalk(self.db), 249 crate::wrap_empty_binders(impl_bound).to_chalk(self.db),
243 wrap_in_empty_binders(proj_bound).to_chalk(self.db), 250 crate::wrap_empty_binders(proj_bound).to_chalk(self.db),
244 ], 251 ],
245 1, 252 1,
246 ), 253 ),
@@ -265,7 +272,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
265 272
266 fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> { 273 fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> {
267 // FIXME: actually provide the hidden type; it is relevant for auto traits 274 // FIXME: actually provide the hidden type; it is relevant for auto traits
268 TyKind::Unknown.intern(&Interner).to_chalk(self.db) 275 TyKind::Error.intern(&Interner).to_chalk(self.db)
269 } 276 }
270 277
271 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool { 278 fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool {
@@ -300,7 +307,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
300 _closure_id: chalk_ir::ClosureId<Interner>, 307 _closure_id: chalk_ir::ClosureId<Interner>,
301 _substs: &chalk_ir::Substitution<Interner>, 308 _substs: &chalk_ir::Substitution<Interner>,
302 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> { 309 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
303 let ty = Ty::unit().to_chalk(self.db); 310 let ty = TyBuilder::unit().to_chalk(self.db);
304 make_binders(ty, 0) 311 make_binders(ty, 0)
305 } 312 }
306 fn closure_fn_substitution( 313 fn closure_fn_substitution(
@@ -308,7 +315,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
308 _closure_id: chalk_ir::ClosureId<Interner>, 315 _closure_id: chalk_ir::ClosureId<Interner>,
309 _substs: &chalk_ir::Substitution<Interner>, 316 _substs: &chalk_ir::Substitution<Interner>,
310 ) -> chalk_ir::Substitution<Interner> { 317 ) -> chalk_ir::Substitution<Interner> {
311 Substitution::empty().to_chalk(self.db) 318 Substitution::empty(&Interner).to_chalk(self.db)
312 } 319 }
313 320
314 fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { 321 fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String {
@@ -387,7 +394,7 @@ pub(crate) fn associated_ty_data_query(
387 // Lower bounds -- we could/should maybe move this to a separate query in `lower` 394 // Lower bounds -- we could/should maybe move this to a separate query in `lower`
388 let type_alias_data = db.type_alias_data(type_alias); 395 let type_alias_data = db.type_alias_data(type_alias);
389 let generic_params = generics(db.upcast(), type_alias.into()); 396 let generic_params = generics(db.upcast(), type_alias.into());
390 let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 397 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
391 let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); 398 let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
392 let ctx = crate::TyLoweringContext::new(db, &resolver) 399 let ctx = crate::TyLoweringContext::new(db, &resolver)
393 .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); 400 .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable);
@@ -421,7 +428,7 @@ pub(crate) fn trait_datum_query(
421 let trait_data = db.trait_data(trait_); 428 let trait_data = db.trait_data(trait_);
422 debug!("trait {:?} = {:?}", trait_id, trait_data.name); 429 debug!("trait {:?} = {:?}", trait_id, trait_data.name);
423 let generic_params = generics(db.upcast(), trait_.into()); 430 let generic_params = generics(db.upcast(), trait_.into());
424 let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 431 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
425 let flags = rust_ir::TraitFlags { 432 let flags = rust_ir::TraitFlags {
426 auto: trait_data.is_auto, 433 auto: trait_data.is_auto,
427 upstream: trait_.lookup(db.upcast()).container.krate() != krate, 434 upstream: trait_.lookup(db.upcast()).container.krate() != krate,
@@ -439,7 +446,7 @@ pub(crate) fn trait_datum_query(
439 lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); 446 lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));
440 let trait_datum = TraitDatum { 447 let trait_datum = TraitDatum {
441 id: trait_id, 448 id: trait_id,
442 binders: make_binders(trait_datum_bound, bound_vars.len()), 449 binders: make_binders(trait_datum_bound, bound_vars.len(&Interner)),
443 flags, 450 flags,
444 associated_ty_ids, 451 associated_ty_ids,
445 well_known, 452 well_known,
@@ -490,7 +497,7 @@ pub(crate) fn struct_datum_query(
490 let upstream = adt_id.module(db.upcast()).krate() != krate; 497 let upstream = adt_id.module(db.upcast()).krate() != krate;
491 let where_clauses = { 498 let where_clauses = {
492 let generic_params = generics(db.upcast(), adt_id.into()); 499 let generic_params = generics(db.upcast(), adt_id.into());
493 let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 500 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
494 convert_where_clauses(db, adt_id.into(), &bound_vars) 501 convert_where_clauses(db, adt_id.into(), &bound_vars)
495 }; 502 };
496 let flags = rust_ir::AdtFlags { 503 let flags = rust_ir::AdtFlags {
@@ -535,11 +542,12 @@ fn impl_def_datum(
535 .impl_trait(impl_id) 542 .impl_trait(impl_id)
536 // ImplIds for impls where the trait ref can't be resolved should never reach Chalk 543 // ImplIds for impls where the trait ref can't be resolved should never reach Chalk
537 .expect("invalid impl passed to Chalk") 544 .expect("invalid impl passed to Chalk")
538 .value; 545 .into_value_and_skipped_binders()
546 .0;
539 let impl_data = db.impl_data(impl_id); 547 let impl_data = db.impl_data(impl_id);
540 548
541 let generic_params = generics(db.upcast(), impl_id.into()); 549 let generic_params = generics(db.upcast(), impl_id.into());
542 let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 550 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
543 let trait_ = trait_ref.hir_trait_id(); 551 let trait_ = trait_ref.hir_trait_id();
544 let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate { 552 let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate {
545 rust_ir::ImplType::Local 553 rust_ir::ImplType::Local
@@ -577,7 +585,7 @@ fn impl_def_datum(
577 .collect(); 585 .collect();
578 debug!("impl_datum: {:?}", impl_datum_bound); 586 debug!("impl_datum: {:?}", impl_datum_bound);
579 let impl_datum = ImplDatum { 587 let impl_datum = ImplDatum {
580 binders: make_binders(impl_datum_bound, bound_vars.len()), 588 binders: make_binders(impl_datum_bound, bound_vars.len(&Interner)),
581 impl_type, 589 impl_type,
582 polarity, 590 polarity,
583 associated_ty_value_ids, 591 associated_ty_value_ids,
@@ -605,18 +613,22 @@ fn type_alias_associated_ty_value(
605 _ => panic!("assoc ty value should be in impl"), 613 _ => panic!("assoc ty value should be in impl"),
606 }; 614 };
607 615
608 let trait_ref = db.impl_trait(impl_id).expect("assoc ty value should not exist").value; // we don't return any assoc ty values if the impl'd trait can't be resolved 616 let trait_ref = db
617 .impl_trait(impl_id)
618 .expect("assoc ty value should not exist")
619 .into_value_and_skipped_binders()
620 .0; // we don't return any assoc ty values if the impl'd trait can't be resolved
609 621
610 let assoc_ty = db 622 let assoc_ty = db
611 .trait_data(trait_ref.hir_trait_id()) 623 .trait_data(trait_ref.hir_trait_id())
612 .associated_type_by_name(&type_alias_data.name) 624 .associated_type_by_name(&type_alias_data.name)
613 .expect("assoc ty value should not exist"); // validated when building the impl data as well 625 .expect("assoc ty value should not exist"); // validated when building the impl data as well
614 let ty = db.ty(type_alias.into()); 626 let (ty, binders) = db.ty(type_alias.into()).into_value_and_skipped_binders();
615 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; 627 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) };
616 let value = rust_ir::AssociatedTyValue { 628 let value = rust_ir::AssociatedTyValue {
617 impl_id: impl_id.to_chalk(db), 629 impl_id: impl_id.to_chalk(db),
618 associated_ty_id: to_assoc_type_id(assoc_ty), 630 associated_ty_id: to_assoc_type_id(assoc_ty),
619 value: make_binders(value_bound, ty.num_binders), 631 value: chalk_ir::Binders::new(binders, value_bound),
620 }; 632 };
621 Arc::new(value) 633 Arc::new(value)
622} 634}
@@ -628,20 +640,15 @@ pub(crate) fn fn_def_datum_query(
628) -> Arc<FnDefDatum> { 640) -> Arc<FnDefDatum> {
629 let callable_def: CallableDefId = from_chalk(db, fn_def_id); 641 let callable_def: CallableDefId = from_chalk(db, fn_def_id);
630 let generic_params = generics(db.upcast(), callable_def.into()); 642 let generic_params = generics(db.upcast(), callable_def.into());
631 let sig = db.callable_item_signature(callable_def); 643 let (sig, binders) = db.callable_item_signature(callable_def).into_value_and_skipped_binders();
632 let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 644 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
633 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); 645 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars);
634 let bound = rust_ir::FnDefDatumBound { 646 let bound = rust_ir::FnDefDatumBound {
635 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway 647 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway
636 inputs_and_output: make_binders( 648 inputs_and_output: make_binders(
637 rust_ir::FnDefInputsAndOutputDatum { 649 rust_ir::FnDefInputsAndOutputDatum {
638 argument_types: sig 650 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(),
639 .value 651 return_type: sig.ret().clone().to_chalk(db),
640 .params()
641 .iter()
642 .map(|ty| ty.clone().to_chalk(db))
643 .collect(),
644 return_type: sig.value.ret().clone().to_chalk(db),
645 } 652 }
646 .shifted_in(&Interner), 653 .shifted_in(&Interner),
647 0, 654 0,
@@ -650,12 +657,8 @@ pub(crate) fn fn_def_datum_query(
650 }; 657 };
651 let datum = FnDefDatum { 658 let datum = FnDefDatum {
652 id: fn_def_id, 659 id: fn_def_id,
653 sig: chalk_ir::FnSig { 660 sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: sig.is_varargs },
654 abi: (), 661 binders: chalk_ir::Binders::new(binders, bound),
655 safety: chalk_ir::Safety::Safe,
656 variadic: sig.value.is_varargs,
657 },
658 binders: make_binders(bound, sig.num_binders),
659 }; 662 };
660 Arc::new(datum) 663 Arc::new(datum)
661} 664}
@@ -720,7 +723,3 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
720 chalk_ir::ClosureId(id.as_intern_id()) 723 chalk_ir::ClosureId(id.as_intern_id())
721 } 724 }
722} 725}
723
724fn wrap_in_empty_binders<T: crate::TypeWalk>(value: T) -> crate::Binders<T> {
725 crate::Binders::wrap_empty(value)
726}
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index 94e94a26d..bd9395b7e 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -192,59 +192,58 @@ impl chalk_ir::interner::Interner for Interner {
192 tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) 192 tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt)))
193 } 193 }
194 194
195 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Arc<chalk_ir::TyData<Self>> { 195 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
196 let flags = kind.compute_flags(self); 196 let flags = kind.compute_flags(self);
197 Arc::new(chalk_ir::TyData { kind, flags }) 197 Arc::new(chalk_ir::TyData { kind, flags })
198 } 198 }
199 199
200 fn ty_data<'a>(&self, ty: &'a Arc<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> { 200 fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> {
201 ty 201 ty
202 } 202 }
203 203
204 fn intern_lifetime( 204 fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
205 &self,
206 lifetime: chalk_ir::LifetimeData<Self>,
207 ) -> chalk_ir::LifetimeData<Self> {
208 lifetime 205 lifetime
209 } 206 }
210 207
211 fn lifetime_data<'a>( 208 fn lifetime_data<'a>(
212 &self, 209 &self,
213 lifetime: &'a chalk_ir::LifetimeData<Self>, 210 lifetime: &'a Self::InternedLifetime,
214 ) -> &'a chalk_ir::LifetimeData<Self> { 211 ) -> &'a chalk_ir::LifetimeData<Self> {
215 lifetime 212 lifetime
216 } 213 }
217 214
218 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Arc<chalk_ir::ConstData<Self>> { 215 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
219 Arc::new(constant) 216 Arc::new(constant)
220 } 217 }
221 218
222 fn const_data<'a>( 219 fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
223 &self,
224 constant: &'a Arc<chalk_ir::ConstData<Self>>,
225 ) -> &'a chalk_ir::ConstData<Self> {
226 constant 220 constant
227 } 221 }
228 222
229 fn const_eq(&self, _ty: &Arc<chalk_ir::TyData<Self>>, _c1: &(), _c2: &()) -> bool { 223 fn const_eq(
224 &self,
225 _ty: &Self::InternedType,
226 _c1: &Self::InternedConcreteConst,
227 _c2: &Self::InternedConcreteConst,
228 ) -> bool {
230 true 229 true
231 } 230 }
232 231
233 fn intern_generic_arg( 232 fn intern_generic_arg(
234 &self, 233 &self,
235 parameter: chalk_ir::GenericArgData<Self>, 234 parameter: chalk_ir::GenericArgData<Self>,
236 ) -> chalk_ir::GenericArgData<Self> { 235 ) -> Self::InternedGenericArg {
237 parameter 236 parameter
238 } 237 }
239 238
240 fn generic_arg_data<'a>( 239 fn generic_arg_data<'a>(
241 &self, 240 &self,
242 parameter: &'a chalk_ir::GenericArgData<Self>, 241 parameter: &'a Self::InternedGenericArg,
243 ) -> &'a chalk_ir::GenericArgData<Self> { 242 ) -> &'a chalk_ir::GenericArgData<Self> {
244 parameter 243 parameter
245 } 244 }
246 245
247 fn intern_goal(&self, goal: GoalData<Self>) -> Arc<GoalData<Self>> { 246 fn intern_goal(&self, goal: GoalData<Self>) -> Self::InternedGoal {
248 Arc::new(goal) 247 Arc::new(goal)
249 } 248 }
250 249
@@ -255,11 +254,11 @@ impl chalk_ir::interner::Interner for Interner {
255 data.into_iter().collect() 254 data.into_iter().collect()
256 } 255 }
257 256
258 fn goal_data<'a>(&self, goal: &'a Arc<GoalData<Self>>) -> &'a GoalData<Self> { 257 fn goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self> {
259 goal 258 goal
260 } 259 }
261 260
262 fn goals_data<'a>(&self, goals: &'a Vec<Goal<Interner>>) -> &'a [Goal<Interner>] { 261 fn goals_data<'a>(&self, goals: &'a Self::InternedGoals) -> &'a [Goal<Interner>] {
263 goals 262 goals
264 } 263 }
265 264
@@ -280,13 +279,13 @@ impl chalk_ir::interner::Interner for Interner {
280 fn intern_program_clause( 279 fn intern_program_clause(
281 &self, 280 &self,
282 data: chalk_ir::ProgramClauseData<Self>, 281 data: chalk_ir::ProgramClauseData<Self>,
283 ) -> Arc<chalk_ir::ProgramClauseData<Self>> { 282 ) -> Self::InternedProgramClause {
284 Arc::new(data) 283 Arc::new(data)
285 } 284 }
286 285
287 fn program_clause_data<'a>( 286 fn program_clause_data<'a>(
288 &self, 287 &self,
289 clause: &'a Arc<chalk_ir::ProgramClauseData<Self>>, 288 clause: &'a Self::InternedProgramClause,
290 ) -> &'a chalk_ir::ProgramClauseData<Self> { 289 ) -> &'a chalk_ir::ProgramClauseData<Self> {
291 clause 290 clause
292 } 291 }
@@ -294,13 +293,13 @@ impl chalk_ir::interner::Interner for Interner {
294 fn intern_program_clauses<E>( 293 fn intern_program_clauses<E>(
295 &self, 294 &self,
296 data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>, 295 data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
297 ) -> Result<Arc<[chalk_ir::ProgramClause<Self>]>, E> { 296 ) -> Result<Self::InternedProgramClauses, E> {
298 data.into_iter().collect() 297 data.into_iter().collect()
299 } 298 }
300 299
301 fn program_clauses_data<'a>( 300 fn program_clauses_data<'a>(
302 &self, 301 &self,
303 clauses: &'a Arc<[chalk_ir::ProgramClause<Self>]>, 302 clauses: &'a Self::InternedProgramClauses,
304 ) -> &'a [chalk_ir::ProgramClause<Self>] { 303 ) -> &'a [chalk_ir::ProgramClause<Self>] {
305 &clauses 304 &clauses
306 } 305 }
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index aef6b8a15..701359e6f 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -3,18 +3,16 @@
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
6use chalk_ir::{cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData}; 6use chalk_ir::{cast::Cast, interner::HasInterner};
7use chalk_solve::rust_ir; 7use chalk_solve::rust_ir;
8 8
9use base_db::salsa::InternKey; 9use base_db::salsa::InternKey;
10use hir_def::{GenericDefId, TypeAliasId}; 10use hir_def::{GenericDefId, TypeAliasId};
11 11
12use crate::{ 12use crate::{
13 db::HirDatabase, 13 db::HirDatabase, static_lifetime, AliasTy, CallableDefId, Canonical, ConstrainedSubst,
14 primitive::UintTy, 14 DomainGoal, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy, ProjectionTyExt,
15 traits::{Canonical, DomainGoal}, 15 QuantifiedWhereClause, Substitution, TraitRef, Ty, TypeWalk, WhereClause,
16 AliasTy, CallableDefId, FnPointer, InEnvironment, OpaqueTy, ProjectionTy,
17 QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause,
18}; 16};
19 17
20use super::interner::*; 18use super::interner::*;
@@ -24,16 +22,16 @@ impl ToChalk for Ty {
24 type Chalk = chalk_ir::Ty<Interner>; 22 type Chalk = chalk_ir::Ty<Interner>;
25 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { 23 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
26 match self.into_inner() { 24 match self.into_inner() {
27 TyKind::Ref(m, ty) => ref_to_chalk(db, m, ty), 25 TyKind::Ref(m, lt, ty) => {
28 TyKind::Array(ty) => array_to_chalk(db, ty), 26 chalk_ir::TyKind::Ref(m, lt, ty.to_chalk(db)).intern(&Interner)
29 TyKind::Function(FnPointer { sig, substs, .. }) => { 27 }
30 let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); 28 TyKind::Array(ty, size) => {
31 chalk_ir::TyKind::Function(chalk_ir::FnPointer { 29 chalk_ir::TyKind::Array(ty.to_chalk(db), size).intern(&Interner)
32 num_binders: 0, 30 }
33 sig, 31 TyKind::Function(FnPointer { sig, substitution: substs, num_binders }) => {
34 substitution, 32 let substitution = chalk_ir::FnSubst(substs.0.to_chalk(db));
35 }) 33 chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders, sig, substitution })
36 .intern(&Interner) 34 .intern(&Interner)
37 } 35 }
38 TyKind::AssociatedType(assoc_type_id, substs) => { 36 TyKind::AssociatedType(assoc_type_id, substs) => {
39 let substitution = substs.to_chalk(db); 37 let substitution = substs.to_chalk(db);
@@ -45,7 +43,7 @@ impl ToChalk for Ty {
45 chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner) 43 chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
46 } 44 }
47 45
48 TyKind::ForeignType(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner), 46 TyKind::Foreign(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner),
49 47
50 TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner), 48 TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner),
51 49
@@ -75,56 +73,41 @@ impl ToChalk for Ty {
75 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) 73 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner)
76 } 74 }
77 TyKind::Alias(AliasTy::Projection(proj_ty)) => { 75 TyKind::Alias(AliasTy::Projection(proj_ty)) => {
78 let associated_ty_id = proj_ty.associated_ty_id; 76 chalk_ir::AliasTy::Projection(proj_ty.to_chalk(db))
79 let substitution = proj_ty.substitution.to_chalk(db);
80 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
81 associated_ty_id,
82 substitution,
83 })
84 .cast(&Interner)
85 .intern(&Interner)
86 }
87 TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
88 let opaque_ty_id = opaque_ty.opaque_ty_id;
89 let substitution = opaque_ty.substitution.to_chalk(db);
90 chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id, substitution })
91 .cast(&Interner) 77 .cast(&Interner)
92 .intern(&Interner) 78 .intern(&Interner)
93 } 79 }
80 TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
81 chalk_ir::AliasTy::Opaque(opaque_ty.to_chalk(db)).cast(&Interner).intern(&Interner)
82 }
94 TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner), 83 TyKind::Placeholder(idx) => idx.to_ty::<Interner>(&Interner),
95 TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), 84 TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner),
96 TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), 85 TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"),
97 TyKind::Dyn(dyn_ty) => { 86 TyKind::Dyn(dyn_ty) => {
87 let (bounds, binders) = dyn_ty.bounds.into_value_and_skipped_binders();
98 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( 88 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter(
99 &Interner, 89 &Interner,
100 dyn_ty.bounds.value.interned().iter().cloned().map(|p| p.to_chalk(db)), 90 bounds.interned().iter().cloned().map(|p| p.to_chalk(db)),
101 ); 91 );
102 let bounded_ty = chalk_ir::DynTy { 92 let bounded_ty = chalk_ir::DynTy {
103 bounds: make_binders(where_clauses, 1), 93 bounds: chalk_ir::Binders::new(binders, where_clauses),
104 lifetime: LifetimeData::Static.intern(&Interner), 94 lifetime: dyn_ty.lifetime,
105 }; 95 };
106 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) 96 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
107 } 97 }
108 TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner), 98 TyKind::Error => chalk_ir::TyKind::Error.intern(&Interner),
109 } 99 }
110 } 100 }
111 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { 101 fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
112 match chalk.data(&Interner).kind.clone() { 102 match chalk.data(&Interner).kind.clone() {
113 chalk_ir::TyKind::Error => TyKind::Unknown, 103 chalk_ir::TyKind::Error => TyKind::Error,
114 chalk_ir::TyKind::Array(ty, _size) => TyKind::Array(from_chalk(db, ty)), 104 chalk_ir::TyKind::Array(ty, size) => TyKind::Array(from_chalk(db, ty), size),
115 chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx), 105 chalk_ir::TyKind::Placeholder(idx) => TyKind::Placeholder(idx),
116 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { 106 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
117 let associated_ty = proj.associated_ty_id; 107 TyKind::Alias(AliasTy::Projection(from_chalk(db, proj)))
118 let parameters = from_chalk(db, proj.substitution);
119 TyKind::Alias(AliasTy::Projection(ProjectionTy {
120 associated_ty_id: associated_ty,
121 substitution: parameters,
122 }))
123 } 108 }
124 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { 109 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
125 let opaque_ty_id = opaque_ty.opaque_ty_id; 110 TyKind::Alias(AliasTy::Opaque(from_chalk(db, opaque_ty)))
126 let parameters = from_chalk(db, opaque_ty.substitution);
127 TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, substitution: parameters }))
128 } 111 }
129 chalk_ir::TyKind::Function(chalk_ir::FnPointer { 112 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
130 num_binders, 113 num_binders,
@@ -133,26 +116,25 @@ impl ToChalk for Ty {
133 .. 116 ..
134 }) => { 117 }) => {
135 assert_eq!(num_binders, 0); 118 assert_eq!(num_binders, 0);
136 let substs: Substitution = from_chalk( 119 let substs = crate::FnSubst(from_chalk(db, substitution.0));
137 db, 120 TyKind::Function(FnPointer { num_binders, sig, substitution: substs })
138 substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"),
139 );
140 TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs })
141 } 121 }
142 chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), 122 chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx),
143 chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, 123 chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Error,
144 chalk_ir::TyKind::Dyn(where_clauses) => { 124 chalk_ir::TyKind::Dyn(dyn_ty) => {
145 assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); 125 assert_eq!(dyn_ty.bounds.binders.len(&Interner), 1);
146 let bounds = where_clauses 126 let (bounds, binders) = dyn_ty.bounds.into_value_and_skipped_binders();
147 .bounds 127 let where_clauses = crate::QuantifiedWhereClauses::from_iter(
148 .skip_binders() 128 &Interner,
149 .iter(&Interner) 129 bounds.interned().iter().cloned().map(|p| from_chalk(db, p)),
150 .map(|c| from_chalk(db, c.clone())); 130 );
151 TyKind::Dyn(crate::DynTy { 131 TyKind::Dyn(crate::DynTy {
152 bounds: crate::Binders::new( 132 bounds: crate::Binders::new(binders, where_clauses),
153 1, 133 // HACK: we sometimes get lifetime variables back in solutions
154 crate::QuantifiedWhereClauses::from_iter(&Interner, bounds), 134 // from Chalk, and don't have the infrastructure to substitute
155 ), 135 // them yet. So for now we just turn them into 'static right
136 // when we get them
137 lifetime: static_lifetime(),
156 }) 138 })
157 } 139 }
158 140
@@ -172,7 +154,11 @@ impl ToChalk for Ty {
172 chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)), 154 chalk_ir::TyKind::Raw(mutability, ty) => TyKind::Raw(mutability, from_chalk(db, ty)),
173 chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)), 155 chalk_ir::TyKind::Slice(ty) => TyKind::Slice(from_chalk(db, ty)),
174 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { 156 chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => {
175 TyKind::Ref(mutability, from_chalk(db, ty)) 157 // HACK: we sometimes get lifetime variables back in solutions
158 // from Chalk, and don't have the infrastructure to substitute
159 // them yet. So for now we just turn them into 'static right
160 // when we get them
161 TyKind::Ref(mutability, static_lifetime(), from_chalk(db, ty))
176 } 162 }
177 chalk_ir::TyKind::Str => TyKind::Str, 163 chalk_ir::TyKind::Str => TyKind::Str,
178 chalk_ir::TyKind::Never => TyKind::Never, 164 chalk_ir::TyKind::Never => TyKind::Never,
@@ -183,7 +169,7 @@ impl ToChalk for Ty {
183 169
184 chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)), 170 chalk_ir::TyKind::Closure(id, subst) => TyKind::Closure(id, from_chalk(db, subst)),
185 171
186 chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id), 172 chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::Foreign(foreign_def_id),
187 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME 173 chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
188 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME 174 chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
189 } 175 }
@@ -191,50 +177,40 @@ impl ToChalk for Ty {
191 } 177 }
192} 178}
193 179
194/// We currently don't model lifetimes, but Chalk does. So, we have to insert a 180impl ToChalk for GenericArg {
195/// fake lifetime here, because Chalks built-in logic may expect it to be there. 181 type Chalk = chalk_ir::GenericArg<Interner>;
196fn ref_to_chalk( 182
197 db: &dyn HirDatabase, 183 fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk {
198 mutability: chalk_ir::Mutability, 184 match self.interned() {
199 ty: Ty, 185 crate::GenericArgData::Ty(ty) => ty.clone().to_chalk(db).cast(&Interner),
200) -> chalk_ir::Ty<Interner> { 186 }
201 let arg = ty.to_chalk(db); 187 }
202 let lifetime = LifetimeData::Static.intern(&Interner);
203 chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner)
204}
205 188
206/// We currently don't model constants, but Chalk does. So, we have to insert a 189 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
207/// fake constant here, because Chalks built-in logic may expect it to be there. 190 match chalk.interned() {
208fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> { 191 chalk_ir::GenericArgData::Ty(ty) => Ty::from_chalk(db, ty.clone()).cast(&Interner),
209 let arg = ty.to_chalk(db); 192 chalk_ir::GenericArgData::Lifetime(_) => unimplemented!(),
210 let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner); 193 chalk_ir::GenericArgData::Const(_) => unimplemented!(),
211 let const_ = chalk_ir::ConstData { 194 }
212 ty: usize_ty, 195 }
213 value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }),
214 }
215 .intern(&Interner);
216 chalk_ir::TyKind::Array(arg, const_).intern(&Interner)
217} 196}
218 197
219impl ToChalk for Substitution { 198impl ToChalk for Substitution {
220 type Chalk = chalk_ir::Substitution<Interner>; 199 type Chalk = chalk_ir::Substitution<Interner>;
221 200
222 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { 201 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
223 chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) 202 chalk_ir::Substitution::from_iter(
203 &Interner,
204 self.iter(&Interner).map(|ty| ty.clone().to_chalk(db)),
205 )
224 } 206 }
225 207
226 fn from_chalk( 208 fn from_chalk(
227 db: &dyn HirDatabase, 209 db: &dyn HirDatabase,
228 parameters: chalk_ir::Substitution<Interner>, 210 parameters: chalk_ir::Substitution<Interner>,
229 ) -> Substitution { 211 ) -> Substitution {
230 let tys = parameters 212 let tys = parameters.iter(&Interner).map(|p| from_chalk(db, p.clone())).collect();
231 .iter(&Interner) 213 Substitution::intern(tys)
232 .map(|p| match p.ty(&Interner) {
233 Some(ty) => from_chalk(db, ty.clone()),
234 None => unimplemented!(),
235 })
236 .collect();
237 Substitution(tys)
238 } 214 }
239} 215}
240 216
@@ -473,19 +449,25 @@ where
473 type Chalk = chalk_ir::Binders<T::Chalk>; 449 type Chalk = chalk_ir::Binders<T::Chalk>;
474 450
475 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T::Chalk> { 451 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T::Chalk> {
476 chalk_ir::Binders::new( 452 let (value, binders) = self.into_value_and_skipped_binders();
477 chalk_ir::VariableKinds::from_iter( 453 chalk_ir::Binders::new(binders, value.to_chalk(db))
478 &Interner,
479 std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
480 .take(self.num_binders),
481 ),
482 self.value.to_chalk(db),
483 )
484 } 454 }
485 455
486 fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders<T::Chalk>) -> crate::Binders<T> { 456 fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders<T::Chalk>) -> crate::Binders<T> {
487 let (v, b) = binders.into_value_and_skipped_binders(); 457 let (v, b) = binders.into_value_and_skipped_binders();
488 crate::Binders::new(b.len(&Interner), from_chalk(db, v)) 458 crate::Binders::new(b, from_chalk(db, v))
459 }
460}
461
462impl ToChalk for crate::ConstrainedSubst {
463 type Chalk = chalk_ir::ConstrainedSubst<Interner>;
464
465 fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk {
466 unimplemented!()
467 }
468
469 fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self {
470 ConstrainedSubst { subst: from_chalk(db, chalk.subst) }
489 } 471 }
490} 472}
491 473
@@ -511,7 +493,7 @@ pub(super) fn convert_where_clauses(
511 let generic_predicates = db.generic_predicates(def); 493 let generic_predicates = db.generic_predicates(def);
512 let mut result = Vec::with_capacity(generic_predicates.len()); 494 let mut result = Vec::with_capacity(generic_predicates.len());
513 for pred in generic_predicates.iter() { 495 for pred in generic_predicates.iter() {
514 result.push(pred.clone().subst(substs).to_chalk(db)); 496 result.push(pred.clone().substitute(&Interner, substs).to_chalk(db));
515 } 497 }
516 result 498 result
517} 499}
@@ -523,27 +505,28 @@ pub(super) fn generic_predicate_to_inline_bound(
523) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> { 505) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> {
524 // An InlineBound is like a GenericPredicate, except the self type is left out. 506 // An InlineBound is like a GenericPredicate, except the self type is left out.
525 // We don't have a special type for this, but Chalk does. 507 // We don't have a special type for this, but Chalk does.
526 let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE); 508 let self_ty_shifted_in = self_ty.clone().shifted_in_from(DebruijnIndex::ONE);
527 match &pred.value { 509 let (pred, binders) = pred.as_ref().into_value_and_skipped_binders();
510 match pred {
528 WhereClause::Implemented(trait_ref) => { 511 WhereClause::Implemented(trait_ref) => {
529 if trait_ref.self_type_parameter() != &self_ty_shifted_in { 512 if trait_ref.self_type_parameter(&Interner) != self_ty_shifted_in {
530 // we can only convert predicates back to type bounds if they 513 // we can only convert predicates back to type bounds if they
531 // have the expected self type 514 // have the expected self type
532 return None; 515 return None;
533 } 516 }
534 let args_no_self = trait_ref.substitution[1..] 517 let args_no_self = trait_ref.substitution.interned()[1..]
535 .iter() 518 .iter()
536 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 519 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
537 .collect(); 520 .collect();
538 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; 521 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
539 Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders)) 522 Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
540 } 523 }
541 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { 524 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
542 if projection_ty.self_type_parameter() != &self_ty_shifted_in { 525 if projection_ty.self_type_parameter(&Interner) != self_ty_shifted_in {
543 return None; 526 return None;
544 } 527 }
545 let trait_ = projection_ty.trait_(db); 528 let trait_ = projection_ty.trait_(db);
546 let args_no_self = projection_ty.substitution[1..] 529 let args_no_self = projection_ty.substitution.interned()[1..]
547 .iter() 530 .iter()
548 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 531 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
549 .collect(); 532 .collect();
@@ -553,7 +536,10 @@ pub(super) fn generic_predicate_to_inline_bound(
553 associated_ty_id: projection_ty.associated_ty_id, 536 associated_ty_id: projection_ty.associated_ty_id,
554 parameters: Vec::new(), // FIXME we don't support generic associated types yet 537 parameters: Vec::new(), // FIXME we don't support generic associated types yet
555 }; 538 };
556 Some(make_binders(rust_ir::InlineBound::AliasEqBound(alias_eq_bound), pred.num_binders)) 539 Some(chalk_ir::Binders::new(
540 binders,
541 rust_ir::InlineBound::AliasEqBound(alias_eq_bound),
542 ))
557 } 543 }
558 _ => None, 544 _ => None,
559 } 545 }