Skip to content

Commit c64f61b

Browse files
authored
Merge pull request #191 from scalexm/subtype
Add a variance parameter to `HhGoal::Unify`
2 parents 1760406 + 394ef31 commit c64f61b

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

chalk-engine/src/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ pub trait Context: Clone + Debug {
103103
/// A vector of program clauses.
104104
type ProgramClauses: Debug;
105105

106+
/// How to relate two kinds when unifying: for example in rustc, we
107+
/// may want to unify parameters either for the sub-typing relation or for
108+
/// the equality relation.
109+
type Variance;
110+
106111
/// The successful result from unification: contains new subgoals
107112
/// and things that can be attached to an ex-clause.
108113
type UnificationResult;
@@ -307,6 +312,7 @@ pub trait UnificationOps<C: Context, I: Context> {
307312
fn unify_parameters(
308313
&mut self,
309314
environment: &I::Environment,
315+
variance: I::Variance,
310316
a: &I::Parameter,
311317
b: &I::Parameter,
312318
) -> Fallible<I::UnificationResult>;

chalk-engine/src/hh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub enum HhGoal<C: Context> {
1010
Implies(C::ProgramClauses, C::Goal),
1111
And(C::Goal, C::Goal),
1212
Not(C::Goal),
13-
Unify(C::Parameter, C::Parameter),
13+
Unify(C::Variance, C::Parameter, C::Parameter),
1414
DomainGoal(C::DomainGoal),
1515

1616
/// Indicates something that cannot be proven to be true or false

chalk-engine/src/simplify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl<C: Context, CO: ContextOps<C>> Forest<C, CO> {
4747
.subgoals
4848
.push(Literal::Negative(I::goal_in_environment(&environment, subgoal)));
4949
}
50-
HhGoal::Unify(a, b) => {
51-
let result = infer.unify_parameters(&environment, &a, &b)?;
50+
HhGoal::Unify(variance, a, b) => {
51+
let result = infer.unify_parameters(&environment, variance, &a, &b)?;
5252
infer.into_ex_clause(result, &mut ex_clause)
5353
}
5454
HhGoal::DomainGoal(domain_goal) => {

chalk-solve/src/solve/slg/implementation.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl context::Context for SlgContext {
5858
type GoalInEnvironment = InEnvironment<Goal>;
5959
type Substitution = Substitution;
6060
type RegionConstraint = InEnvironment<Constraint>;
61+
type Variance = ();
6162

6263
fn goal_in_environment(environment: &Arc<Environment>, goal: Goal) -> InEnvironment<Goal> {
6364
InEnvironment::new(environment, goal)
@@ -176,7 +177,7 @@ impl context::InferenceTable<SlgContext, SlgContext> for TruncatingInferenceTabl
176177
Goal::Implies(dg, subgoal) => HhGoal::Implies(dg, *subgoal),
177178
Goal::And(g1, g2) => HhGoal::And(*g1, *g2),
178179
Goal::Not(g1) => HhGoal::Not(*g1),
179-
Goal::Leaf(LeafGoal::EqGoal(EqGoal { a, b })) => HhGoal::Unify(a, b),
180+
Goal::Leaf(LeafGoal::EqGoal(EqGoal { a, b })) => HhGoal::Unify((), a, b),
180181
Goal::Leaf(LeafGoal::DomainGoal(domain_goal)) => HhGoal::DomainGoal(domain_goal),
181182
Goal::CannotProve(()) => HhGoal::CannotProve,
182183
}
@@ -276,6 +277,7 @@ impl context::UnificationOps<SlgContext, SlgContext> for TruncatingInferenceTabl
276277
fn unify_parameters(
277278
&mut self,
278279
environment: &Arc<Environment>,
280+
_: (),
279281
a: &Parameter,
280282
b: &Parameter,
281283
) -> Fallible<UnificationResult> {

0 commit comments

Comments
 (0)