Skip to content

Commit 4876693

Browse files
committed
Auto merge of rust-lang#13408 - lowr:patch/bump-chalk-0.86, r=Veykril
Bump chalk There's a bug in current chalk that prevents us from properly supporting GATs, which is supposed to be fixed in v0.86. Note the following: - v0.86 is only going to be released next Sunday so I'll keep this PR as draft until then. - This doesn't compile without rust-lang/chalk#779, which I hope will be included in v0.86. I confirmed this compiles with it locally. Two breaking changes from v0.84: - `TypeFolder` has been split into `TypeFolder` and `FallibleTypeFolder` (rust-lang/chalk#772) - `ProjectionTy::self_type_parameter()` has been removed (rust-lang/chalk#778)
2 parents 8406380 + 310a72b commit 4876693

File tree

9 files changed

+103
-102
lines changed

9 files changed

+103
-102
lines changed

Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ debug = 0
2727
# chalk-solve = { path = "../chalk/chalk-solve" }
2828
# chalk-ir = { path = "../chalk/chalk-ir" }
2929
# chalk-recursive = { path = "../chalk/chalk-recursive" }
30+
# chalk-derive = { path = "../chalk/chalk-derive" }
3031

3132
# ungrammar = { path = "../ungrammar" }
3233

crates/hir-ty/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ ena = "0.14.0"
1818
tracing = "0.1.35"
1919
rustc-hash = "1.1.0"
2020
scoped-tls = "1.0.0"
21-
chalk-solve = { version = "0.84.0", default-features = false }
22-
chalk-ir = "0.84.0"
23-
chalk-recursive = { version = "0.84.0", default-features = false }
21+
chalk-solve = { version = "0.86.0", default-features = false }
22+
chalk-ir = "0.86.0"
23+
chalk-recursive = { version = "0.86.0", default-features = false }
24+
chalk-derive = "0.86.0"
2425
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
2526
once_cell = "1.15.0"
2627
typed-arena = "2.0.1"

crates/hir-ty/src/chalk_db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,10 @@ pub(super) fn generic_predicate_to_inline_bound(
823823
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
824824
}
825825
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
826-
if projection_ty.self_type_parameter(Interner) != self_ty_shifted_in {
826+
let trait_ = projection_ty.trait_(db);
827+
if projection_ty.self_type_parameter(db) != self_ty_shifted_in {
827828
return None;
828829
}
829-
let trait_ = projection_ty.trait_(db);
830830
let args_no_self = projection_ty.substitution.as_slice(Interner)[1..]
831831
.iter()
832832
.map(|ty| ty.clone().cast(Interner))

crates/hir-ty/src/chalk_ext.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl TyExt for Ty {
262262
WhereClause::AliasEq(AliasEq {
263263
alias: AliasTy::Projection(proj),
264264
ty: _,
265-
}) => &proj.self_type_parameter(Interner) == self,
265+
}) => &proj.self_type_parameter(db) == self,
266266
_ => false,
267267
})
268268
.collect::<Vec<_>>();
@@ -333,6 +333,7 @@ impl TyExt for Ty {
333333
pub trait ProjectionTyExt {
334334
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef;
335335
fn trait_(&self, db: &dyn HirDatabase) -> TraitId;
336+
fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty;
336337
}
337338

338339
impl ProjectionTyExt for ProjectionTy {
@@ -349,6 +350,10 @@ impl ProjectionTyExt for ProjectionTy {
349350
_ => panic!("projection ty without parent trait"),
350351
}
351352
}
353+
354+
fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty {
355+
self.trait_ref(db).self_type_parameter(Interner)
356+
}
352357
}
353358

354359
pub trait TraitRefExt {

crates/hir-ty/src/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl HirDisplay for ProjectionTy {
291291

292292
let trait_ = f.db.trait_data(self.trait_(f.db));
293293
write!(f, "<")?;
294-
self.self_type_parameter(Interner).hir_fmt(f)?;
294+
self.self_type_parameter(f.db).hir_fmt(f)?;
295295
write!(f, " as {}", trait_.name)?;
296296
if self.substitution.len(Interner) > 1 {
297297
write!(f, "<")?;
@@ -731,7 +731,7 @@ impl HirDisplay for Ty {
731731
WhereClause::AliasEq(AliasEq {
732732
alias: AliasTy::Projection(proj),
733733
ty: _,
734-
}) => &proj.self_type_parameter(Interner) == self,
734+
}) => &proj.self_type_parameter(f.db) == self,
735735
_ => false,
736736
})
737737
.collect::<Vec<_>>();

crates/hir-ty/src/infer/unify.rs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{fmt, mem, sync::Arc};
44

55
use chalk_ir::{
66
cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy,
7-
IntTy, NoSolution, TyVariableKind, UniverseIndex,
7+
IntTy, TyVariableKind, UniverseIndex,
88
};
99
use chalk_solve::infer::ParameterEnaVariableExt;
1010
use ena::unify::UnifyKey;
@@ -331,7 +331,6 @@ impl<'a> InferenceTable<'a> {
331331
&mut resolve::Resolver { table: self, var_stack, fallback },
332332
DebruijnIndex::INNERMOST,
333333
)
334-
.expect("fold failed unexpectedly")
335334
}
336335

337336
pub(crate) fn resolve_completely<T>(&mut self, t: T) -> T
@@ -452,13 +451,14 @@ impl<'a> InferenceTable<'a> {
452451
f: impl FnOnce(&mut Self) -> T,
453452
) -> T {
454453
use chalk_ir::fold::TypeFolder;
454+
455+
#[derive(chalk_derive::FallibleTypeFolder)]
456+
#[has_interner(Interner)]
455457
struct VarFudger<'a, 'b> {
456458
table: &'a mut InferenceTable<'b>,
457459
highest_known_var: InferenceVar,
458460
}
459461
impl<'a, 'b> TypeFolder<Interner> for VarFudger<'a, 'b> {
460-
type Error = NoSolution;
461-
462462
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
463463
self
464464
}
@@ -472,37 +472,37 @@ impl<'a> InferenceTable<'a> {
472472
var: chalk_ir::InferenceVar,
473473
kind: TyVariableKind,
474474
_outer_binder: chalk_ir::DebruijnIndex,
475-
) -> chalk_ir::Fallible<chalk_ir::Ty<Interner>> {
476-
Ok(if var < self.highest_known_var {
475+
) -> chalk_ir::Ty<Interner> {
476+
if var < self.highest_known_var {
477477
var.to_ty(Interner, kind)
478478
} else {
479479
self.table.new_type_var()
480-
})
480+
}
481481
}
482482

483483
fn fold_inference_lifetime(
484484
&mut self,
485485
var: chalk_ir::InferenceVar,
486486
_outer_binder: chalk_ir::DebruijnIndex,
487-
) -> chalk_ir::Fallible<chalk_ir::Lifetime<Interner>> {
488-
Ok(if var < self.highest_known_var {
487+
) -> chalk_ir::Lifetime<Interner> {
488+
if var < self.highest_known_var {
489489
var.to_lifetime(Interner)
490490
} else {
491491
self.table.new_lifetime_var()
492-
})
492+
}
493493
}
494494

495495
fn fold_inference_const(
496496
&mut self,
497497
ty: chalk_ir::Ty<Interner>,
498498
var: chalk_ir::InferenceVar,
499499
_outer_binder: chalk_ir::DebruijnIndex,
500-
) -> chalk_ir::Fallible<chalk_ir::Const<Interner>> {
501-
Ok(if var < self.highest_known_var {
500+
) -> chalk_ir::Const<Interner> {
501+
if var < self.highest_known_var {
502502
var.to_const(Interner, ty)
503503
} else {
504504
self.table.new_const_var(ty)
505-
})
505+
}
506506
}
507507
}
508508

@@ -512,7 +512,6 @@ impl<'a> InferenceTable<'a> {
512512
self.rollback_to(snapshot);
513513
result
514514
.fold_with(&mut VarFudger { table: self, highest_known_var }, DebruijnIndex::INNERMOST)
515-
.expect("fold_with with VarFudger")
516515
}
517516

518517
/// This checks whether any of the free variables in the `canonicalized`
@@ -639,21 +638,24 @@ mod resolve {
639638
use chalk_ir::{
640639
cast::Cast,
641640
fold::{TypeFoldable, TypeFolder},
642-
Fallible, NoSolution,
643641
};
644642
use hir_def::type_ref::ConstScalar;
645643

646-
pub(super) struct Resolver<'a, 'b, F> {
644+
#[derive(chalk_derive::FallibleTypeFolder)]
645+
#[has_interner(Interner)]
646+
pub(super) struct Resolver<
647+
'a,
648+
'b,
649+
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
650+
> {
647651
pub(super) table: &'a mut InferenceTable<'b>,
648652
pub(super) var_stack: &'a mut Vec<InferenceVar>,
649653
pub(super) fallback: F,
650654
}
651-
impl<'a, 'b, 'i, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
655+
impl<'a, 'b, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
652656
where
653-
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg + 'i,
657+
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
654658
{
655-
type Error = NoSolution;
656-
657659
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
658660
self
659661
}
@@ -667,20 +669,19 @@ mod resolve {
667669
var: InferenceVar,
668670
kind: TyVariableKind,
669671
outer_binder: DebruijnIndex,
670-
) -> Fallible<Ty> {
672+
) -> Ty {
671673
let var = self.table.var_unification_table.inference_var_root(var);
672674
if self.var_stack.contains(&var) {
673675
// recursive type
674676
let default = self.table.fallback_value(var, kind).cast(Interner);
675-
return Ok((self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
677+
return (self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
676678
.assert_ty_ref(Interner)
677-
.clone());
679+
.clone();
678680
}
679681
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
680682
// known_ty may contain other variables that are known by now
681683
self.var_stack.push(var);
682-
let result =
683-
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
684+
let result = known_ty.fold_with(self, outer_binder);
684685
self.var_stack.pop();
685686
result.assert_ty_ref(Interner).clone()
686687
} else {
@@ -689,15 +690,15 @@ mod resolve {
689690
.assert_ty_ref(Interner)
690691
.clone()
691692
};
692-
Ok(result)
693+
result
693694
}
694695

695696
fn fold_inference_const(
696697
&mut self,
697698
ty: Ty,
698699
var: InferenceVar,
699700
outer_binder: DebruijnIndex,
700-
) -> Fallible<Const> {
701+
) -> Const {
701702
let var = self.table.var_unification_table.inference_var_root(var);
702703
let default = ConstData {
703704
ty: ty.clone(),
@@ -707,35 +708,33 @@ mod resolve {
707708
.cast(Interner);
708709
if self.var_stack.contains(&var) {
709710
// recursive
710-
return Ok((self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
711+
return (self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
711712
.assert_const_ref(Interner)
712-
.clone());
713+
.clone();
713714
}
714-
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
715+
if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
715716
// known_ty may contain other variables that are known by now
716717
self.var_stack.push(var);
717-
let result =
718-
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
718+
let result = known_ty.fold_with(self, outer_binder);
719719
self.var_stack.pop();
720720
result.assert_const_ref(Interner).clone()
721721
} else {
722722
(self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
723723
.assert_const_ref(Interner)
724724
.clone()
725-
};
726-
Ok(result)
725+
}
727726
}
728727

729728
fn fold_inference_lifetime(
730729
&mut self,
731730
_var: InferenceVar,
732731
_outer_binder: DebruijnIndex,
733-
) -> Fallible<Lifetime> {
732+
) -> Lifetime {
734733
// fall back all lifetimes to 'static -- currently we don't deal
735734
// with any lifetimes, but we can sometimes get some lifetime
736735
// variables through Chalk's unification, and this at least makes
737736
// sure we don't leak them outside of inference
738-
Ok(crate::static_lifetime())
737+
crate::static_lifetime()
739738
}
740739
}
741740
}

0 commit comments

Comments
 (0)