Skip to content

Commit

Permalink
Canonicalize effect vars in new solver
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 14, 2023
1 parent 5adddad commit 63f31e2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,10 @@ impl<'tcx> InferCtxt<'tcx> {
self.inner.borrow_mut().const_unification_table().find(var)
}

pub fn root_effect_var(&self, var: ty::EffectVid<'tcx>) -> ty::EffectVid<'tcx> {
self.inner.borrow_mut().effect_unification_table().find(var)
}

/// Resolves an int var to a rigid int type, if it was constrained to one,
/// or else the root int var in the unification table.
pub fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> {
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_trait_selection/src/solve/canonicalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,16 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
// FIXME: we should fold this ty eventually
CanonicalVarKind::Const(ui, c.ty())
}
ty::ConstKind::Infer(ty::InferConst::EffectVar(_)) => {
bug!("effect var has no universe")
ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => {
assert_eq!(
self.infcx.root_effect_var(vid),
vid,
"effect var should have been resolved"
);
let None = self.infcx.probe_effect_var(vid) else {
bug!("effect var should have been resolved");
};
CanonicalVarKind::Effect
}
ty::ConstKind::Infer(ty::InferConst::Fresh(_)) => {
bug!("fresh var during canonicalization: {c:?}")
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerResolver<'_, 'tcx> {
}
}
}
ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => {
// FIXME: we need to fold the ty too, I think.
match self.infcx.probe_effect_var(vid) {
Some(c) => c.as_const(self.infcx.tcx),
None => ty::Const::new_infer(
self.infcx.tcx,
ty::InferConst::EffectVar(self.infcx.root_effect_var(vid)),
c.ty(),
),
}
}
_ => {
if c.has_infer() {
c.super_fold_with(self)
Expand Down
22 changes: 22 additions & 0 deletions tests/ui/traits/new-solver/canonicalize-effect-var.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// compile-flags: -Ztrait-solver=next
// check-pass

#![feature(effects)]
#![feature(const_trait_impl)]

#[const_trait]
trait Foo {
fn foo();
}

trait Bar {}

impl const Foo for i32 {
fn foo() {}
}

impl<T> const Foo for T where T: Bar {
fn foo() {}
}

fn main() {}

0 comments on commit 63f31e2

Please sign in to comment.