Skip to content

Commit 806a8f6

Browse files
authored
Rollup merge of rust-lang#80593 - jackh726:chalk-upgrade, r=nikomatsakis
Upgrade Chalk ~~Blocked on rust-lang/chalk#670~~ ~~Now blocked on rust-lang/chalk#680 and release~~ In addition to the straight upgrade, I also tried to fix some tests by properly returning variables and max universes in the solution. Unfortunately, this actually triggers the same perf problem that rustc traits code runs into in `canonicalizer`. Not sure what the root cause of this problem is, or why it's supposed to be solved in chalk. r? ``@nikomatsakis``
2 parents 3182375 + a0622d6 commit 806a8f6

File tree

8 files changed

+174
-39
lines changed

8 files changed

+174
-39
lines changed

Cargo.lock

+10-8
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
496496

497497
[[package]]
498498
name = "chalk-derive"
499-
version = "0.36.0"
499+
version = "0.55.0"
500500
source = "registry+https://github.com/rust-lang/crates.io-index"
501-
checksum = "9f88ce4deae1dace71e49b7611cfae2d5489de3530d6daba5758043c47ac3a10"
501+
checksum = "3983193cacd81f0f924acb666b7fe5e1a0d81db9f113fa69203eda7ea8ce8b6c"
502502
dependencies = [
503503
"proc-macro2",
504504
"quote",
@@ -508,9 +508,9 @@ dependencies = [
508508

509509
[[package]]
510510
name = "chalk-engine"
511-
version = "0.36.0"
511+
version = "0.55.0"
512512
source = "registry+https://github.com/rust-lang/crates.io-index"
513-
checksum = "0e34c9b1b10616782143d7f49490f91ae94afaf2202de3ab0b2835e78b4f0ccc"
513+
checksum = "05a171ce5abbf0fbd06f221ab80ab182c7ef78603d23b858bc44e7ce8a86a396"
514514
dependencies = [
515515
"chalk-derive",
516516
"chalk-ir",
@@ -521,19 +521,20 @@ dependencies = [
521521

522522
[[package]]
523523
name = "chalk-ir"
524-
version = "0.36.0"
524+
version = "0.55.0"
525525
source = "registry+https://github.com/rust-lang/crates.io-index"
526-
checksum = "63362c629c2014ab639b04029070763fb8224df136d1363d30e9ece4c8877da3"
526+
checksum = "a522f53af971e7678f472d687e053120157b3ae26e2ebd5ecbc0f5ab124f2cb6"
527527
dependencies = [
528+
"bitflags",
528529
"chalk-derive",
529530
"lazy_static",
530531
]
531532

532533
[[package]]
533534
name = "chalk-solve"
534-
version = "0.36.0"
535+
version = "0.55.0"
535536
source = "registry+https://github.com/rust-lang/crates.io-index"
536-
checksum = "cac338a67af52a7f50bb2f8232e730a3518ce432dbe303246acfe525ddd838c7"
537+
checksum = "cdf79fb77a567e456a170f7ec84ea6584163d4ba3f13660cd182013d34ca667c"
537538
dependencies = [
538539
"chalk-derive",
539540
"chalk-ir",
@@ -4313,6 +4314,7 @@ dependencies = [
43134314
"chalk-ir",
43144315
"chalk-solve",
43154316
"rustc_ast",
4317+
"rustc_attr",
43164318
"rustc_data_structures",
43174319
"rustc_hir",
43184320
"rustc_index",

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
353353
// `TyVar(vid)` is unresolved, track its universe index in the canonicalized
354354
// result.
355355
Err(mut ui) => {
356-
if !self.infcx.unwrap().tcx.sess.opts.debugging_opts.chalk {
357-
// FIXME: perf problem described in #55921.
358-
ui = ty::UniverseIndex::ROOT;
359-
}
356+
// FIXME: perf problem described in #55921.
357+
ui = ty::UniverseIndex::ROOT;
360358
self.canonicalize_ty_var(
361359
CanonicalVarInfo {
362360
kind: CanonicalVarKind::Ty(CanonicalTyVarKind::General(ui)),
@@ -440,10 +438,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
440438
// `ConstVar(vid)` is unresolved, track its universe index in the
441439
// canonicalized result
442440
Err(mut ui) => {
443-
if !self.infcx.unwrap().tcx.sess.opts.debugging_opts.chalk {
444-
// FIXME: perf problem described in #55921.
445-
ui = ty::UniverseIndex::ROOT;
446-
}
441+
// FIXME: perf problem described in #55921.
442+
ui = ty::UniverseIndex::ROOT;
447443
return self.canonicalize_const_var(
448444
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui) },
449445
ct,

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.36.0"
29+
chalk-ir = "0.55.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

+36-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
7272
type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
7373
type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
7474
type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
75+
type InternedVariances = Vec<chalk_ir::Variance>;
7576
type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
7677
type DefId = DefId;
7778
type InternedAdtId = &'tcx AdtDef;
@@ -86,17 +87,34 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
8687
write!(fmt, "{:?}", pci.consequence)?;
8788

8889
let conditions = pci.conditions.interned();
90+
let constraints = pci.constraints.interned();
8991

9092
let conds = conditions.len();
91-
if conds == 0 {
93+
let consts = constraints.len();
94+
if conds == 0 && consts == 0 {
9295
return Ok(());
9396
}
9497

9598
write!(fmt, " :- ")?;
96-
for cond in &conditions[..conds - 1] {
97-
write!(fmt, "{:?}, ", cond)?;
99+
100+
if conds != 0 {
101+
for cond in &conditions[..conds - 1] {
102+
write!(fmt, "{:?}, ", cond)?;
103+
}
104+
write!(fmt, "{:?}", conditions[conds - 1])?;
105+
}
106+
107+
if conds != 0 && consts != 0 {
108+
write!(fmt, " ; ")?;
98109
}
99-
write!(fmt, "{:?}", conditions[conds - 1])?;
110+
111+
if consts != 0 {
112+
for constraint in &constraints[..consts - 1] {
113+
write!(fmt, "{:?}, ", constraint)?;
114+
}
115+
write!(fmt, "{:?}", constraints[consts - 1])?;
116+
}
117+
100118
Ok(())
101119
};
102120
Some(write())
@@ -351,6 +369,20 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
351369
) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
352370
constraints
353371
}
372+
373+
fn intern_variances<E>(
374+
&self,
375+
data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>,
376+
) -> Result<Self::InternedVariances, E> {
377+
data.into_iter().collect::<Result<Vec<_>, _>>()
378+
}
379+
380+
fn variances_data<'a>(
381+
&self,
382+
variances: &'a Self::InternedVariances,
383+
) -> &'a [chalk_ir::Variance] {
384+
variances
385+
}
354386
}
355387

356388
impl<'tcx> chalk_ir::interner::HasInterner for RustInterner<'tcx> {

compiler/rustc_traits/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ edition = "2018"
66

77
[dependencies]
88
tracing = "0.1"
9+
rustc_attr = { path = "../rustc_attr" }
910
rustc_middle = { path = "../rustc_middle" }
1011
rustc_data_structures = { path = "../rustc_data_structures" }
1112
rustc_hir = { path = "../rustc_hir" }
1213
rustc_index = { path = "../rustc_index" }
1314
rustc_ast = { path = "../rustc_ast" }
1415
rustc_span = { path = "../rustc_span" }
15-
chalk-ir = "0.36.0"
16-
chalk-solve = "0.36.0"
17-
chalk-engine = "0.36.0"
16+
chalk-ir = "0.55.0"
17+
chalk-solve = "0.55.0"
18+
chalk-engine = "0.55.0"
1819
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
1920
rustc_infer = { path = "../rustc_infer" }
2021
rustc_trait_selection = { path = "../rustc_trait_selection" }

compiler/rustc_traits/src/chalk/db.rs

+80-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use rustc_middle::traits::ChalkRustInterner as RustInterner;
1010
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
1111
use rustc_middle::ty::{self, AssocItemContainer, AssocKind, TyCtxt, TypeFoldable};
1212

13+
use rustc_ast::ast;
14+
use rustc_attr as attr;
15+
1316
use rustc_hir::def_id::DefId;
1417

1518
use rustc_span::symbol::sym;
@@ -18,7 +21,6 @@ use std::fmt;
1821
use std::sync::Arc;
1922

2023
use crate::chalk::lowering::{self, LowerInto};
21-
use rustc_ast::ast;
2224

2325
pub struct RustIrDatabase<'tcx> {
2426
pub(crate) interner: RustInterner<'tcx>,
@@ -205,12 +207,32 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
205207
fn adt_repr(
206208
&self,
207209
adt_id: chalk_ir::AdtId<RustInterner<'tcx>>,
208-
) -> chalk_solve::rust_ir::AdtRepr {
210+
) -> Arc<chalk_solve::rust_ir::AdtRepr<RustInterner<'tcx>>> {
209211
let adt_def = adt_id.0;
210-
chalk_solve::rust_ir::AdtRepr {
211-
repr_c: adt_def.repr.c(),
212-
repr_packed: adt_def.repr.packed(),
213-
}
212+
let int = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(i)).intern(&self.interner);
213+
let uint = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(i)).intern(&self.interner);
214+
Arc::new(chalk_solve::rust_ir::AdtRepr {
215+
c: adt_def.repr.c(),
216+
packed: adt_def.repr.packed(),
217+
int: adt_def.repr.int.map(|i| match i {
218+
attr::IntType::SignedInt(ty) => match ty {
219+
ast::IntTy::Isize => int(chalk_ir::IntTy::Isize),
220+
ast::IntTy::I8 => int(chalk_ir::IntTy::I8),
221+
ast::IntTy::I16 => int(chalk_ir::IntTy::I16),
222+
ast::IntTy::I32 => int(chalk_ir::IntTy::I32),
223+
ast::IntTy::I64 => int(chalk_ir::IntTy::I64),
224+
ast::IntTy::I128 => int(chalk_ir::IntTy::I128),
225+
},
226+
attr::IntType::UnsignedInt(ty) => match ty {
227+
ast::UintTy::Usize => uint(chalk_ir::UintTy::Usize),
228+
ast::UintTy::U8 => uint(chalk_ir::UintTy::U8),
229+
ast::UintTy::U16 => uint(chalk_ir::UintTy::U16),
230+
ast::UintTy::U32 => uint(chalk_ir::UintTy::U32),
231+
ast::UintTy::U64 => uint(chalk_ir::UintTy::U64),
232+
ast::UintTy::U128 => uint(chalk_ir::UintTy::U128),
233+
},
234+
}),
235+
})
214236
}
215237

216238
fn fn_def_datum(
@@ -316,7 +338,11 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
316338
let self_ty = self_ty.fold_with(&mut regions_substitutor);
317339
let lowered_ty = self_ty.lower_into(&self.interner);
318340

319-
parameters[0].assert_ty_ref(&self.interner).could_match(&self.interner, &lowered_ty)
341+
parameters[0].assert_ty_ref(&self.interner).could_match(
342+
&self.interner,
343+
self.unification_database(),
344+
&lowered_ty,
345+
)
320346
});
321347

322348
let impls = matched_impls.map(chalk_ir::ImplId).collect();
@@ -541,6 +567,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
541567
Unsize => lang_items.unsize_trait(),
542568
Unpin => lang_items.unpin_trait(),
543569
CoerceUnsized => lang_items.coerce_unsized_trait(),
570+
DiscriminantKind => lang_items.discriminant_kind_trait(),
544571
};
545572
def_id.map(chalk_ir::TraitId)
546573
}
@@ -586,7 +613,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
586613
let sig = &substs.as_slice(&self.interner)[substs.len(&self.interner) - 2];
587614
match sig.assert_ty_ref(&self.interner).kind(&self.interner) {
588615
chalk_ir::TyKind::Function(f) => {
589-
let substitution = f.substitution.as_slice(&self.interner);
616+
let substitution = f.substitution.0.as_slice(&self.interner);
590617
let return_type =
591618
substitution.last().unwrap().assert_ty_ref(&self.interner).clone();
592619
// Closure arguments are tupled
@@ -644,6 +671,51 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
644671
) -> Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<RustInterner<'tcx>>> {
645672
unimplemented!()
646673
}
674+
675+
fn unification_database(&self) -> &dyn chalk_ir::UnificationDatabase<RustInterner<'tcx>> {
676+
self
677+
}
678+
679+
fn discriminant_type(
680+
&self,
681+
_: chalk_ir::Ty<RustInterner<'tcx>>,
682+
) -> chalk_ir::Ty<RustInterner<'tcx>> {
683+
unimplemented!()
684+
}
685+
}
686+
687+
impl<'tcx> chalk_ir::UnificationDatabase<RustInterner<'tcx>> for RustIrDatabase<'tcx> {
688+
fn fn_def_variance(
689+
&self,
690+
def_id: chalk_ir::FnDefId<RustInterner<'tcx>>,
691+
) -> chalk_ir::Variances<RustInterner<'tcx>> {
692+
let variances = self.interner.tcx.variances_of(def_id.0);
693+
chalk_ir::Variances::from_iter(
694+
&self.interner,
695+
variances.iter().map(|v| match v {
696+
ty::Variance::Invariant => chalk_ir::Variance::Invariant,
697+
ty::Variance::Covariant => chalk_ir::Variance::Covariant,
698+
ty::Variance::Contravariant => chalk_ir::Variance::Contravariant,
699+
ty::Variance::Bivariant => unimplemented!(),
700+
}),
701+
)
702+
}
703+
704+
fn adt_variance(
705+
&self,
706+
def_id: chalk_ir::AdtId<RustInterner<'tcx>>,
707+
) -> chalk_ir::Variances<RustInterner<'tcx>> {
708+
let variances = self.interner.tcx.variances_of(def_id.0.did);
709+
chalk_ir::Variances::from_iter(
710+
&self.interner,
711+
variances.iter().map(|v| match v {
712+
ty::Variance::Invariant => chalk_ir::Variance::Invariant,
713+
ty::Variance::Covariant => chalk_ir::Variance::Covariant,
714+
ty::Variance::Contravariant => chalk_ir::Variance::Contravariant,
715+
ty::Variance::Bivariant => unimplemented!(),
716+
}),
717+
)
718+
}
647719
}
648720

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

compiler/rustc_traits/src/chalk/lowering.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
287287
chalk_ir::TyKind::Function(chalk_ir::FnPointer {
288288
num_binders: binders.len(interner),
289289
sig: sig.lower_into(interner),
290-
substitution: chalk_ir::Substitution::from_iter(
290+
substitution: chalk_ir::FnSubst(chalk_ir::Substitution::from_iter(
291291
interner,
292292
inputs_and_outputs.iter().map(|ty| {
293293
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner)
294294
}),
295-
),
295+
)),
296296
})
297297
}
298298
ty::Dynamic(predicates, region) => chalk_ir::TyKind::Dyn(chalk_ir::DynTy {
@@ -478,6 +478,10 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
478478
}
479479
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
480480
chalk_ir::LifetimeData::Phantom(_, _) => unimplemented!(),
481+
chalk_ir::LifetimeData::Empty(ui) => {
482+
ty::RegionKind::ReEmpty(ty::UniverseIndex::from_usize(ui.counter))
483+
}
484+
chalk_ir::LifetimeData::Erased => ty::RegionKind::ReErased,
481485
};
482486
interner.tcx.mk_region(kind)
483487
}

0 commit comments

Comments
 (0)