Skip to content

Update to chalk 0.31 #77515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ dependencies = [

[[package]]
name = "chalk-derive"
version = "0.29.0"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a7f257e3bcdc56d8877ae31c012bd69fba0be66929d588e603905f2632c0c59"
checksum = "ca40c97e20f43e4aac2282d342103d45fafad74ad9bfcbaaf0b5d386f9ce1f39"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -454,9 +454,9 @@ dependencies = [

[[package]]
name = "chalk-engine"
version = "0.29.0"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c43fcc7edf4d51b42f44ed50e2337bd90ddc8e088d0cd78a71db92a6f780f782"
checksum = "88e3d545394fbc4f7d8fe203c6a78d2b73f82bb119f21af98de1f924c2518e34"
dependencies = [
"chalk-derive",
"chalk-ir",
Expand All @@ -467,19 +467,19 @@ dependencies = [

[[package]]
name = "chalk-ir"
version = "0.29.0"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a4050029ecb2b5a1ff3bfc64c39279179b294821ec2e8891a4a5c6e3a08db0"
checksum = "8c4183955e084fcc387b515f867ed0e17e9e7301f5eee29c0338d5e63315bb41"
dependencies = [
"chalk-derive",
"lazy_static",
]

[[package]]
name = "chalk-solve"
version = "0.29.0"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "828c1f80d4eaf681027cce02050c54a3c97370f81988d31bf2a56df54048746c"
checksum = "50e8407bba06d9e760011a28060e8f3b3f87b82ea53fb8bfaa43614c19c14dcc"
dependencies = [
"chalk-derive",
"chalk-ir",
Expand Down Expand Up @@ -5121,9 +5121,9 @@ dependencies = [

[[package]]
name = "tracing-serde"
version = "0.1.1"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79"
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
dependencies = [
"serde",
"tracing-core",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rustc_index = { path = "../rustc_index" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
chalk-ir = "0.29.0"
chalk-ir = "0.31.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
measureme = "0.7.1"
rustc_session = { path = "../rustc_session" }
6 changes: 3 additions & 3 deletions compiler/rustc_traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
chalk-ir = "0.29.0"
chalk-solve = "0.29.0"
chalk-engine = "0.29.0"
chalk-ir = "0.31.0"
chalk-solve = "0.31.0"
chalk-engine = "0.31.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_infer = { path = "../rustc_infer" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
36 changes: 20 additions & 16 deletions compiler/rustc_traits/src/chalk/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use rustc_ast::ast;

pub struct RustIrDatabase<'tcx> {
pub(crate) interner: RustInterner<'tcx>,
pub(crate) restatic_placeholder: ty::Region<'tcx>,
pub(crate) reempty_placeholder: ty::Region<'tcx>,
}

Expand All @@ -39,11 +38,8 @@ impl<'tcx> RustIrDatabase<'tcx> {
bound_vars: SubstsRef<'tcx>,
) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
let predicates = self.interner.tcx.predicates_of(def_id).predicates;
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
self.interner.tcx,
self.restatic_placeholder,
self.reempty_placeholder,
);
let mut regions_substitutor =
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
predicates
.iter()
.map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars))
Expand Down Expand Up @@ -274,11 +270,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t

let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
self.interner.tcx,
self.restatic_placeholder,
self.reempty_placeholder,
);
let mut regions_substitutor =
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
let trait_ref = trait_ref.fold_with(&mut regions_substitutor);

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

let self_ty = trait_ref.self_ty();
let self_ty = self_ty.subst(self.interner.tcx, bound_vars);
let mut regions_substitutor = lowering::RegionsSubstitutor::new(
self.interner.tcx,
self.restatic_placeholder,
self.reempty_placeholder,
);
let mut regions_substitutor =
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
let self_ty = self_ty.fold_with(&mut regions_substitutor);
let lowered_ty = self_ty.lower_into(&self.interner);

Expand Down Expand Up @@ -590,6 +580,20 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let substitution = &substs.as_slice(&self.interner)[0..substs.len(&self.interner) - 3];
chalk_ir::Substitution::from_iter(&self.interner, substitution)
}

fn generator_datum(
&self,
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<RustInterner<'tcx>>> {
unimplemented!()
}

fn generator_witness_datum(
&self,
_generator_id: chalk_ir::GeneratorId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<RustInterner<'tcx>>> {
unimplemented!()
}
}

/// Creates a `InternalSubsts` that maps each generic parameter to a higher-ranked
Expand Down
44 changes: 31 additions & 13 deletions compiler/rustc_traits/src/chalk/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,20 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
chalk_ir::FloatTy::F64 => ty::Float(ast::FloatTy::F64),
},
},
chalk_ir::TypeName::Array => unimplemented!(),
chalk_ir::TypeName::Array => {
let substs = application_ty.substitution.as_slice(interner);
let ty = substs[0].assert_ty_ref(interner).lower_into(interner);
let c = substs[1].assert_const_ref(interner).lower_into(interner);
ty::Array(ty, interner.tcx.mk_const(c))
}
chalk_ir::TypeName::FnDef(id) => {
ty::FnDef(id.0, application_ty.substitution.lower_into(interner))
}
chalk_ir::TypeName::Closure(closure) => {
ty::Closure(closure.0, application_ty.substitution.lower_into(interner))
}
chalk_ir::TypeName::Generator(_) => unimplemented!(),
chalk_ir::TypeName::GeneratorWitness(_) => unimplemented!(),
chalk_ir::TypeName::Never => ty::Never,
chalk_ir::TypeName::Tuple(_size) => {
ty::Tuple(application_ty.substitution.lower_into(interner))
Expand Down Expand Up @@ -483,7 +490,15 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
universe: ty::UniverseIndex::from_usize(placeholder.ui.counter),
name: ty::BoundVar::from_usize(placeholder.idx),
}),
TyData::Alias(_alias_ty) => unimplemented!(),
chalk_ir::TyData::Alias(alias_ty) => match alias_ty {
chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::ProjectionTy {
item_def_id: projection.associated_ty_id.0,
substs: projection.substitution.lower_into(interner),
}),
chalk_ir::AliasTy::Opaque(opaque) => {
ty::Opaque(opaque.opaque_ty_id.0, opaque.substitution.lower_into(interner))
}
},
TyData::Function(_quantified_ty) => unimplemented!(),
TyData::BoundVar(_bound) => ty::Bound(
ty::DebruijnIndex::from_usize(_bound.debruijn.depth() as usize),
Expand Down Expand Up @@ -519,8 +534,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
ty::BrEnv => unimplemented!(),
},
ReFree(_) => unimplemented!(),
// FIXME(chalk): need to handle ReStatic
ReStatic => unimplemented!(),
ReStatic => chalk_ir::LifetimeData::Static.intern(interner),
ReVar(_) => unimplemented!(),
RePlaceholder(placeholder_region) => {
chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex {
Expand Down Expand Up @@ -550,6 +564,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
name: ty::BoundRegion::BrAnon(p.idx as u32),
})
}
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
chalk_ir::LifetimeData::Phantom(_, _) => unimplemented!(),
};
interner.tcx.mk_region(kind)
Expand Down Expand Up @@ -701,7 +716,16 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
}),
)
}
ty::ExistentialPredicate::Projection(_predicate) => unimplemented!(),
ty::ExistentialPredicate::Projection(predicate) => chalk_ir::Binders::new(
chalk_ir::VariableKinds::empty(interner),
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
alias: chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
associated_ty_id: chalk_ir::AssocTypeId(predicate.item_def_id),
substitution: predicate.substs.lower_into(interner),
}),
ty: predicate.ty.lower_into(interner),
}),
),
ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new(
chalk_ir::VariableKinds::empty(interner),
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
Expand Down Expand Up @@ -1116,17 +1140,12 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
/// Used to substitute specific `Regions`s with placeholders.
crate struct RegionsSubstitutor<'tcx> {
tcx: TyCtxt<'tcx>,
restatic_placeholder: ty::Region<'tcx>,
reempty_placeholder: ty::Region<'tcx>,
}

impl<'tcx> RegionsSubstitutor<'tcx> {
crate fn new(
tcx: TyCtxt<'tcx>,
restatic_placeholder: ty::Region<'tcx>,
reempty_placeholder: ty::Region<'tcx>,
) -> Self {
RegionsSubstitutor { tcx, restatic_placeholder, reempty_placeholder }
crate fn new(tcx: TyCtxt<'tcx>, reempty_placeholder: ty::Region<'tcx>) -> Self {
RegionsSubstitutor { tcx, reempty_placeholder }
}
}

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

fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
match r {
ty::ReStatic => self.restatic_placeholder,
ty::ReEmpty(ui) => {
assert_eq!(ui.as_usize(), 0);
self.reempty_placeholder
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_traits/src/chalk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ crate fn evaluate_goal<'tcx>(
let mut placeholders_collector = PlaceholdersCollector::new();
obligation.visit_with(&mut placeholders_collector);

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

let mut regions_substitutor =
RegionsSubstitutor::new(tcx, restatic_placeholder, reempty_placeholder);
let mut regions_substitutor = RegionsSubstitutor::new(tcx, reempty_placeholder);
let obligation = obligation.fold_with(&mut regions_substitutor);

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

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

// Ideally, the code to convert *back* to rustc types would live close to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// NOTE: rustc cannot currently handle bounds of the form `for<'a> <Foo as Bar<'a>>::Assoc: Baz`.
// This should hopefully be fixed with Chalk.
// ignore-compare-mode-chalk

#![feature(associated_type_bounds)]

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

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

error[E0277]: `<<Self as Case1>::C as Iterator>::Item` cannot be shared between threads safely
--> $DIR/bad-bounds-on-assoc-in-trait.rs:26:93
--> $DIR/bad-bounds-on-assoc-in-trait.rs:27:93
|
LL | type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
| ^^^^ `<<Self as Case1>::C as Iterator>::Item` cannot be shared between threads safely
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/associated-type-bounds/trait-params.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// build-pass (FIXME(62277): could be check-pass?)
// ignore-compare-mode-chalk

#![feature(associated_type_bounds)]

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/associated-type-bounds/union-bounds.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-pass
// ignore-compare-mode-chalk

#![feature(associated_type_bounds)]
#![feature(untagged_unions)]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/associated-types/associated-types-stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-pass
// Test references to the trait `Stream` in the bounds for associated
// types defined on `Stream`. Issue #20551.
// ignore-compare-mode-chalk


trait Stream {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore-compare-mode-chalk
trait Z<'a, T: ?Sized>
where
T: Z<'a, u16>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: Clone` is not satisfied
--> $DIR/hr-associated-type-bound-param-2.rs:3:8
--> $DIR/hr-associated-type-bound-param-2.rs:4:8
|
LL | trait Z<'a, T: ?Sized>
| - required by a bound in this
Expand All @@ -15,7 +15,7 @@ LL | for<'b> <T as Z<'b, u16>>::W: Clone,
<&mut T as Clone>

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

error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: Clone` is not satisfied
--> $DIR/hr-associated-type-bound-param-2.rs:3:8
--> $DIR/hr-associated-type-bound-param-2.rs:4:8
|
LL | trait Z<'a, T: ?Sized>
| - required by a bound in this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore-compare-mode-chalk
trait Cycle: Sized {
type Next: Cycle<Next = Self>;
}
Expand Down
Loading