-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MVP for chalkification #48985
MVP for chalkification #48985
Conversation
☔ The latest upstream changes (presumably #48411) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome! I left some suggestions, mostly nits of various kinds. I'm inclined to move forward quickly and do most of our iteration in tree rather than spending too much time in this PR, so we should feel free to mark some items as "follow-up work" (e.g., giving names and comments and things).
src/librustc/ich/impls_ty.rs
Outdated
@@ -1237,3 +1237,86 @@ for ty::UniverseIndex { | |||
self.depth().hash_stable(hcx, hasher); | |||
} | |||
} | |||
|
|||
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClauseAtom<'tcx> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
egads we should really extend the macro here
src/librustc/traits/mod.rs
Outdated
@@ -242,6 +244,59 @@ pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>; | |||
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>; | |||
pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>; | |||
|
|||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] | |||
pub enum WhereClauseAtom<'tcx> { | |||
Implemented(ty::PolyTraitPredicate<'tcx>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want poly trait predicates here. I think we want the binders to be moved out of WhereClauseAtom
and into the Goal
-- actually, in Chalk we get this mildly wrong, as I'll comment below.
src/librustc/traits/mod.rs
Outdated
Implies(Vec<DomainGoal<'tcx>>, Box<Goal<'tcx>>), | ||
And(Box<Goal<'tcx>>, Box<Goal<'tcx>>), | ||
Not(Box<Goal<'tcx>>), | ||
Leaf(LeafGoal<'tcx>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just call this DomainGoal
, and forego the Leaf
indirection
src/librustc/traits/mod.rs
Outdated
|
||
#[derive(Clone, PartialEq, Eq, Hash, Debug)] | ||
pub enum Goal<'tcx> { | ||
Implies(Vec<DomainGoal<'tcx>>, Box<Goal<'tcx>>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this matches chalk, where we make the hypotheses a set of domain goals, but it's not as general as we could do. We really should use Clause<'tcx>
here, which would match the following enum:
enum Clause<'tcx> {
Implies(Vec<Goal<'tcx>>, DomainGoal<'tcx>),
DomainGoal(DomainGoal<'tcx>),
ForAll(Box<ty::Binder<Clause<'tcx>>),
}
This matches the definition from Page 7 of "A Proof Procedure for the Logic of Hereditary Harrop Formulas" pretty well. That definition is D = A | G => A | D ^ D | forall x. D
-- where D
is a clause, G
is a goal, and A
is a DomainGoal
-- but we've moved the "and" case (D ^ D
) into the vector. (There are broader definitions as well for clauses, but they can be normalized into this form.)
This would also entail a change to Environment
to store these clauses instead of just domain goals.
The reason that this matters is that if we move the binder out of DomainGoal
, we need somewhere to put it in the case of a clause!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we should use interners probably, and hence make this:
type Goal<'tcx> = &'tcx GoalKind<'tcx>;
enum GoalKind<'tcx> {
Implies(Vec<DomainGoal<'tcx>, Goal<'tcx>),
... // as today
}
but we can do that in a follow-up. (We should open a FIXME for it before landing.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened rust-lang/chalk#94 to describe the change here in chalk
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
write!(fmt, "{}", self.consequence)?; | ||
if self.conditions.is_empty() { | ||
write!(fmt, ".")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Total nit: let's either keep the .
on both sides or drop it on both sides. =)
} | ||
} | ||
|
||
impl<'tcx> TypeFoldable<'tcx> for traits::WhereClauseAtom<'tcx> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are pretty decent macros for this... oh, shoot, they are in #48411 -- oh, wait, that just landed =)
You may want to adopt one of these:
Lines 160 to 164 in 8c4ff22
/////////////////////////////////////////////////////////////////////////// | |
// Lift and TypeFoldable macros | |
// | |
// When possible, use one of these (relatively) convenient macros to write | |
// the impls for you. |
|
||
trait Foo { } | ||
|
||
#[rustc_dump_program_clauses] //~ ERROR Implemented(T: Foo) :- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so nice =) I guess you intentionally omitted the details here? (We see them below in the stderr file...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I skipped them here because it's a bit verbose :)
src/librustc/traits/lowering.rs
Outdated
fn lower(&self) -> DomainGoal<'tcx> { | ||
use self::Predicate::*; | ||
|
||
match *self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit; you don't need the *self
anymore; you can add the feature(match_default_bindings)
instead
src/librustc/traits/lowering.rs
Outdated
let trait_ref = ty::Binder(TraitPredicate { trait_ref }).lower(); | ||
let where_clauses = tcx.predicates_of(def_id).predicates.lower(); | ||
|
||
let clause = ProgramClause { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. So, I think we should go through the rustc-guide reference on this topic and give names to each of these rules. Then we can reference those rules here to allow for easy cross-reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done later.
src/librustc/traits/lowering.rs
Outdated
use ty::{self, PolyTraitPredicate, TraitPredicate, PolyProjectionPredicate, TyCtxt, Predicate}; | ||
use super::{DomainGoal, ProgramClause, WhereClauseAtom}; | ||
use rustc_data_structures::sync::Lrc; | ||
use syntax::ast; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's move this code into librustc_traits
now that #48411 has landed
ok so I was talking to @scalexm on gitter. We agreed that we can leave most of the changes here for later. Here is the list of thing I wrote, I think:
|
@scalexm I'd like to review one last time tomorrow or whatever, but otherwise once nits are fixed I think we should land and then we can open up issues for follow-up work |
@bors r+ This is so exciting. 🎉 |
📌 Commit 4eaa85d has been approved by |
src/librustc_traits/lowering.rs
Outdated
if let ImplPolarity::Negative = tcx.impl_polarity(def_id) { | ||
return Lrc::new(vec![]); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[00:06:08] tidy error: /checkout/src/librustc_traits/lowering.rs:120: trailing whitespace
[00:06:10] some tidy checks failed
@bors r- Tidy failed. |
@bors r=nikomatsakis |
📌 Commit ef3b4e1 has been approved by |
MVP for chalkification r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
r? @nikomatsakis