aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-05 16:13:50 +0100
committerFlorian Diebold <[email protected]>2021-04-05 18:19:18 +0100
commit69714d36e6617800f3edea174f5d6f76c985ad4c (patch)
treee74b3e3ab442e4e2e36c3985de978ebbbccf7634 /crates/hir_ty/src/traits
parent6e9798a992b30b735f14018379e0861d2ec30647 (diff)
Hide Binders internals more
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r--crates/hir_ty/src/traits/chalk.rs43
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs17
2 files changed, 32 insertions, 28 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index b7388b98c..47867f77e 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -184,10 +184,15 @@ 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 data = &datas.skip_binders().impl_traits[idx as usize];
188 let bound = OpaqueTyDatumBound { 188 let bound = OpaqueTyDatumBound {
189 bounds: make_binders( 189 bounds: make_binders(
190 data.bounds.value.iter().cloned().map(|b| b.to_chalk(self.db)).collect(), 190 data.bounds
191 .skip_binders()
192 .iter()
193 .cloned()
194 .map(|b| b.to_chalk(self.db))
195 .collect(),
191 1, 196 1,
192 ), 197 ),
193 where_clauses: make_binders(vec![], 0), 198 where_clauses: make_binders(vec![], 0),
@@ -535,7 +540,8 @@ fn impl_def_datum(
535 .impl_trait(impl_id) 540 .impl_trait(impl_id)
536 // ImplIds for impls where the trait ref can't be resolved should never reach Chalk 541 // ImplIds for impls where the trait ref can't be resolved should never reach Chalk
537 .expect("invalid impl passed to Chalk") 542 .expect("invalid impl passed to Chalk")
538 .value; 543 .into_value_and_skipped_binders()
544 .0;
539 let impl_data = db.impl_data(impl_id); 545 let impl_data = db.impl_data(impl_id);
540 546
541 let generic_params = generics(db.upcast(), impl_id.into()); 547 let generic_params = generics(db.upcast(), impl_id.into());
@@ -605,18 +611,22 @@ fn type_alias_associated_ty_value(
605 _ => panic!("assoc ty value should be in impl"), 611 _ => panic!("assoc ty value should be in impl"),
606 }; 612 };
607 613
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 614 let trait_ref = db
615 .impl_trait(impl_id)
616 .expect("assoc ty value should not exist")
617 .into_value_and_skipped_binders()
618 .0; // we don't return any assoc ty values if the impl'd trait can't be resolved
609 619
610 let assoc_ty = db 620 let assoc_ty = db
611 .trait_data(trait_ref.hir_trait_id()) 621 .trait_data(trait_ref.hir_trait_id())
612 .associated_type_by_name(&type_alias_data.name) 622 .associated_type_by_name(&type_alias_data.name)
613 .expect("assoc ty value should not exist"); // validated when building the impl data as well 623 .expect("assoc ty value should not exist"); // validated when building the impl data as well
614 let ty = db.ty(type_alias.into()); 624 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) }; 625 let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) };
616 let value = rust_ir::AssociatedTyValue { 626 let value = rust_ir::AssociatedTyValue {
617 impl_id: impl_id.to_chalk(db), 627 impl_id: impl_id.to_chalk(db),
618 associated_ty_id: to_assoc_type_id(assoc_ty), 628 associated_ty_id: to_assoc_type_id(assoc_ty),
619 value: make_binders(value_bound, ty.num_binders), 629 value: make_binders(value_bound, binders),
620 }; 630 };
621 Arc::new(value) 631 Arc::new(value)
622} 632}
@@ -628,20 +638,15 @@ pub(crate) fn fn_def_datum_query(
628) -> Arc<FnDefDatum> { 638) -> Arc<FnDefDatum> {
629 let callable_def: CallableDefId = from_chalk(db, fn_def_id); 639 let callable_def: CallableDefId = from_chalk(db, fn_def_id);
630 let generic_params = generics(db.upcast(), callable_def.into()); 640 let generic_params = generics(db.upcast(), callable_def.into());
631 let sig = db.callable_item_signature(callable_def); 641 let (sig, binders) = db.callable_item_signature(callable_def).into_value_and_skipped_binders();
632 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); 642 let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST);
633 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); 643 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars);
634 let bound = rust_ir::FnDefDatumBound { 644 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 645 // 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( 646 inputs_and_output: make_binders(
637 rust_ir::FnDefInputsAndOutputDatum { 647 rust_ir::FnDefInputsAndOutputDatum {
638 argument_types: sig 648 argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(),
639 .value 649 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 } 650 }
646 .shifted_in(&Interner), 651 .shifted_in(&Interner),
647 0, 652 0,
@@ -650,12 +655,8 @@ pub(crate) fn fn_def_datum_query(
650 }; 655 };
651 let datum = FnDefDatum { 656 let datum = FnDefDatum {
652 id: fn_def_id, 657 id: fn_def_id,
653 sig: chalk_ir::FnSig { 658 sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: sig.is_varargs },
654 abi: (), 659 binders: make_binders(bound, binders),
655 safety: chalk_ir::Safety::Safe,
656 variadic: sig.value.is_varargs,
657 },
658 binders: make_binders(bound, sig.num_binders),
659 }; 660 };
660 Arc::new(datum) 661 Arc::new(datum)
661} 662}
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 67e88ebf4..72458f367 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -93,12 +93,13 @@ impl ToChalk for Ty {
93 TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), 93 TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner),
94 TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), 94 TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"),
95 TyKind::Dyn(dyn_ty) => { 95 TyKind::Dyn(dyn_ty) => {
96 let (bounds, binders) = dyn_ty.bounds.into_value_and_skipped_binders();
96 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( 97 let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter(
97 &Interner, 98 &Interner,
98 dyn_ty.bounds.value.interned().iter().cloned().map(|p| p.to_chalk(db)), 99 bounds.interned().iter().cloned().map(|p| p.to_chalk(db)),
99 ); 100 );
100 let bounded_ty = chalk_ir::DynTy { 101 let bounded_ty = chalk_ir::DynTy {
101 bounds: make_binders(where_clauses, 1), 102 bounds: make_binders(where_clauses, binders),
102 lifetime: LifetimeData::Static.intern(&Interner), 103 lifetime: LifetimeData::Static.intern(&Interner),
103 }; 104 };
104 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) 105 chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner)
@@ -486,13 +487,14 @@ where
486 type Chalk = chalk_ir::Binders<T::Chalk>; 487 type Chalk = chalk_ir::Binders<T::Chalk>;
487 488
488 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T::Chalk> { 489 fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T::Chalk> {
490 let (value, binders) = self.into_value_and_skipped_binders();
489 chalk_ir::Binders::new( 491 chalk_ir::Binders::new(
490 chalk_ir::VariableKinds::from_iter( 492 chalk_ir::VariableKinds::from_iter(
491 &Interner, 493 &Interner,
492 std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)) 494 std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
493 .take(self.num_binders), 495 .take(binders),
494 ), 496 ),
495 self.value.to_chalk(db), 497 value.to_chalk(db),
496 ) 498 )
497 } 499 }
498 500
@@ -537,7 +539,8 @@ pub(super) fn generic_predicate_to_inline_bound(
537 // An InlineBound is like a GenericPredicate, except the self type is left out. 539 // An InlineBound is like a GenericPredicate, except the self type is left out.
538 // We don't have a special type for this, but Chalk does. 540 // We don't have a special type for this, but Chalk does.
539 let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE); 541 let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE);
540 match &pred.value { 542 let (pred, binders) = pred.as_ref().into_value_and_skipped_binders();
543 match pred {
541 WhereClause::Implemented(trait_ref) => { 544 WhereClause::Implemented(trait_ref) => {
542 if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in { 545 if trait_ref.self_type_parameter(&Interner) != &self_ty_shifted_in {
543 // we can only convert predicates back to type bounds if they 546 // we can only convert predicates back to type bounds if they
@@ -549,7 +552,7 @@ pub(super) fn generic_predicate_to_inline_bound(
549 .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) 552 .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
550 .collect(); 553 .collect();
551 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; 554 let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
552 Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), pred.num_binders)) 555 Some(make_binders(rust_ir::InlineBound::TraitBound(trait_bound), binders))
553 } 556 }
554 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { 557 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
555 if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in { 558 if projection_ty.self_type_parameter(&Interner) != &self_ty_shifted_in {
@@ -566,7 +569,7 @@ pub(super) fn generic_predicate_to_inline_bound(
566 associated_ty_id: projection_ty.associated_ty_id, 569 associated_ty_id: projection_ty.associated_ty_id,
567 parameters: Vec::new(), // FIXME we don't support generic associated types yet 570 parameters: Vec::new(), // FIXME we don't support generic associated types yet
568 }; 571 };
569 Some(make_binders(rust_ir::InlineBound::AliasEqBound(alias_eq_bound), pred.num_binders)) 572 Some(make_binders(rust_ir::InlineBound::AliasEqBound(alias_eq_bound), binders))
570 } 573 }
571 _ => None, 574 _ => None,
572 } 575 }