提交 24714310 编写于 作者: J Jack Huey

Move is_free and is_free_or_static to Region, change resolve_var to...

Move is_free and is_free_or_static to Region, change resolve_var to resolve_region, and remove RootEmptyRegion
上级 1517f5de
...@@ -495,8 +495,7 @@ fn init_free_and_bound_regions(&mut self) { ...@@ -495,8 +495,7 @@ fn init_free_and_bound_regions(&mut self) {
} }
} }
NllRegionVariableOrigin::RootEmptyRegion NllRegionVariableOrigin::Existential { .. } => {
| NllRegionVariableOrigin::Existential { .. } => {
// For existential, regions, nothing to do. // For existential, regions, nothing to do.
} }
} }
...@@ -1410,8 +1409,7 @@ fn check_universal_regions( ...@@ -1410,8 +1409,7 @@ fn check_universal_regions(
self.check_bound_universal_region(fr, placeholder, errors_buffer); self.check_bound_universal_region(fr, placeholder, errors_buffer);
} }
NllRegionVariableOrigin::RootEmptyRegion NllRegionVariableOrigin::Existential { .. } => {
| NllRegionVariableOrigin::Existential { .. } => {
// nothing to check here // nothing to check here
} }
} }
...@@ -1513,8 +1511,7 @@ fn check_polonius_subset_errors( ...@@ -1513,8 +1511,7 @@ fn check_polonius_subset_errors(
self.check_bound_universal_region(fr, placeholder, errors_buffer); self.check_bound_universal_region(fr, placeholder, errors_buffer);
} }
NllRegionVariableOrigin::RootEmptyRegion NllRegionVariableOrigin::Existential { .. } => {
| NllRegionVariableOrigin::Existential { .. } => {
// nothing to check here // nothing to check here
} }
} }
...@@ -1788,9 +1785,9 @@ pub(crate) fn cannot_name_placeholder(&self, r1: RegionVid, r2: RegionVid) -> bo ...@@ -1788,9 +1785,9 @@ pub(crate) fn cannot_name_placeholder(&self, r1: RegionVid, r2: RegionVid) -> bo
universe1.cannot_name(placeholder.universe) universe1.cannot_name(placeholder.universe)
} }
NllRegionVariableOrigin::RootEmptyRegion NllRegionVariableOrigin::FreeRegion | NllRegionVariableOrigin::Existential { .. } => {
| NllRegionVariableOrigin::FreeRegion false
| NllRegionVariableOrigin::Existential { .. } => false, }
} }
} }
...@@ -2152,8 +2149,7 @@ pub(crate) fn best_blame_constraint( ...@@ -2152,8 +2149,7 @@ pub(crate) fn best_blame_constraint(
let blame_source = match from_region_origin { let blame_source = match from_region_origin {
NllRegionVariableOrigin::FreeRegion NllRegionVariableOrigin::FreeRegion
| NllRegionVariableOrigin::Existential { from_forall: false } => true, | NllRegionVariableOrigin::Existential { from_forall: false } => true,
NllRegionVariableOrigin::RootEmptyRegion NllRegionVariableOrigin::Placeholder(_)
| NllRegionVariableOrigin::Placeholder(_)
| NllRegionVariableOrigin::Existential { from_forall: true } => false, | NllRegionVariableOrigin::Existential { from_forall: true } => false,
}; };
......
...@@ -503,7 +503,7 @@ fn build(self) -> UniversalRegions<'tcx> { ...@@ -503,7 +503,7 @@ fn build(self) -> UniversalRegions<'tcx> {
let root_empty = self let root_empty = self
.infcx .infcx
.next_nll_region_var(NllRegionVariableOrigin::RootEmptyRegion) .next_nll_region_var(NllRegionVariableOrigin::Existential { from_forall: true })
.to_region_vid(); .to_region_vid();
UniversalRegions { UniversalRegions {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
//! and use that to decide when one free region outlives another, and so forth. //! and use that to decide when one free region outlives another, and so forth.
use rustc_data_structures::transitive_relation::TransitiveRelation; use rustc_data_structures::transitive_relation::TransitiveRelation;
use rustc_middle::ty::{self, Lift, Region, TyCtxt}; use rustc_middle::ty::{Lift, Region, TyCtxt};
/// Combines a `FreeRegionMap` and a `TyCtxt`. /// Combines a `FreeRegionMap` and a `TyCtxt`.
/// ///
...@@ -49,7 +49,7 @@ pub fn is_empty(&self) -> bool { ...@@ -49,7 +49,7 @@ pub fn is_empty(&self) -> bool {
// (with the exception that `'static: 'x` is not notable) // (with the exception that `'static: 'x` is not notable)
pub fn relate_regions(&mut self, sub: Region<'tcx>, sup: Region<'tcx>) { pub fn relate_regions(&mut self, sub: Region<'tcx>, sup: Region<'tcx>) {
debug!("relate_regions(sub={:?}, sup={:?})", sub, sup); debug!("relate_regions(sub={:?}, sup={:?})", sub, sup);
if self.is_free_or_static(sub) && self.is_free(sup) { if sub.is_free_or_static() && sup.is_free() {
self.relation.add(sub, sup) self.relation.add(sub, sup)
} }
} }
...@@ -68,7 +68,7 @@ pub fn sub_free_regions( ...@@ -68,7 +68,7 @@ pub fn sub_free_regions(
r_a: Region<'tcx>, r_a: Region<'tcx>,
r_b: Region<'tcx>, r_b: Region<'tcx>,
) -> bool { ) -> bool {
assert!(self.is_free_or_static(r_a) && self.is_free_or_static(r_b)); assert!(r_a.is_free_or_static() && r_b.is_free_or_static());
let re_static = tcx.lifetimes.re_static; let re_static = tcx.lifetimes.re_static;
if self.check_relation(re_static, r_b) { if self.check_relation(re_static, r_b) {
// `'a <= 'static` is always true, and not stored in the // `'a <= 'static` is always true, and not stored in the
...@@ -85,20 +85,6 @@ fn check_relation(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> bool { ...@@ -85,20 +85,6 @@ fn check_relation(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> bool {
r_a == r_b || self.relation.contains(r_a, r_b) r_a == r_b || self.relation.contains(r_a, r_b)
} }
/// True for free regions other than `'static`.
pub fn is_free(&self, r: Region<'_>) -> bool {
matches!(*r, ty::ReEarlyBound(_) | ty::ReFree(_))
}
/// True if `r` is a free region or static of the sort that this
/// free region map can be used with.
pub fn is_free_or_static(&self, r: Region<'_>) -> bool {
match *r {
ty::ReStatic => true,
_ => self.is_free(r),
}
}
/// Computes the least-upper-bound of two free regions. In some /// Computes the least-upper-bound of two free regions. In some
/// cases, this is more conservative than necessary, in order to /// cases, this is more conservative than necessary, in order to
/// avoid making arbitrary choices. See /// avoid making arbitrary choices. See
...@@ -110,8 +96,8 @@ pub fn lub_free_regions( ...@@ -110,8 +96,8 @@ pub fn lub_free_regions(
r_b: Region<'tcx>, r_b: Region<'tcx>,
) -> Region<'tcx> { ) -> Region<'tcx> {
debug!("lub_free_regions(r_a={:?}, r_b={:?})", r_a, r_b); debug!("lub_free_regions(r_a={:?}, r_b={:?})", r_a, r_b);
assert!(self.is_free(r_a)); assert!(r_a.is_free());
assert!(self.is_free(r_b)); assert!(r_b.is_free());
let result = if r_a == r_b { let result = if r_a == r_b {
r_a r_a
} else { } else {
......
...@@ -47,7 +47,6 @@ pub(crate) fn resolve<'tcx>( ...@@ -47,7 +47,6 @@ pub(crate) fn resolve<'tcx>(
#[derive(Clone)] #[derive(Clone)]
pub struct LexicalRegionResolutions<'tcx> { pub struct LexicalRegionResolutions<'tcx> {
pub(crate) values: IndexVec<RegionVid, VarValue<'tcx>>, pub(crate) values: IndexVec<RegionVid, VarValue<'tcx>>,
pub(crate) error_region: ty::Region<'tcx>,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
...@@ -140,7 +139,6 @@ fn num_vars(&self) -> usize { ...@@ -140,7 +139,6 @@ fn num_vars(&self) -> usize {
/// empty region. The `expansion` phase will grow this larger. /// empty region. The `expansion` phase will grow this larger.
fn construct_var_data(&self, tcx: TyCtxt<'tcx>) -> LexicalRegionResolutions<'tcx> { fn construct_var_data(&self, tcx: TyCtxt<'tcx>) -> LexicalRegionResolutions<'tcx> {
LexicalRegionResolutions { LexicalRegionResolutions {
error_region: tcx.lifetimes.re_static,
values: IndexVec::from_fn_n( values: IndexVec::from_fn_n(
|vid| { |vid| {
let vid_universe = self.var_infos[vid].universe; let vid_universe = self.var_infos[vid].universe;
...@@ -310,7 +308,7 @@ fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool { ...@@ -310,7 +308,7 @@ fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool {
// Check for the case where we know that `'b: 'static` -- in that case, // Check for the case where we know that `'b: 'static` -- in that case,
// `a <= b` for all `a`. // `a <= b` for all `a`.
let b_free_or_static = self.region_rels.free_regions.is_free_or_static(b); let b_free_or_static = b.is_free_or_static();
if b_free_or_static && sub_free_regions(tcx.lifetimes.re_static, b) { if b_free_or_static && sub_free_regions(tcx.lifetimes.re_static, b) {
return true; return true;
} }
...@@ -320,7 +318,7 @@ fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool { ...@@ -320,7 +318,7 @@ fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool {
// `lub` relationship defined below, since sometimes the "lub" // `lub` relationship defined below, since sometimes the "lub"
// is actually the `postdom_upper_bound` (see // is actually the `postdom_upper_bound` (see
// `TransitiveRelation` for more details). // `TransitiveRelation` for more details).
let a_free_or_static = self.region_rels.free_regions.is_free_or_static(a); let a_free_or_static = a.is_free_or_static();
if a_free_or_static && b_free_or_static { if a_free_or_static && b_free_or_static {
return sub_free_regions(a, b); return sub_free_regions(a, b);
} }
...@@ -864,10 +862,7 @@ fn normalize<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T ...@@ -864,10 +862,7 @@ fn normalize<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
tcx.fold_regions(value, |r, _db| match *r { tcx.fold_regions(value, |r, _db| self.resolve_region(tcx, r))
ty::ReVar(rid) => self.resolve_var(rid),
_ => r,
})
} }
fn value(&self, rid: RegionVid) -> &VarValue<'tcx> { fn value(&self, rid: RegionVid) -> &VarValue<'tcx> {
...@@ -878,12 +873,19 @@ fn value_mut(&mut self, rid: RegionVid) -> &mut VarValue<'tcx> { ...@@ -878,12 +873,19 @@ fn value_mut(&mut self, rid: RegionVid) -> &mut VarValue<'tcx> {
&mut self.values[rid] &mut self.values[rid]
} }
pub fn resolve_var(&self, rid: RegionVid) -> ty::Region<'tcx> { pub(crate) fn resolve_region(
let result = match self.values[rid] { &self,
VarValue::Value(r) => r, tcx: TyCtxt<'tcx>,
VarValue::ErrorValue => self.error_region, r: ty::Region<'tcx>,
) -> ty::Region<'tcx> {
let result = match *r {
ty::ReVar(rid) => match self.values[rid] {
VarValue::Value(r) => r,
VarValue::ErrorValue => tcx.lifetimes.re_static,
},
_ => r,
}; };
debug!("resolve_var({:?}) = {:?}", rid, result); debug!("resolve_region({:?}) = {:?}", r, result);
result result
} }
} }
...@@ -466,9 +466,6 @@ pub enum NllRegionVariableOrigin { ...@@ -466,9 +466,6 @@ pub enum NllRegionVariableOrigin {
/// from a `for<'a> T` binder). Meant to represent "any region". /// from a `for<'a> T` binder). Meant to represent "any region".
Placeholder(ty::PlaceholderRegion), Placeholder(ty::PlaceholderRegion),
/// The variable we create to represent `'empty(U0)`.
RootEmptyRegion,
Existential { Existential {
/// If this is true, then this variable was created to represent a lifetime /// If this is true, then this variable was created to represent a lifetime
/// bound in a `for` binder. For example, it might have been created to /// bound in a `for` binder. For example, it might have been created to
...@@ -1250,7 +1247,6 @@ pub fn skip_region_resolution(&self) { ...@@ -1250,7 +1247,6 @@ pub fn skip_region_resolution(&self) {
}; };
let lexical_region_resolutions = LexicalRegionResolutions { let lexical_region_resolutions = LexicalRegionResolutions {
error_region: self.tcx.lifetimes.re_static,
values: rustc_index::vec::IndexVec::from_elem_n( values: rustc_index::vec::IndexVec::from_elem_n(
crate::infer::lexical_region_resolve::VarValue::Value(self.tcx.lifetimes.re_erased), crate::infer::lexical_region_resolve::VarValue::Value(self.tcx.lifetimes.re_erased),
var_infos.len(), var_infos.len(),
......
...@@ -206,13 +206,13 @@ fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> { ...@@ -206,13 +206,13 @@ fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> { fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> {
match *r { match *r {
ty::ReVar(rid) => Ok(self ty::ReVar(_) => Ok(self
.infcx .infcx
.lexical_region_resolutions .lexical_region_resolutions
.borrow() .borrow()
.as_ref() .as_ref()
.expect("region resolution not performed") .expect("region resolution not performed")
.resolve_var(rid)), .resolve_region(self.infcx.tcx, r)),
_ => Ok(r), _ => Ok(r),
} }
} }
......
...@@ -1570,6 +1570,19 @@ pub fn free_region_binding_scope(self, tcx: TyCtxt<'_>) -> DefId { ...@@ -1570,6 +1570,19 @@ pub fn free_region_binding_scope(self, tcx: TyCtxt<'_>) -> DefId {
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self), _ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
} }
} }
/// True for free regions other than `'static`.
pub fn is_free(self) -> bool {
matches!(*self, ty::ReEarlyBound(_) | ty::ReFree(_))
}
/// True if `self` is a free region or static.
pub fn is_free_or_static(self) -> bool {
match *self {
ty::ReStatic => true,
_ => self.is_free(),
}
}
} }
/// Type utilities /// Type utilities
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册