Skip to content

Commit da9467d

Browse files
committed
Handle sub-typing in chalk-engine
1 parent ba6314a commit da9467d

File tree

9 files changed

+41
-11
lines changed

9 files changed

+41
-11
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
273273

274274
[[package]]
275275
name = "chalk-engine"
276-
version = "0.8.0"
276+
version = "0.9.0"
277277
source = "registry+https://github.com/rust-lang/crates.io-index"
278278
dependencies = [
279279
"chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2067,7 +2067,7 @@ dependencies = [
20672067
"backtrace 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
20682068
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
20692069
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
2070-
"chalk-engine 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
2070+
"chalk-engine 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
20712071
"flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
20722072
"fmt_macros 0.0.0",
20732073
"graphviz 0.0.0",
@@ -2640,7 +2640,7 @@ name = "rustc_traits"
26402640
version = "0.0.0"
26412641
dependencies = [
26422642
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
2643-
"chalk-engine 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
2643+
"chalk-engine 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
26442644
"graphviz 0.0.0",
26452645
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
26462646
"rustc 0.0.0",
@@ -3403,7 +3403,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
34033403
"checksum cargo_metadata 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d8dfe3adeb30f7938e6c1dd5327f29235d8ada3e898aeb08c343005ec2915a2"
34043404
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
34053405
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
3406-
"checksum chalk-engine 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6749eb72e7d4355d944a99f15fbaea701b978c18c5e184a025fcde942b0c9779"
3406+
"checksum chalk-engine 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17ec698a6f053a23bfbe646d9f2fde4b02abc19125595270a99e6f44ae0bdd1a"
34073407
"checksum chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "295635afd6853aa9f20baeb7f0204862440c0fe994c5a253d5f479dac41d047e"
34083408
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
34093409
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"

src/librustc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ syntax_pos = { path = "../libsyntax_pos" }
3030
backtrace = "0.3.3"
3131
parking_lot = "0.6"
3232
byteorder = { version = "1.1", features = ["i128"]}
33-
chalk-engine = { version = "0.8.0", default-features=false }
33+
chalk-engine = { version = "0.9.0", default-features=false }
3434
rustc_fs_util = { path = "../librustc_fs_util" }
3535
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }
3636

src/librustc/ich/impls_ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
11951195
quantifier.hash_stable(hcx, hasher);
11961196
goal.hash_stable(hcx, hasher);
11971197
},
1198+
Subtype(a, b) => {
1199+
a.hash_stable(hcx, hasher);
1200+
b.hash_stable(hcx, hasher);
1201+
}
11981202
CannotProve => { },
11991203
}
12001204
}

src/librustc/traits/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ pub enum GoalKind<'tcx> {
324324
Not(Goal<'tcx>),
325325
DomainGoal(DomainGoal<'tcx>),
326326
Quantified(QuantifierKind, ty::Binder<Goal<'tcx>>),
327+
Subtype(Ty<'tcx>, Ty<'tcx>),
327328
CannotProve,
328329
}
329330

src/librustc/traits/structural_impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ impl<'tcx> fmt::Display for traits::Goal<'tcx> {
395395

396396
Ok(())
397397
}
398+
Subtype(a, b) => write!(fmt, "{} <: {}", a, b),
398399
CannotProve => write!(fmt, "CannotProve"),
399400
}
400401
}
@@ -668,6 +669,7 @@ EnumLiftImpl! {
668669
(traits::GoalKind::Not)(goal),
669670
(traits::GoalKind::DomainGoal)(domain_goal),
670671
(traits::GoalKind::Quantified)(kind, goal),
672+
(traits::GoalKind::Subtype)(a, b),
671673
(traits::GoalKind::CannotProve),
672674
}
673675
}
@@ -864,6 +866,7 @@ EnumTypeFoldableImpl! {
864866
(traits::GoalKind::Not)(goal),
865867
(traits::GoalKind::DomainGoal)(domain_goal),
866868
(traits::GoalKind::Quantified)(qkind, goal),
869+
(traits::GoalKind::Subtype)(a, b),
867870
(traits::GoalKind::CannotProve),
868871
}
869872
}

src/librustc_traits/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ rustc_data_structures = { path = "../librustc_data_structures" }
1717
rustc_target = { path = "../librustc_target" }
1818
syntax = { path = "../libsyntax" }
1919
syntax_pos = { path = "../libsyntax_pos" }
20-
chalk-engine = { version = "0.8.0", default-features=false }
20+
chalk-engine = { version = "0.9.0", default-features=false }
2121
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }

src/librustc_traits/chalk_context/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ impl context::Context for ChalkArenas<'tcx> {
116116

117117
type UnificationResult = UnificationResult<'tcx>;
118118

119+
type Variance = ty::Variance;
120+
119121
fn goal_in_environment(
120122
env: &Environment<'tcx>,
121123
goal: Goal<'tcx>,
@@ -332,6 +334,11 @@ impl context::InferenceTable<ChalkArenas<'gcx>, ChalkArenas<'tcx>>
332334
GoalKind::DomainGoal(d) => HhGoal::DomainGoal(d),
333335
GoalKind::Quantified(QuantifierKind::Universal, binder) => HhGoal::ForAll(binder),
334336
GoalKind::Quantified(QuantifierKind::Existential, binder) => HhGoal::Exists(binder),
337+
GoalKind::Subtype(a, b) => HhGoal::Unify(
338+
ty::Variance::Covariant,
339+
a.into(),
340+
b.into()
341+
),
335342
GoalKind::CannotProve => HhGoal::CannotProve,
336343
}
337344
}
@@ -444,11 +451,13 @@ impl context::UnificationOps<ChalkArenas<'gcx>, ChalkArenas<'tcx>>
444451
fn unify_parameters(
445452
&mut self,
446453
environment: &Environment<'tcx>,
454+
variance: ty::Variance,
447455
a: &Kind<'tcx>,
448456
b: &Kind<'tcx>,
449457
) -> Fallible<UnificationResult<'tcx>> {
450458
self.infcx.commit_if_ok(|_| {
451-
unify(self.infcx, *environment, a, b).map_err(|_| chalk_engine::fallible::NoSolution)
459+
unify(self.infcx, *environment, variance, a, b)
460+
.map_err(|_| chalk_engine::fallible::NoSolution)
452461
})
453462
}
454463

@@ -673,6 +682,13 @@ crate fn evaluate_goal<'a, 'tcx>(
673682
GoalKind::DomainGoal(DomainGoal::WellFormed(WellFormed::Ty(ty)))
674683
),
675684

685+
ty::Predicate::Subtype(predicate) => tcx.mk_goal(
686+
GoalKind::Quantified(
687+
QuantifierKind::Universal,
688+
predicate.map_bound(|pred| tcx.mk_goal(GoalKind::Subtype(pred.a, pred.b)))
689+
)
690+
),
691+
676692
other => tcx.mk_goal(
677693
GoalKind::from_poly_domain_goal(other.lower(), tcx)
678694
),

src/librustc_traits/chalk_context/resolvent_ops.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ impl context::ResolventOps<ChalkArenas<'gcx>, ChalkArenas<'tcx>>
5151
).0,
5252
};
5353

54-
let result = unify(self.infcx, *environment, goal, &consequence)
55-
.map_err(|_| NoSolution)?;
54+
let result = unify(
55+
self.infcx,
56+
*environment,
57+
ty::Variance::Invariant,
58+
goal,
59+
&consequence
60+
).map_err(|_| NoSolution)?;
5661

5762
let mut ex_clause = ExClause {
5863
subst: subst.clone(),
@@ -139,7 +144,7 @@ impl AnswerSubstitutor<'cx, 'gcx, 'tcx> {
139144
);
140145

141146
super::into_ex_clause(
142-
unify(self.infcx, self.environment, answer_param, pending)?,
147+
unify(self.infcx, self.environment, ty::Variance::Invariant, answer_param, pending)?,
143148
&mut self.ex_clause
144149
);
145150

src/librustc_traits/chalk_context/unify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ crate struct UnificationResult<'tcx> {
1313
crate fn unify<'me, 'gcx, 'tcx, T: Relate<'tcx>>(
1414
infcx: &'me InferCtxt<'me, 'gcx, 'tcx>,
1515
environment: Environment<'tcx>,
16+
variance: ty::Variance,
1617
a: &T,
1718
b: &T
1819
) -> RelateResult<'tcx, UnificationResult<'tcx>> {
@@ -30,7 +31,7 @@ crate fn unify<'me, 'gcx, 'tcx, T: Relate<'tcx>>(
3031
TypeRelating::new(
3132
infcx,
3233
&mut delegate,
33-
ty::Variance::Invariant
34+
variance
3435
).relate(a, b)?;
3536

3637
debug!("unify: goals = {:?}, constraints = {:?}", delegate.goals, delegate.constraints);

0 commit comments

Comments
 (0)