Skip to content

Commit 2349108

Browse files
committed
Update to chalk 0.31. Implement some unimplemented. Ignore some tests in compare mode chalk don't finish.
1 parent 08e2d46 commit 2349108

Some content is hidden

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

44 files changed

+143
-99
lines changed

Cargo.lock

+10-10
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ dependencies = [
442442

443443
[[package]]
444444
name = "chalk-derive"
445-
version = "0.29.0"
445+
version = "0.31.0"
446446
source = "registry+https://github.com/rust-lang/crates.io-index"
447-
checksum = "3a7f257e3bcdc56d8877ae31c012bd69fba0be66929d588e603905f2632c0c59"
447+
checksum = "ca40c97e20f43e4aac2282d342103d45fafad74ad9bfcbaaf0b5d386f9ce1f39"
448448
dependencies = [
449449
"proc-macro2",
450450
"quote",
@@ -454,9 +454,9 @@ dependencies = [
454454

455455
[[package]]
456456
name = "chalk-engine"
457-
version = "0.29.0"
457+
version = "0.31.0"
458458
source = "registry+https://github.com/rust-lang/crates.io-index"
459-
checksum = "c43fcc7edf4d51b42f44ed50e2337bd90ddc8e088d0cd78a71db92a6f780f782"
459+
checksum = "88e3d545394fbc4f7d8fe203c6a78d2b73f82bb119f21af98de1f924c2518e34"
460460
dependencies = [
461461
"chalk-derive",
462462
"chalk-ir",
@@ -467,19 +467,19 @@ dependencies = [
467467

468468
[[package]]
469469
name = "chalk-ir"
470-
version = "0.29.0"
470+
version = "0.31.0"
471471
source = "registry+https://github.com/rust-lang/crates.io-index"
472-
checksum = "03a4050029ecb2b5a1ff3bfc64c39279179b294821ec2e8891a4a5c6e3a08db0"
472+
checksum = "8c4183955e084fcc387b515f867ed0e17e9e7301f5eee29c0338d5e63315bb41"
473473
dependencies = [
474474
"chalk-derive",
475475
"lazy_static",
476476
]
477477

478478
[[package]]
479479
name = "chalk-solve"
480-
version = "0.29.0"
480+
version = "0.31.0"
481481
source = "registry+https://github.com/rust-lang/crates.io-index"
482-
checksum = "828c1f80d4eaf681027cce02050c54a3c97370f81988d31bf2a56df54048746c"
482+
checksum = "50e8407bba06d9e760011a28060e8f3b3f87b82ea53fb8bfaa43614c19c14dcc"
483483
dependencies = [
484484
"chalk-derive",
485485
"chalk-ir",
@@ -5121,9 +5121,9 @@ dependencies = [
51215121

51225122
[[package]]
51235123
name = "tracing-serde"
5124-
version = "0.1.1"
5124+
version = "0.1.2"
51255125
source = "registry+https://github.com/rust-lang/crates.io-index"
5126-
checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79"
5126+
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
51275127
dependencies = [
51285128
"serde",
51295129
"tracing-core",

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))
@@ -274,11 +270,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
274270

275271
let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
276272
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
277-
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
278-
self.interner.tcx,
279-
self.restatic_placeholder,
280-
self.reempty_placeholder,
281-
);
273+
let mut regions_substitutor =
274+
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
282275
let trait_ref = trait_ref.fold_with(&mut regions_substitutor);
283276

284277
let where_clauses = self.where_clauses_for(def_id, bound_vars);
@@ -316,11 +309,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
316309

317310
let self_ty = trait_ref.self_ty();
318311
let self_ty = self_ty.subst(self.interner.tcx, bound_vars);
319-
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
320-
self.interner.tcx,
321-
self.restatic_placeholder,
322-
self.reempty_placeholder,
323-
);
312+
let mut regions_substitutor =
313+
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
324314
let self_ty = self_ty.fold_with(&mut regions_substitutor);
325315
let lowered_ty = self_ty.lower_into(&self.interner);
326316

@@ -590,6 +580,20 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
590580
let substitution = &substs.as_slice(&self.interner)[0..substs.len(&self.interner) - 3];
591581
chalk_ir::Substitution::from_iter(&self.interner, substitution)
592582
}
583+
584+
fn generator_datum(
585+
&self,
586+
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
587+
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<RustInterner<'tcx>>> {
588+
unimplemented!()
589+
}
590+
591+
fn generator_witness_datum(
592+
&self,
593+
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
594+
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<RustInterner<'tcx>>> {
595+
unimplemented!()
596+
}
593597
}
594598

595599
/// 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 {
@@ -1116,17 +1140,12 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
11161140
/// Used to substitute specific `Regions`s with placeholders.
11171141
crate struct RegionsSubstitutor<'tcx> {
11181142
tcx: TyCtxt<'tcx>,
1119-
restatic_placeholder: ty::Region<'tcx>,
11201143
reempty_placeholder: ty::Region<'tcx>,
11211144
}
11221145

11231146
impl<'tcx> RegionsSubstitutor<'tcx> {
1124-
crate fn new(
1125-
tcx: TyCtxt<'tcx>,
1126-
restatic_placeholder: ty::Region<'tcx>,
1127-
reempty_placeholder: ty::Region<'tcx>,
1128-
) -> Self {
1129-
RegionsSubstitutor { tcx, restatic_placeholder, reempty_placeholder }
1147+
crate fn new(tcx: TyCtxt<'tcx>, reempty_placeholder: ty::Region<'tcx>) -> Self {
1148+
RegionsSubstitutor { tcx, reempty_placeholder }
11301149
}
11311150
}
11321151

@@ -1137,7 +1156,6 @@ impl<'tcx> TypeFolder<'tcx> for RegionsSubstitutor<'tcx> {
11371156

11381157
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
11391158
match r {
1140-
ty::ReStatic => self.restatic_placeholder,
11411159
ty::ReEmpty(ui) => {
11421160
assert_eq!(ui.as_usize(), 0);
11431161
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: `<<Self as Case1>::C as Iterator>::Item` is not an iterator
2-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:26:5
2+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:27:5
33
|
44
LL | type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `<<Self as Case1>::C as Iterator>::Item` is not an iterator
@@ -11,7 +11,7 @@ LL | trait Case1 where <<Self as Case1>::C as Iterator>::Item: Iterator {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error[E0277]: `<<Self as Case1>::C as Iterator>::Item` cannot be sent between threads safely
14-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:26:36
14+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:27:36
1515
|
1616
LL | type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
1717
| ^^^^ `<<Self as Case1>::C as Iterator>::Item` cannot be sent between threads safely
@@ -28,7 +28,7 @@ LL | trait Case1 where <<Self as Case1>::C as Iterator>::Item: Send {
2828
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2929

3030
error[E0277]: `<<Self as Case1>::C as Iterator>::Item` cannot be shared between threads safely
31-
--> $DIR/bad-bounds-on-assoc-in-trait.rs:26:93
31+
--> $DIR/bad-bounds-on-assoc-in-trait.rs:27:93
3232
|
3333
LL | type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
3434
| ^^^^ `<<Self as Case1>::C as Iterator>::Item` cannot be shared between threads safely

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-compare-mode-chalk
12
trait Cycle: Sized {
23
type Next: Cycle<Next = Self>;
34
}

0 commit comments

Comments
 (0)