Skip to content

Commit e8f3ed5

Browse files
committed
Add documentation
1 parent 2bbd16d commit e8f3ed5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc/traits/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
245245
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;
246246
pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>;
247247

248+
/// The following types:
249+
/// * `WhereClauseAtom`
250+
/// * `DomainGoal`
251+
/// * `Goal`
252+
/// * `Clause`
253+
/// are used for representing the trait system in the form of
254+
/// logic programming clauses. They are part of the interface
255+
/// for the chalk SLG solver.
248256
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
249257
pub enum WhereClauseAtom<'tcx> {
250258
Implemented(ty::TraitPredicate<'tcx>),
@@ -270,6 +278,7 @@ pub enum QuantifierKind {
270278

271279
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
272280
pub enum Goal<'tcx> {
281+
// FIXME: use interned refs instead of `Box`
273282
Implies(Vec<Clause<'tcx>>, Box<Goal<'tcx>>),
274283
And(Box<Goal<'tcx>>, Box<Goal<'tcx>>),
275284
Not(Box<Goal<'tcx>>),
@@ -289,8 +298,11 @@ impl<'tcx> From<DomainGoal<'tcx>> for Clause<'tcx> {
289298
}
290299
}
291300

301+
/// This matches the definition from Page 7 of "A Proof Procedure for the Logic of Hereditary
302+
/// Harrop Formulas".
292303
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
293304
pub enum Clause<'tcx> {
305+
// FIXME: again, use interned refs instead of `Box`
294306
Implies(Vec<Goal<'tcx>>, DomainGoal<'tcx>),
295307
DomainGoal(DomainGoal<'tcx>),
296308
ForAll(Box<ty::Binder<Clause<'tcx>>>),

src/librustc_traits/lowering.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use syntax::ast;
1717
use rustc_data_structures::sync::Lrc;
1818

1919
trait Lower<T> {
20+
/// Lower a rustc construction (e.g. `ty::TraitPredicate`) to a chalk-like type.
2021
fn lower(&self) -> T;
2122
}
2223

@@ -56,6 +57,15 @@ impl<'tcx> Lower<DomainGoal<'tcx>> for ty::TypeOutlivesPredicate<'tcx> {
5657
}
5758
}
5859

60+
/// `ty::Binder` is used for wrapping a rustc construction possibly containing generic
61+
/// lifetimes, e.g. `for<'a> T: Fn(&'a i32)`. Instead of representing higher-ranked things
62+
/// in that leaf-form (i.e. `Holds(Implemented(Binder<TraitPredicate>))` in the previous
63+
/// example), we model them with quantified goals, e.g. as for the previous example:
64+
/// `forall<'a> { T: Fn(&'a i32) }` which corresponds to something like
65+
/// `Binder<Holds(Implemented(TraitPredicate))>`.
66+
///
67+
/// Also, if `self` does not contain generic lifetimes, we can safely drop the binder and we
68+
/// can directly lower to a leaf goal instead of a quantified goal.
5969
impl<'tcx, T> Lower<Goal<'tcx>> for ty::Binder<T>
6070
where T: Lower<DomainGoal<'tcx>> + ty::fold::TypeFoldable<'tcx> + Copy
6171
{
@@ -95,6 +105,8 @@ crate fn program_clauses_for<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI
95105
let item = tcx.hir.expect_item(node_id);
96106
match item.node {
97107
hir::ItemImpl(..) => program_clauses_for_impl(tcx, def_id),
108+
109+
// FIXME: other constructions e.g. traits, associated types...
98110
_ => Lrc::new(vec![]),
99111
}
100112
}

0 commit comments

Comments
 (0)