Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0aed74a

Browse files
authoredNov 9, 2020
Rollup merge of #78502 - matthewjasper:chalkup, r=nikomatsakis
Update Chalk to 0.36.0 This PR updates Chalk and fixes a number of bugs in the chalk integration code. cc `@rust-lang/wg-traits` r? `@nikomatsakis`
2 parents 2187f3c + 4d60a80 commit 0aed74a

File tree

11 files changed

+384
-355
lines changed

11 files changed

+384
-355
lines changed
 

‎Cargo.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
460460

461461
[[package]]
462462
name = "chalk-derive"
463-
version = "0.32.0"
463+
version = "0.36.0"
464464
source = "registry+https://github.com/rust-lang/crates.io-index"
465-
checksum = "2d072b2ba723f0bada7c515d8b3725224bc4f5052d2a92dcbeb0b118ff37084a"
465+
checksum = "9f88ce4deae1dace71e49b7611cfae2d5489de3530d6daba5758043c47ac3a10"
466466
dependencies = [
467467
"proc-macro2",
468468
"quote",
@@ -472,9 +472,9 @@ dependencies = [
472472

473473
[[package]]
474474
name = "chalk-engine"
475-
version = "0.32.0"
475+
version = "0.36.0"
476476
source = "registry+https://github.com/rust-lang/crates.io-index"
477-
checksum = "6fb5475f6083d6d6c509e1c335c4f69ad04144ac090faa1afb134a53c3695841"
477+
checksum = "0e34c9b1b10616782143d7f49490f91ae94afaf2202de3ab0b2835e78b4f0ccc"
478478
dependencies = [
479479
"chalk-derive",
480480
"chalk-ir",
@@ -485,19 +485,19 @@ dependencies = [
485485

486486
[[package]]
487487
name = "chalk-ir"
488-
version = "0.32.0"
488+
version = "0.36.0"
489489
source = "registry+https://github.com/rust-lang/crates.io-index"
490-
checksum = "f60cdb0e18c5455cb6a85e8464aad3622b70476018edfa8845691df66f7e9a05"
490+
checksum = "63362c629c2014ab639b04029070763fb8224df136d1363d30e9ece4c8877da3"
491491
dependencies = [
492492
"chalk-derive",
493493
"lazy_static",
494494
]
495495

496496
[[package]]
497497
name = "chalk-solve"
498-
version = "0.32.0"
498+
version = "0.36.0"
499499
source = "registry+https://github.com/rust-lang/crates.io-index"
500-
checksum = "981534d499a8476ecc0b520be4d3864757f96211826a75360fbf2cb6fae362ab"
500+
checksum = "cac338a67af52a7f50bb2f8232e730a3518ce432dbe303246acfe525ddd838c7"
501501
dependencies = [
502502
"chalk-derive",
503503
"chalk-ir",

‎compiler/rustc_middle/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rustc_index = { path = "../rustc_index" }
2626
rustc_serialize = { path = "../rustc_serialize" }
2727
rustc_ast = { path = "../rustc_ast" }
2828
rustc_span = { path = "../rustc_span" }
29-
chalk-ir = "0.32.0"
29+
chalk-ir = "0.36.0"
3030
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3131
measureme = "9.0.0"
3232
rustc_session = { path = "../rustc_session" }

‎compiler/rustc_middle/src/traits/chalk.rs

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -102,48 +102,6 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
102102
Some(write())
103103
}
104104

105-
fn debug_application_ty(
106-
application_ty: &chalk_ir::ApplicationTy<Self>,
107-
fmt: &mut fmt::Formatter<'_>,
108-
) -> Option<fmt::Result> {
109-
match application_ty.name {
110-
chalk_ir::TypeName::Ref(mutbl) => {
111-
let data = application_ty.substitution.interned();
112-
match (&**data[0].interned(), &**data[1].interned()) {
113-
(
114-
chalk_ir::GenericArgData::Lifetime(lifetime),
115-
chalk_ir::GenericArgData::Ty(ty),
116-
) => Some(match mutbl {
117-
chalk_ir::Mutability::Not => write!(fmt, "(&{:?} {:?})", lifetime, ty),
118-
chalk_ir::Mutability::Mut => write!(fmt, "(&{:?} mut {:?})", lifetime, ty),
119-
}),
120-
_ => unreachable!(),
121-
}
122-
}
123-
chalk_ir::TypeName::Array => {
124-
let data = application_ty.substitution.interned();
125-
match (&**data[0].interned(), &**data[1].interned()) {
126-
(chalk_ir::GenericArgData::Ty(ty), chalk_ir::GenericArgData::Const(len)) => {
127-
Some(write!(fmt, "[{:?}; {:?}]", ty, len))
128-
}
129-
_ => unreachable!(),
130-
}
131-
}
132-
chalk_ir::TypeName::Slice => {
133-
let data = application_ty.substitution.interned();
134-
let ty = match &**data[0].interned() {
135-
chalk_ir::GenericArgData::Ty(t) => t,
136-
_ => unreachable!(),
137-
};
138-
Some(write!(fmt, "[{:?}]", ty))
139-
}
140-
_ => {
141-
let chalk_ir::ApplicationTy { name, substitution } = application_ty;
142-
Some(write!(fmt, "{:?}{:?}", name, chalk_ir::debug::Angle(substitution.interned())))
143-
}
144-
}
145-
}
146-
147105
fn debug_substitution(
148106
substitution: &chalk_ir::Substitution<Self>,
149107
fmt: &mut fmt::Formatter<'_>,
@@ -174,6 +132,32 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
174132
Some(write!(fmt, "{:?}", clauses.interned()))
175133
}
176134

135+
fn debug_ty(ty: &chalk_ir::Ty<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
136+
match &ty.interned().kind {
137+
chalk_ir::TyKind::Ref(chalk_ir::Mutability::Not, lifetime, ty) => {
138+
Some(write!(fmt, "(&{:?} {:?})", lifetime, ty))
139+
}
140+
chalk_ir::TyKind::Ref(chalk_ir::Mutability::Mut, lifetime, ty) => {
141+
Some(write!(fmt, "(&{:?} mut {:?})", lifetime, ty))
142+
}
143+
chalk_ir::TyKind::Array(ty, len) => Some(write!(fmt, "[{:?}; {:?}]", ty, len)),
144+
chalk_ir::TyKind::Slice(ty) => Some(write!(fmt, "[{:?}]", ty)),
145+
chalk_ir::TyKind::Tuple(len, substs) => Some((|| {
146+
write!(fmt, "(")?;
147+
for (idx, substitution) in substs.interned().iter().enumerate() {
148+
if idx == *len && *len != 1 {
149+
// Don't add a trailing comma if the tuple has more than one element
150+
write!(fmt, "{:?}", substitution)?;
151+
} else {
152+
write!(fmt, "{:?},", substitution)?;
153+
}
154+
}
155+
write!(fmt, ")")
156+
})()),
157+
_ => None,
158+
}
159+
}
160+
177161
fn debug_alias(
178162
alias_ty: &chalk_ir::AliasTy<Self>,
179163
fmt: &mut fmt::Formatter<'_>,

‎compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ thread_local! {
6363
/// Avoids running any queries during any prints that occur
6464
/// during the closure. This may alter the appearance of some
6565
/// types (e.g. forcing verbose printing for opaque types).
66-
/// This method is used during some queries (e.g. `predicates_of`
66+
/// This method is used during some queries (e.g. `explicit_item_bounds`
6767
/// for opaque types), to ensure that any debug printing that
6868
/// occurs during the query computation does not end up recursively
6969
/// calling the same query.

‎compiler/rustc_traits/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ rustc_hir = { path = "../rustc_hir" }
1212
rustc_index = { path = "../rustc_index" }
1313
rustc_ast = { path = "../rustc_ast" }
1414
rustc_span = { path = "../rustc_span" }
15-
chalk-ir = "0.32.0"
16-
chalk-solve = "0.32.0"
17-
chalk-engine = "0.32.0"
15+
chalk-ir = "0.36.0"
16+
chalk-solve = "0.36.0"
17+
chalk-engine = "0.36.0"
1818
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
1919
rustc_infer = { path = "../rustc_infer" }
2020
rustc_trait_selection = { path = "../rustc_trait_selection" }

‎compiler/rustc_traits/src/chalk/db.rs

Lines changed: 128 additions & 78 deletions
Large diffs are not rendered by default.

‎compiler/rustc_traits/src/chalk/lowering.rs

Lines changed: 171 additions & 210 deletions
Large diffs are not rendered by default.

‎compiler/rustc_traits/src/chalk/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ crate fn evaluate_goal<'tcx>(
6969
CanonicalVarKind::PlaceholderRegion(_ui) => unimplemented!(),
7070
CanonicalVarKind::Ty(ty) => match ty {
7171
CanonicalTyVarKind::General(ui) => chalk_ir::WithKind::new(
72-
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General),
72+
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
7373
chalk_ir::UniverseIndex { counter: ui.index() },
7474
),
7575
CanonicalTyVarKind::Int => chalk_ir::WithKind::new(
76-
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::Integer),
76+
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Integer),
7777
chalk_ir::UniverseIndex::root(),
7878
),
7979
CanonicalTyVarKind::Float => chalk_ir::WithKind::new(
80-
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::Float),
80+
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::Float),
8181
chalk_ir::UniverseIndex::root(),
8282
),
8383
},
@@ -97,7 +97,8 @@ crate fn evaluate_goal<'tcx>(
9797
use chalk_solve::Solver;
9898
let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
9999
let db = ChalkRustIrDatabase { interner, reempty_placeholder };
100-
let solution = chalk_solve::logging::with_tracing_logs(|| solver.solve(&db, &lowered_goal));
100+
let solution = solver.solve(&db, &lowered_goal);
101+
debug!(?obligation, ?solution, "evaluatate goal");
101102

102103
// Ideally, the code to convert *back* to rustc types would live close to
103104
// the code to convert *from* rustc types. Right now though, we don't

‎compiler/rustc_typeck/src/collect/item_bounds.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ fn opaque_type_bounds<'tcx>(
6161
bounds: &'tcx [hir::GenericBound<'tcx>],
6262
span: Span,
6363
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
64-
let item_ty =
65-
tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id));
64+
ty::print::with_no_queries(|| {
65+
let item_ty =
66+
tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id));
6667

67-
let bounds = ty::print::with_no_queries(|| {
68-
AstConv::compute_bounds(
68+
let bounds = AstConv::compute_bounds(
6969
&ItemCtxt::new(tcx, opaque_def_id),
7070
item_ty,
7171
bounds,
7272
SizedByDefault::Yes,
7373
span,
7474
)
75-
});
75+
.predicates(tcx, item_ty);
7676

77-
let bounds = bounds.predicates(tcx, item_ty);
78-
debug!("opaque_type_bounds({}) = {:?}", tcx.def_path_str(opaque_def_id), bounds);
77+
debug!("opaque_type_bounds({}) = {:?}", tcx.def_path_str(opaque_def_id), bounds);
7978

80-
tcx.arena.alloc_slice(&bounds)
79+
tcx.arena.alloc_slice(&bounds)
80+
})
8181
}
8282

8383
pub(super) fn explicit_item_bounds(

‎src/test/ui/chalkify/arithmetic.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
// compile-flags: -Z chalk
3+
4+
fn main() {
5+
1 + 2;
6+
3 * 6;
7+
2 - 5;
8+
17 / 6;
9+
23 % 11;
10+
4 & 6;
11+
7 | 15;
12+
4 << 7;
13+
123 >> 3;
14+
1 == 2;
15+
5 != 5;
16+
6 < 2;
17+
7 > 11;
18+
3 <= 1;
19+
9 >= 14;
20+
}

‎src/test/ui/chalkify/trait-objects.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
// compile-flags: -Z chalk
3+
4+
use std::fmt::Display;
5+
6+
fn main() {
7+
let d: &dyn Display = &mut 3;
8+
// FIXME(chalk) should be able to call d.to_string() as well, but doing so
9+
// requires Chalk to be able to prove trait object well-formed goals.
10+
(&d).to_string();
11+
let f: &dyn Fn(i32) -> _ = &|x| x + x;
12+
f(2);
13+
}

0 commit comments

Comments
 (0)
Please sign in to comment.