Skip to content

Commit acd499f

Browse files
committed
Add more comments
1 parent 902d344 commit acd499f

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

src/ir/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,16 +753,11 @@ impl<T> UCanonical<T> {
753753
}
754754

755755
impl UCanonical<InEnvironment<Goal>> {
756-
<<<<<<< HEAD
757-
/// A goal has coinductive semantics if it is of the form `T: AutoTrait`.
758-
crate fn is_coinductive(&self, program: &ProgramEnvironment) -> bool {
759-
=======
760756
/// A goal has coinductive semantics if it is of the form `T: AutoTrait`, or if it is of the
761757
/// form `WellFormed(T: Trait)` where `Trait` is any trait. The latter is needed for dealing
762758
/// with WF requirements and cyclic traits, which generates cycles in the proof tree which must
763759
/// not be rejected but instead must be treated as a success.
764-
pub fn is_coinductive(&self, program: &ProgramEnvironment) -> bool {
765-
>>>>>>> Add documentation
760+
crate fn is_coinductive(&self, program: &ProgramEnvironment) -> bool {
766761
match &self.canonical.value.goal {
767762
Goal::Leaf(LeafGoal::DomainGoal(DomainGoal::Implemented(tr))) => {
768763
let trait_datum = &program.trait_data[&tr.trait_id];

src/lower/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,7 @@ impl ir::AssociatedTyDatum {
13871387
// particular, whenever normalization is possible, we cannot
13881388
// solve that projection uniquely, since we can now elaborate
13891389
// `ProjectionEq` to fallback *or* normalize it. So instead we
1390-
// handle this kind of reasoning by expanding "projection
1391-
// equality" predicates (see `DomainGoal::expanded`).
1390+
// handle this kind of reasoning through the `FromEnv` predicate.
13921391
//
13931392
// We also generate rules specific to WF requirements and implied bounds,
13941393
// see below.

src/lower/test.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ macro_rules! lowering_error {
3232

3333

3434
fn parse_and_lower(text: &str) -> Result<Program> {
35-
// Use the on-demand SLG solver to avoid ambiguities on projection types encountered when
36-
// using the recursive solver.
37-
chalk_parse::parse_program(text)?.lower(SolverChoice::on_demand_slg())
35+
// FIXME: Use the SLG solver to avoid ambiguities on projection types encountered
36+
// when using the recursive solver.
37+
chalk_parse::parse_program(text)?.lower(SolverChoice::slg())
3838
}
3939

4040
fn parse_and_lower_goal(program: &Program, text: &str) -> Result<Box<Goal>> {
@@ -575,7 +575,6 @@ fn ill_formed_trait_decl() {
575575
}
576576
}
577577
}
578-
579578
#[test]
580579
fn cyclic_traits() {
581580
lowering_success! {
@@ -587,23 +586,34 @@ fn cyclic_traits() {
587586
impl<T> A for T { }
588587
}
589588
}
590-
}
591589

592-
#[test]
593-
fn cyclic_traits_error() {
594590
lowering_error! {
595591
program {
596592
trait Copy { }
597593

598594
trait A where Self: B, Self: Copy {}
599595
trait B where Self: A { }
600596

597+
// This impl won't be able to prove that `T: Copy` holds.
601598
impl<T> B for T {}
599+
602600
impl<T> A for T where T: B {}
603601
} error_msg {
604602
"trait impl for \"B\" does not meet well-formedness requirements"
605603
}
606604
}
605+
606+
lowering_success! {
607+
program {
608+
trait Copy { }
609+
610+
trait A where Self: B, Self: Copy {}
611+
trait B where Self: A { }
612+
613+
impl<T> B for T where T: Copy {}
614+
impl<T> A for T where T: B {}
615+
}
616+
}
607617
}
608618

609619
#[test]
@@ -636,6 +646,7 @@ fn ill_formed_assoc_ty() {
636646
}
637647

638648
impl Bar for i32 {
649+
// `OnlyFoo<i32>` is ill-formed because `i32: Foo` does not hold.
639650
type Value = OnlyFoo<i32>;
640651
}
641652
} error_msg {
@@ -660,6 +671,7 @@ fn implied_bounds() {
660671
}
661672

662673
impl<K> Foo for Set<K> {
674+
// Here, `WF(Set<K>)` implies `K: Hash` and hence `OnlyEq<K>` is WF.
663675
type Value = OnlyEq<K>;
664676
}
665677
}
@@ -710,6 +722,8 @@ fn wf_requiremements_for_projection() {
710722
}
711723

712724
impl<T> Foo for T {
725+
// The projection is well-formed if `T: Iterator` holds, which cannot
726+
// be proved here.
713727
type Value = <T as Iterator>::Item;
714728
}
715729
} error_msg {
@@ -744,6 +758,8 @@ fn projection_type_in_header() {
744758

745759
trait Bar { }
746760

761+
// Projection types in an impl header are not assumed to be well-formed,
762+
// an explicit where clause is needed (see below).
747763
impl<T> Bar for <T as Foo>::Value { }
748764
} error_msg {
749765
"trait impl for \"Bar\" does not meet well-formedness requirements"

src/lower/wf.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct WfSolver {
1313

1414
impl Program {
1515
pub fn verify_well_formedness(&self, solver_choice: SolverChoice) -> Result<()> {
16-
set_current_program(&Arc::new(self.clone()), || self.solve_wf_requirements(solver_choice))
16+
tls::set_current_program(&Arc::new(self.clone()), || self.solve_wf_requirements(solver_choice))
1717
}
1818

1919
fn solve_wf_requirements(&self, solver_choice: SolverChoice) -> Result<()> {
@@ -79,9 +79,15 @@ impl FoldInputTypes for Ty {
7979
proj.parameters.fold(accumulator);
8080
}
8181

82-
// Type parameters and higher-kinded types do not carry any input types (so we can sort
83-
// of assume they are always WF).
84-
Ty::Var(..) | Ty::ForAll(..) => (),
82+
// Type parameters do not carry any input types (so we can sort of assume they are
83+
// always WF).
84+
Ty::Var(..) => (),
85+
86+
// Higher-kinded types such as `for<'a> fn(&'a u32)` introduce their own implied
87+
// bounds, and these bounds will be enforced upon calling such a function. In some
88+
// sense, well-formedness requirements for the input types of an HKT will be enforced
89+
// lazily, so no need to include them here.
90+
Ty::ForAll(..) => (),
8591
}
8692
}
8793
}
@@ -244,7 +250,7 @@ impl WfSolver {
244250
.map(|ty| WellFormed::Ty(ty).cast())
245251
.chain(assoc_ty_goals)
246252
.chain(Some(WellFormed::TraitRef(trait_ref.clone())).cast());
247-
253+
248254
let goal = goals.fold1(|goal, leaf| Goal::And(Box::new(goal), Box::new(leaf)))
249255
.expect("at least one goal");
250256

src/solve/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn parse_and_lower_program(text: &str, solver_choice: SolverChoice, skip_coheren
1414
-> Result<ir::Program>
1515
{
1616
if skip_coherence {
17-
// We disable WF checks for the recursive solver, because of ambiguities appearing
17+
// FIXME: We disable WF checks for the recursive solver, because of ambiguities appearing
1818
// with projection types.
1919
chalk_parse::parse_program(text)?.lower_without_coherence()
2020
} else {

0 commit comments

Comments
 (0)