Opportunistically resolve region var in canonicalizer

This commit is contained in:
Michael Goulet 2023-12-15 05:02:32 +00:00
parent 03515c6a22
commit 146e345d8b
7 changed files with 70 additions and 35 deletions

View File

@ -381,17 +381,13 @@ fn probe_ty_var(&self, vid: TyVid) -> Option<Ty<'tcx>> {
self.probe_ty_var(vid).ok()
}
fn root_lt_var(&self, vid: ty::RegionVid) -> ty::RegionVid {
self.root_region_var(vid)
}
fn probe_lt_var(&self, vid: ty::RegionVid) -> Option<ty::Region<'tcx>> {
fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> Option<ty::Region<'tcx>> {
let re = self
.inner
.borrow_mut()
.unwrap_region_constraints()
.opportunistic_resolve_var(self.tcx, vid);
if re.is_var() { None } else { Some(re) }
if *re == ty::ReVar(vid) { None } else { Some(re) }
}
fn root_ct_var(&self, vid: ConstVid) -> ConstVid {
@ -1367,10 +1363,6 @@ pub fn root_var(&self, var: ty::TyVid) -> ty::TyVid {
self.inner.borrow_mut().type_variables().root_var(var)
}
pub fn root_region_var(&self, var: ty::RegionVid) -> ty::RegionVid {
self.inner.borrow_mut().unwrap_region_constraints().root_var(var)
}
pub fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid {
self.inner.borrow_mut().const_unification_table().find(var).vid
}

View File

@ -623,11 +623,6 @@ pub fn opportunistic_resolve_var(
}
}
pub fn root_var(&mut self, vid: ty::RegionVid) -> ty::RegionVid {
let mut ut = self.unification_table_mut(); // FIXME(rust-lang/ena#42): unnecessary mut
ut.find(vid).vid
}
fn combine_map(&mut self, t: CombineMapType) -> &mut CombineMap<'tcx> {
match t {
Glb => &mut self.glbs,

View File

@ -242,16 +242,10 @@ fn fold_region(&mut self, r: I::Region) -> I::Region {
ty::ReVar(vid) => {
assert_eq!(
self.infcx.root_lt_var(vid),
vid,
"region vid should have been resolved fully before canonicalization"
);
assert_eq!(
self.infcx.probe_lt_var(vid),
self.infcx.opportunistic_resolve_lt_var(vid),
None,
"region vid should have been resolved fully before canonicalization"
);
match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
CanonicalizeMode::Response { .. } => {

View File

@ -32,11 +32,7 @@ fn probe_ty_var(&self, _vid: TyVid) -> Option<I::Ty> {
None
}
fn root_lt_var(&self, vid: I::InferRegion) -> I::InferRegion {
vid
}
fn probe_lt_var(&self, _vid: I::InferRegion) -> Option<I::Region> {
fn opportunistic_resolve_lt_var(&self, _vid: I::InferRegion) -> Option<I::Region> {
None
}

View File

@ -18,14 +18,14 @@ fn universe_of_lt(
lt: <Self::Interner as Interner>::InferRegion,
) -> Option<UniverseIndex>;
/// Resolve `InferRegion` to its root `InferRegion`.
fn root_lt_var(
&self,
vid: <Self::Interner as Interner>::InferRegion,
) -> <Self::Interner as Interner>::InferRegion;
/// Resolve `InferRegion` to its inferred region, if it has been equated with a non-infer region.
fn probe_lt_var(
/// Resolve `InferRegion` to its inferred region, if it has been equated with
/// a non-infer region.
///
/// FIXME: This has slightly different semantics than `{probe,resolve}_{ty,ct}_var`,
/// that has to do with the fact unlike `Ty` or `Const` vars, in rustc, we may
/// not always be able to *name* the root region var from the universe of the
/// var we're trying to resolve. That's why it's called *opportunistic*.
fn opportunistic_resolve_lt_var(
&self,
vid: <Self::Interner as Interner>::InferRegion,
) -> Option<<Self::Interner as Interner>::Region>;

View File

@ -0,0 +1,22 @@
// compile-flags: -Znext-solver
//
// This is a gnarly test but I don't know how to minimize it, frankly.
#![feature(lazy_type_alias)]
//~^ WARN the feature `lazy_type_alias` is incomplete
trait ToUnit<'a> {
type Unit;
}
trait Overlap<T> {}
type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit;
impl<T> Overlap<T> for T {}
impl<T> Overlap<for<'a> fn(Assoc<'a, T>)> for T where Missing: Overlap<T> {}
//~^ ERROR conflicting implementations of trait `Overlap<fn(_)>` for type `fn(_)`
//~| ERROR cannot find type `Missing` in this scope
fn main() {}

View File

@ -0,0 +1,36 @@
error[E0412]: cannot find type `Missing` in this scope
--> $DIR/issue-118950-root-region.rs:18:55
|
LL | impl<T> Overlap<for<'a> fn(Assoc<'a, T>)> for T where Missing: Overlap<T> {}
| ^^^^^^^ not found in this scope
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-118950-root-region.rs:5:12
|
LL | #![feature(lazy_type_alias)]
| ^^^^^^^^^^^^^^^
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= note: `#[warn(incomplete_features)]` on by default
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [RePlaceholder(!1_BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [RePlaceholder(!1_BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [RePlaceholder(!1_BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
WARN rustc_infer::infer::generalize may incompletely handle alias type: Alias(Weak, AliasTy { args: [RePlaceholder(!1_BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) })
error[E0119]: conflicting implementations of trait `Overlap<fn(_)>` for type `fn(_)`
--> $DIR/issue-118950-root-region.rs:18:1
|
LL | impl<T> Overlap<T> for T {}
| ------------------------ first implementation here
LL |
LL | impl<T> Overlap<for<'a> fn(Assoc<'a, T>)> for T where Missing: Overlap<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(_)`
error: aborting due to 2 previous errors; 1 warning emitted
Some errors have detailed explanations: E0119, E0412.
For more information about an error, try `rustc --explain E0119`.