Skip to content
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

Remove lub_empty from lexical region resolve #115224

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Changes from 1 commit
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
65 changes: 19 additions & 46 deletions compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use rustc_data_structures::graph::implementation::{
use rustc_data_structures::intern::Interned;
use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::PlaceholderRegion;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{ReEarlyBound, ReErased, ReError, ReFree, ReStatic};
use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
Expand Down Expand Up @@ -173,38 +172,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
}
}

/// Gets the LUb of a given region and the empty region
fn lub_empty(&self, a_region: Region<'tcx>) -> Result<Region<'tcx>, PlaceholderRegion> {
match *a_region {
ReLateBound(..) | ReErased => {
bug!("cannot relate region: {:?}", a_region);
}

ReVar(v_id) => {
span_bug!(
self.var_infos[v_id].origin.span(),
"lub invoked with non-concrete regions: {:?}",
a_region,
);
}

ReStatic => {
// nothing lives longer than `'static`
Ok(self.tcx().lifetimes.re_static)
}

ReError(_) => Ok(a_region),

ReEarlyBound(_) | ReFree(_) => {
// All empty regions are less than early-bound, free,
// and scope regions.
Ok(a_region)
}

RePlaceholder(placeholder) => Err(placeholder),
}
}

fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
// In the first pass, we expand region vids according to constraints we
// have previously found. In the second pass, we loop through the region
Expand Down Expand Up @@ -247,15 +214,17 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
true
}
VarValue::Value(cur_region) => {
let lub = match self.lub_empty(cur_region) {
Ok(r) => r,
let lub = match *cur_region {
spastorino marked this conversation as resolved.
Show resolved Hide resolved
// If the empty and placeholder regions are in the same universe,
// then the LUB is the Placeholder region (which is the cur_region).
// If they are not in the same universe, the LUB is the Static lifetime.
Err(placeholder) if a_universe == placeholder.universe => {
cur_region
RePlaceholder(placeholder)
if a_universe != placeholder.universe =>
spastorino marked this conversation as resolved.
Show resolved Hide resolved
{
self.tcx().lifetimes.re_static
}
Err(_) => self.tcx().lifetimes.re_static,

_ => cur_region,
};

if lub == cur_region {
Expand Down Expand Up @@ -341,15 +310,19 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {

match *b_data {
VarValue::Empty(empty_ui) => {
let lub = match self.lub_empty(a_region) {
Ok(r) => r,
// If this empty region is from a universe that can
// name the placeholder, then the placeholder is
// larger; otherwise, the only ancestor is `'static`.
Err(placeholder) if empty_ui.can_name(placeholder.universe) => {
ty::Region::new_placeholder(self.tcx(), placeholder)
let lub = match *a_region {
RePlaceholder(placeholder) => {
// If this empty region is from a universe that can
// name the placeholder, then the placeholder is
// larger; otherwise, the only ancestor is `'static`.
if empty_ui.can_name(placeholder.universe) {
ty::Region::new_placeholder(self.tcx(), placeholder)
} else {
self.tcx().lifetimes.re_static
}
}
Err(_) => self.tcx().lifetimes.re_static,

_ => a_region,
};

debug!("Expanding value of {:?} from empty lifetime to {:?}", b_vid, lub);
Expand Down