Skip to content

Commit 7d47af5

Browse files
committed
rename WellKnownConstrants and add comments
1 parent 4eaa7d0 commit 7d47af5

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

chalk-solve/src/wf.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ where
197197
let interner = gb.interner();
198198

199199
// struct is well-formed in terms of Sized
200-
let sized_constraint_goal =
201-
WellKnownConstraints::struct_sized_constraint(gb.db(), fields);
200+
let sized_constraint_goal = WfWellKnownGoals::struct_sized_constraint(gb.db(), fields);
202201

203202
// (FromEnv(T: Eq) => ...)
204203
gb.implies(
@@ -292,7 +291,7 @@ fn impl_header_wf_goal<I: Interner>(
292291
let well_formed_goal = gb.forall(&impl_fields, (), |gb, _, (trait_ref, where_clauses), ()| {
293292
let interner = gb.interner();
294293

295-
let trait_constraint_goal = WellKnownConstraints::inside_impl(gb.db(), &trait_ref);
294+
let trait_constraint_goal = WfWellKnownGoals::inside_impl(gb.db(), &trait_ref);
296295

297296
// if (WC && input types are well formed) { ... }
298297
gb.implies(
@@ -326,7 +325,7 @@ fn impl_header_wf_goal<I: Interner>(
326325
Some(
327326
gb.all(
328327
iter::once(well_formed_goal)
329-
.chain(WellKnownConstraints::outside_impl(db, &impl_datum).into_iter()),
328+
.chain(WfWellKnownGoals::outside_impl(db, &impl_datum).into_iter()),
330329
),
331330
)
332331
}
@@ -492,9 +491,13 @@ fn compute_assoc_ty_goal<I: Interner>(
492491
))
493492
}
494493

495-
struct WellKnownConstraints {}
494+
/// Defines methods to compute well-formedness goals for well-known
495+
/// traits (e.g. a goal for all fields of struct in a Copy impl to be Copy)
496+
struct WfWellKnownGoals {}
496497

497-
impl WellKnownConstraints {
498+
impl WfWellKnownGoals {
499+
/// A convenience method to compute the goal assuming `trait_ref`
500+
/// well-formedness requirements are in the environment.
498501
pub fn inside_impl<I: Interner>(
499502
db: &dyn RustIrDatabase<I>,
500503
trait_ref: &TraitRef<I>,
@@ -507,6 +510,9 @@ impl WellKnownConstraints {
507510
}
508511
}
509512

513+
/// Computes well-formedness goals without any assumptions about the environment.
514+
/// Note that `outside_impl` does not call `inside_impl`, one needs to call both
515+
/// in order to get the full set of goals to be proven.
510516
pub fn outside_impl<I: Interner>(
511517
db: &dyn RustIrDatabase<I>,
512518
impl_datum: &ImplDatum<I>,
@@ -573,6 +579,7 @@ impl WellKnownConstraints {
573579
_ => return None,
574580
};
575581

582+
// not { Implemented(ImplSelfTy: Drop) }
576583
let neg_drop_goal =
577584
db.well_known_trait_id(WellKnownTrait::DropTrait)
578585
.map(|drop_trait_id| {
@@ -592,6 +599,7 @@ impl WellKnownConstraints {
592599
.substitute(interner, substitution)
593600
.into_iter()
594601
.map(|f| {
602+
// Implemented(FieldTy: Copy)
595603
TraitRef {
596604
trait_id: trait_ref.trait_id,
597605
substitution: Substitution::from1(interner, f),
@@ -668,16 +676,19 @@ impl WellKnownConstraints {
668676
.binders
669677
.map_ref(|v| (&v.trait_ref, &v.where_clauses));
670678

679+
// forall<ImplP1...ImplPn> { .. }
671680
let implied_by_struct_def_goal =
672681
gb.forall(&impl_fields, (), |gb, _, (trait_ref, where_clauses), ()| {
673682
let interner = gb.interner();
674683

684+
// FromEnv(ImplSelfType) => ...
675685
gb.implies(
676686
iter::once(
677687
FromEnv::Ty(trait_ref.self_type_parameter(interner))
678688
.cast::<DomainGoal<I>>(interner),
679689
),
680690
|gb| {
691+
// All(ImplWhereClauses)
681692
gb.all(
682693
where_clauses
683694
.iter()
@@ -691,6 +702,7 @@ impl WellKnownConstraints {
691702
.binders
692703
.map_ref(|b| b.trait_ref.self_type_parameter(interner));
693704

705+
// forall<StructP1..StructPN> {...}
694706
let eq_goal = gb.forall(
695707
&struct_datum.binders,
696708
(struct_name, impl_self_ty),
@@ -704,11 +716,14 @@ impl WellKnownConstraints {
704716
.cast(interner)
705717
.intern(interner);
706718

719+
// exists<ImplP1...ImplPn> { .. }
707720
gb.exists(
708721
&impl_self_ty,
709722
def_struct,
710723
|gb, _, impl_struct, def_struct| {
711724
let interner = gb.interner();
725+
726+
// StructName<StructP1..StructPn> = ImplSelfType
712727
GoalData::EqGoal(EqGoal {
713728
a: ParameterData::Ty(def_struct).intern(interner),
714729
b: ParameterData::Ty(impl_struct.clone()).intern(interner),

0 commit comments

Comments
 (0)