Skip to content

Commit 3d17eb3

Browse files
committed
Update to chalk 0.31. Implement some unimplemented. Ignore some tests in compare mode chalk don't finish.
1 parent 738d4a7 commit 3d17eb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+147
-103
lines changed

Cargo.lock

+12-12
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ dependencies = [
430430

431431
[[package]]
432432
name = "chalk-derive"
433-
version = "0.29.0"
433+
version = "0.31.0"
434434
source = "registry+https://github.com/rust-lang/crates.io-index"
435-
checksum = "3a7f257e3bcdc56d8877ae31c012bd69fba0be66929d588e603905f2632c0c59"
435+
checksum = "ca40c97e20f43e4aac2282d342103d45fafad74ad9bfcbaaf0b5d386f9ce1f39"
436436
dependencies = [
437437
"proc-macro2",
438438
"quote",
@@ -442,9 +442,9 @@ dependencies = [
442442

443443
[[package]]
444444
name = "chalk-engine"
445-
version = "0.29.0"
445+
version = "0.31.0"
446446
source = "registry+https://github.com/rust-lang/crates.io-index"
447-
checksum = "c43fcc7edf4d51b42f44ed50e2337bd90ddc8e088d0cd78a71db92a6f780f782"
447+
checksum = "88e3d545394fbc4f7d8fe203c6a78d2b73f82bb119f21af98de1f924c2518e34"
448448
dependencies = [
449449
"chalk-derive",
450450
"chalk-ir",
@@ -455,19 +455,19 @@ dependencies = [
455455

456456
[[package]]
457457
name = "chalk-ir"
458-
version = "0.29.0"
458+
version = "0.31.0"
459459
source = "registry+https://github.com/rust-lang/crates.io-index"
460-
checksum = "03a4050029ecb2b5a1ff3bfc64c39279179b294821ec2e8891a4a5c6e3a08db0"
460+
checksum = "8c4183955e084fcc387b515f867ed0e17e9e7301f5eee29c0338d5e63315bb41"
461461
dependencies = [
462462
"chalk-derive",
463463
"lazy_static",
464464
]
465465

466466
[[package]]
467467
name = "chalk-solve"
468-
version = "0.29.0"
468+
version = "0.31.0"
469469
source = "registry+https://github.com/rust-lang/crates.io-index"
470-
checksum = "828c1f80d4eaf681027cce02050c54a3c97370f81988d31bf2a56df54048746c"
470+
checksum = "50e8407bba06d9e760011a28060e8f3b3f87b82ea53fb8bfaa43614c19c14dcc"
471471
dependencies = [
472472
"chalk-derive",
473473
"chalk-ir",
@@ -5073,9 +5073,9 @@ dependencies = [
50735073

50745074
[[package]]
50755075
name = "tracing-serde"
5076-
version = "0.1.1"
5076+
version = "0.1.2"
50775077
source = "registry+https://github.com/rust-lang/crates.io-index"
5078-
checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79"
5078+
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
50795079
dependencies = [
50805080
"serde",
50815081
"tracing-core",
@@ -5105,9 +5105,9 @@ dependencies = [
51055105

51065106
[[package]]
51075107
name = "tracing-tree"
5108-
version = "0.1.5"
5108+
version = "0.1.6"
51095109
source = "registry+https://github.com/rust-lang/crates.io-index"
5110-
checksum = "e1a3dc4774db3a6b2d66a4f8d8de670e874ec3ed55615860c994927419b32c5f"
5110+
checksum = "43aac8afb493b08e1e1904956f7407c1e671b9c83b26a17e1bd83d6a3520e350"
51115111
dependencies = [
51125112
"ansi_term 0.12.1",
51135113
"atty",

compiler/rustc_middle/Cargo.toml

+1-1
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.29.0"
29+
chalk-ir = "0.31.0"
3030
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3131
measureme = "0.7.1"
3232
rustc_session = { path = "../rustc_session" }

compiler/rustc_traits/Cargo.toml

+3-3
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.29.0"
16-
chalk-solve = "0.29.0"
17-
chalk-engine = "0.29.0"
15+
chalk-ir = "0.31.0"
16+
chalk-solve = "0.31.0"
17+
chalk-engine = "0.31.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

+20-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_ast::ast;
2222

2323
pub struct RustIrDatabase<'tcx> {
2424
pub(crate) interner: RustInterner<'tcx>,
25-
pub(crate) restatic_placeholder: ty::Region<'tcx>,
2625
pub(crate) reempty_placeholder: ty::Region<'tcx>,
2726
}
2827

@@ -39,11 +38,8 @@ impl<'tcx> RustIrDatabase<'tcx> {
3938
bound_vars: SubstsRef<'tcx>,
4039
) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
4140
let predicates = self.interner.tcx.predicates_of(def_id).predicates;
42-
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
43-
self.interner.tcx,
44-
self.restatic_placeholder,
45-
self.reempty_placeholder,
46-
);
41+
let mut regions_substitutor =
42+
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
4743
predicates
4844
.iter()
4945
.map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars))
@@ -262,11 +258,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
262258

263259
let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
264260
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
265-
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
266-
self.interner.tcx,
267-
self.restatic_placeholder,
268-
self.reempty_placeholder,
269-
);
261+
let mut regions_substitutor =
262+
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
270263
let trait_ref = trait_ref.fold_with(&mut regions_substitutor);
271264

272265
let where_clauses = self.where_clauses_for(def_id, bound_vars);
@@ -304,11 +297,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
304297

305298
let self_ty = trait_ref.self_ty();
306299
let self_ty = self_ty.subst(self.interner.tcx, bound_vars);
307-
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
308-
self.interner.tcx,
309-
self.restatic_placeholder,
310-
self.reempty_placeholder,
311-
);
300+
let mut regions_substitutor =
301+
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
312302
let self_ty = self_ty.fold_with(&mut regions_substitutor);
313303
let lowered_ty = self_ty.lower_into(&self.interner);
314304

@@ -576,6 +566,20 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
576566
let substitution = &substs.as_slice(&self.interner)[0..substs.len(&self.interner) - 3];
577567
chalk_ir::Substitution::from_iter(&self.interner, substitution)
578568
}
569+
570+
fn generator_datum(
571+
&self,
572+
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
573+
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<RustInterner<'tcx>>> {
574+
unimplemented!()
575+
}
576+
577+
fn generator_witness_datum(
578+
&self,
579+
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
580+
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<RustInterner<'tcx>>> {
581+
unimplemented!()
582+
}
579583
}
580584

581585
/// Creates a `InternalSubsts` that maps each generic parameter to a higher-ranked

compiler/rustc_traits/src/chalk/lowering.rs

+31-13
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,20 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
427427
chalk_ir::FloatTy::F64 => ty::Float(ast::FloatTy::F64),
428428
},
429429
},
430-
chalk_ir::TypeName::Array => unimplemented!(),
430+
chalk_ir::TypeName::Array => {
431+
let substs = application_ty.substitution.as_slice(interner);
432+
let ty = substs[0].assert_ty_ref(interner).lower_into(interner);
433+
let c = substs[1].assert_const_ref(interner).lower_into(interner);
434+
ty::Array(ty, interner.tcx.mk_const(c))
435+
}
431436
chalk_ir::TypeName::FnDef(id) => {
432437
ty::FnDef(id.0, application_ty.substitution.lower_into(interner))
433438
}
434439
chalk_ir::TypeName::Closure(closure) => {
435440
ty::Closure(closure.0, application_ty.substitution.lower_into(interner))
436441
}
442+
chalk_ir::TypeName::Generator(_) => unimplemented!(),
443+
chalk_ir::TypeName::GeneratorWitness(_) => unimplemented!(),
437444
chalk_ir::TypeName::Never => ty::Never,
438445
chalk_ir::TypeName::Tuple(_size) => {
439446
ty::Tuple(application_ty.substitution.lower_into(interner))
@@ -483,7 +490,15 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
483490
universe: ty::UniverseIndex::from_usize(placeholder.ui.counter),
484491
name: ty::BoundVar::from_usize(placeholder.idx),
485492
}),
486-
TyData::Alias(_alias_ty) => unimplemented!(),
493+
chalk_ir::TyData::Alias(alias_ty) => match alias_ty {
494+
chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::ProjectionTy {
495+
item_def_id: projection.associated_ty_id.0,
496+
substs: projection.substitution.lower_into(interner),
497+
}),
498+
chalk_ir::AliasTy::Opaque(opaque) => {
499+
ty::Opaque(opaque.opaque_ty_id.0, opaque.substitution.lower_into(interner))
500+
}
501+
},
487502
TyData::Function(_quantified_ty) => unimplemented!(),
488503
TyData::BoundVar(_bound) => ty::Bound(
489504
ty::DebruijnIndex::from_usize(_bound.debruijn.depth() as usize),
@@ -519,8 +534,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
519534
ty::BrEnv => unimplemented!(),
520535
},
521536
ReFree(_) => unimplemented!(),
522-
// FIXME(chalk): need to handle ReStatic
523-
ReStatic => unimplemented!(),
537+
ReStatic => chalk_ir::LifetimeData::Static.intern(interner),
524538
ReVar(_) => unimplemented!(),
525539
RePlaceholder(placeholder_region) => {
526540
chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex {
@@ -550,6 +564,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
550564
name: ty::BoundRegion::BrAnon(p.idx as u32),
551565
})
552566
}
567+
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
553568
chalk_ir::LifetimeData::Phantom(_, _) => unimplemented!(),
554569
};
555570
interner.tcx.mk_region(kind)
@@ -701,7 +716,16 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
701716
}),
702717
)
703718
}
704-
ty::ExistentialPredicate::Projection(_predicate) => unimplemented!(),
719+
ty::ExistentialPredicate::Projection(predicate) => chalk_ir::Binders::new(
720+
chalk_ir::VariableKinds::empty(interner),
721+
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
722+
alias: chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
723+
associated_ty_id: chalk_ir::AssocTypeId(predicate.item_def_id),
724+
substitution: predicate.substs.lower_into(interner),
725+
}),
726+
ty: predicate.ty.lower_into(interner),
727+
}),
728+
),
705729
ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new(
706730
chalk_ir::VariableKinds::empty(interner),
707731
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
@@ -1035,17 +1059,12 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
10351059
/// Used to substitute specific `Regions`s with placeholders.
10361060
crate struct RegionsSubstitutor<'tcx> {
10371061
tcx: TyCtxt<'tcx>,
1038-
restatic_placeholder: ty::Region<'tcx>,
10391062
reempty_placeholder: ty::Region<'tcx>,
10401063
}
10411064

10421065
impl<'tcx> RegionsSubstitutor<'tcx> {
1043-
crate fn new(
1044-
tcx: TyCtxt<'tcx>,
1045-
restatic_placeholder: ty::Region<'tcx>,
1046-
reempty_placeholder: ty::Region<'tcx>,
1047-
) -> Self {
1048-
RegionsSubstitutor { tcx, restatic_placeholder, reempty_placeholder }
1066+
crate fn new(tcx: TyCtxt<'tcx>, reempty_placeholder: ty::Region<'tcx>) -> Self {
1067+
RegionsSubstitutor { tcx, reempty_placeholder }
10491068
}
10501069
}
10511070

@@ -1056,7 +1075,6 @@ impl<'tcx> TypeFolder<'tcx> for RegionsSubstitutor<'tcx> {
10561075

10571076
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
10581077
match r {
1059-
ty::ReStatic => self.restatic_placeholder,
10601078
ty::ReEmpty(ui) => {
10611079
assert_eq!(ui.as_usize(), 0);
10621080
self.reempty_placeholder

compiler/rustc_traits/src/chalk/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ crate fn evaluate_goal<'tcx>(
4242
let mut placeholders_collector = PlaceholdersCollector::new();
4343
obligation.visit_with(&mut placeholders_collector);
4444

45-
let restatic_placeholder = tcx.mk_region(ty::RegionKind::RePlaceholder(ty::Placeholder {
46-
universe: ty::UniverseIndex::ROOT,
47-
name: ty::BoundRegion::BrAnon(placeholders_collector.next_anon_region_placeholder),
48-
}));
4945
let reempty_placeholder = tcx.mk_region(ty::RegionKind::RePlaceholder(ty::Placeholder {
5046
universe: ty::UniverseIndex::ROOT,
5147
name: ty::BoundRegion::BrAnon(placeholders_collector.next_anon_region_placeholder + 1),
@@ -57,8 +53,7 @@ crate fn evaluate_goal<'tcx>(
5753
// FIXME(chalk): we really should be substituting these back in the solution
5854
let _params: FxHashMap<usize, ParamTy> = params_substitutor.params;
5955

60-
let mut regions_substitutor =
61-
RegionsSubstitutor::new(tcx, restatic_placeholder, reempty_placeholder);
56+
let mut regions_substitutor = RegionsSubstitutor::new(tcx, reempty_placeholder);
6257
let obligation = obligation.fold_with(&mut regions_substitutor);
6358

6459
let max_universe = obligation.max_universe.index();
@@ -101,7 +96,7 @@ crate fn evaluate_goal<'tcx>(
10196

10297
use chalk_solve::Solver;
10398
let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
104-
let db = ChalkRustIrDatabase { interner, restatic_placeholder, reempty_placeholder };
99+
let db = ChalkRustIrDatabase { interner, reempty_placeholder };
105100
let solution = chalk_solve::logging::with_tracing_logs(|| solver.solve(&db, &lowered_goal));
106101

107102
// Ideally, the code to convert *back* to rustc types would live close to

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// NOTE: rustc cannot currently handle bounds of the form `for<'a> <Foo as Bar<'a>>::Assoc: Baz`.
22
// This should hopefully be fixed with Chalk.
3+
// ignore-compare-mode-chalk
34

45
#![feature(associated_type_bounds)]
56

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: `<L1 as Lam<&'a u8>>::App` doesn't implement `Debug`
2-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:29:6
2+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:30:6
33
|
44
LL | trait Case1 {
55
| ----- required by a bound in this
@@ -13,7 +13,7 @@ LL | impl Case1 for S1 {
1313
= help: the trait `for<'a> Debug` is not implemented for `<L1 as Lam<&'a u8>>::App`
1414

1515
error[E0277]: `<<T as Case1>::C as Iterator>::Item` is not an iterator
16-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:34:20
16+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:35:20
1717
|
1818
LL | fn assume_case1<T: Case1>() {
1919
| ^^^^^ `<<T as Case1>::C as Iterator>::Item` is not an iterator
@@ -25,7 +25,7 @@ LL | fn assume_case1<T: Case1>() where <<T as Case1>::C as Iterator>::Item: Iter
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626

2727
error[E0277]: `<<T as Case1>::C as Iterator>::Item` cannot be sent between threads safely
28-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:34:20
28+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:35:20
2929
|
3030
LL | trait Case1 {
3131
| ----- required by a bound in this
@@ -43,7 +43,7 @@ LL | fn assume_case1<T: Case1>() where <<T as Case1>::C as Iterator>::Item: Send
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

4545
error[E0277]: `<<T as Case1>::C as Iterator>::Item` cannot be shared between threads safely
46-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:34:20
46+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:35:20
4747
|
4848
LL | trait Case1 {
4949
| ----- required by a bound in this
@@ -61,7 +61,7 @@ LL | fn assume_case1<T: Case1>() where <<T as Case1>::C as Iterator>::Item: Sync
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6262

6363
error[E0277]: `<_ as Lam<&'a u8>>::App` doesn't implement `Debug`
64-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:34:20
64+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:35:20
6565
|
6666
LL | trait Case1 {
6767
| ----- required by a bound in this

src/test/ui/associated-type-bounds/trait-params.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// build-pass (FIXME(62277): could be check-pass?)
2+
// ignore-compare-mode-chalk
23

34
#![feature(associated_type_bounds)]
45

src/test/ui/associated-type-bounds/union-bounds.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-pass
2+
// ignore-compare-mode-chalk
23

34
#![feature(associated_type_bounds)]
45
#![feature(untagged_unions)]

src/test/ui/associated-types/associated-types-stream.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22
// Test references to the trait `Stream` in the bounds for associated
33
// types defined on `Stream`. Issue #20551.
4+
// ignore-compare-mode-chalk
45

56

67
trait Stream {

src/test/ui/associated-types/hr-associated-type-bound-param-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-compare-mode-chalk
12
trait Z<'a, T: ?Sized>
23
where
34
T: Z<'a, u16>,

src/test/ui/associated-types/hr-associated-type-bound-param-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: Clone` is not satisfied
2-
--> $DIR/hr-associated-type-bound-param-2.rs:3:8
2+
--> $DIR/hr-associated-type-bound-param-2.rs:4:8
33
|
44
LL | trait Z<'a, T: ?Sized>
55
| - required by a bound in this
@@ -15,7 +15,7 @@ LL | for<'b> <T as Z<'b, u16>>::W: Clone,
1515
<&mut T as Clone>
1616

1717
error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: Clone` is not satisfied
18-
--> $DIR/hr-associated-type-bound-param-2.rs:15:14
18+
--> $DIR/hr-associated-type-bound-param-2.rs:16:14
1919
|
2020
LL | trait Z<'a, T: ?Sized>
2121
| - required by a bound in this
@@ -31,7 +31,7 @@ LL | type W = str;
3131
<&mut T as Clone>
3232

3333
error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: Clone` is not satisfied
34-
--> $DIR/hr-associated-type-bound-param-2.rs:3:8
34+
--> $DIR/hr-associated-type-bound-param-2.rs:4:8
3535
|
3636
LL | trait Z<'a, T: ?Sized>
3737
| - required by a bound in this

0 commit comments

Comments
 (0)