simplify NLLRegionVariableOrigin
This commit is contained in:
parent
145155dc96
commit
40498bae65
src
@ -87,7 +87,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.11"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -187,7 +187,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
name = "cargo"
|
||||
version = "0.30.0"
|
||||
dependencies = [
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -303,7 +303,7 @@ version = "2.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -622,7 +622,7 @@ name = "env_logger"
|
||||
version = "0.5.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1844,7 +1844,7 @@ name = "rustc-ap-rustc_errors"
|
||||
version = "182.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-ap-rustc_data_structures 182.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-ap-serialize 182.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-ap-syntax_pos 182.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2097,7 +2097,7 @@ dependencies = [
|
||||
name = "rustc_errors"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_data_structures 0.0.0",
|
||||
"serialize 0.0.0",
|
||||
"syntax_pos 0.0.0",
|
||||
@ -3056,7 +3056,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
|
||||
"checksum assert_cli 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98589b0e465a6c510d95fceebd365bb79bedece7f6e18a480897f2015f85ec51"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
|
||||
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
|
||||
"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
|
||||
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
|
@ -377,7 +377,20 @@ pub enum NLLRegionVariableOrigin {
|
||||
// elsewhere. This origin indices we've got one of those.
|
||||
FreeRegion,
|
||||
|
||||
Inferred(::mir::visit::TyContext),
|
||||
Existential,
|
||||
}
|
||||
|
||||
impl NLLRegionVariableOrigin {
|
||||
pub fn is_universal(self) -> bool {
|
||||
match self {
|
||||
NLLRegionVariableOrigin::FreeRegion => true,
|
||||
NLLRegionVariableOrigin::Existential => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_existential(self) -> bool {
|
||||
!self.is_universal()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -27,8 +27,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
writeln!(out, "| Free Region Mapping")?;
|
||||
|
||||
for region in self.regions() {
|
||||
if self.definitions[region].is_universal {
|
||||
let classification = self.universal_regions.region_classification(region).unwrap();
|
||||
if self.definitions[region].origin.is_universal() {
|
||||
let classification = self.universal_regions
|
||||
.region_classification(region)
|
||||
.unwrap();
|
||||
let outlived_by = self.universal_regions.regions_outlived_by(region);
|
||||
writeln!(
|
||||
out,
|
||||
|
@ -9,18 +9,16 @@
|
||||
// except according to those terms.
|
||||
|
||||
use super::universal_regions::UniversalRegions;
|
||||
use borrow_check::nll::constraints::graph::ConstraintGraph;
|
||||
use borrow_check::nll::constraints::{
|
||||
ConstraintIndex, ConstraintSccIndex, ConstraintSet, OutlivesConstraint,
|
||||
};
|
||||
use borrow_check::nll::constraints::graph::ConstraintGraph;
|
||||
use borrow_check::nll::region_infer::values::ToElementIndex;
|
||||
use borrow_check::nll::type_check::Locations;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::infer::canonical::QueryRegionConstraint;
|
||||
use rustc::infer::region_constraints::{GenericKind, VarInfos};
|
||||
use rustc::infer::InferCtxt;
|
||||
use rustc::infer::NLLRegionVariableOrigin;
|
||||
use rustc::infer::RegionVariableOrigin;
|
||||
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin, RegionVariableOrigin};
|
||||
use rustc::mir::{
|
||||
ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements, Local, Location,
|
||||
Mir,
|
||||
@ -85,17 +83,10 @@ pub struct RegionInferenceContext<'tcx> {
|
||||
}
|
||||
|
||||
struct RegionDefinition<'tcx> {
|
||||
/// Why we created this variable. Mostly these will be
|
||||
/// `RegionVariableOrigin::NLL`, but some variables get created
|
||||
/// elsewhere in the code with other causes (e.g., instantiation
|
||||
/// late-bound-regions).
|
||||
origin: RegionVariableOrigin,
|
||||
|
||||
/// True if this is a universally quantified region. This means a
|
||||
/// lifetime parameter that appears in the function signature (or,
|
||||
/// in the case of a closure, in the closure environment, which of
|
||||
/// course is also in the function signature).
|
||||
is_universal: bool,
|
||||
/// What kind of variable is this -- a free region? existential
|
||||
/// variable? etc. (See the `NLLRegionVariableOrigin` for more
|
||||
/// info.)
|
||||
origin: NLLRegionVariableOrigin,
|
||||
|
||||
/// If this is 'static or an early-bound region, then this is
|
||||
/// `Some(X)` where `X` is the name of the region.
|
||||
@ -287,12 +278,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
for variable in universal_regions.universal_regions() {
|
||||
// These should be free-region variables.
|
||||
assert!(match self.definitions[variable].origin {
|
||||
RegionVariableOrigin::NLL(NLLRegionVariableOrigin::FreeRegion) => true,
|
||||
_ => false,
|
||||
NLLRegionVariableOrigin::FreeRegion => true,
|
||||
NLLRegionVariableOrigin::Existential => false,
|
||||
});
|
||||
|
||||
self.definitions[variable].is_universal = true;
|
||||
|
||||
// Add all nodes in the CFG to liveness constraints
|
||||
for point_index in elements.all_point_indices() {
|
||||
self.add_live_element(variable, point_index);
|
||||
@ -842,24 +831,26 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'gcx>>>,
|
||||
errors_buffer: &mut Vec<Diagnostic>,
|
||||
) {
|
||||
// The universal regions are always found in a prefix of the
|
||||
// full list.
|
||||
let universal_definitions = self.definitions
|
||||
.iter_enumerated()
|
||||
.take_while(|(_, fr_definition)| fr_definition.is_universal);
|
||||
for (fr, fr_definition) in self.definitions.iter_enumerated() {
|
||||
match fr_definition.origin {
|
||||
NLLRegionVariableOrigin::FreeRegion => {
|
||||
// Go through each of the universal regions `fr` and check that
|
||||
// they did not grow too large, accumulating any requirements
|
||||
// for our caller into the `outlives_requirements` vector.
|
||||
self.check_universal_region(
|
||||
infcx,
|
||||
mir,
|
||||
mir_def_id,
|
||||
fr,
|
||||
&mut propagated_outlives_requirements,
|
||||
errors_buffer,
|
||||
);
|
||||
}
|
||||
|
||||
// Go through each of the universal regions `fr` and check that
|
||||
// they did not grow too large, accumulating any requirements
|
||||
// for our caller into the `outlives_requirements` vector.
|
||||
for (fr, _) in universal_definitions {
|
||||
self.check_universal_region(
|
||||
infcx,
|
||||
mir,
|
||||
mir_def_id,
|
||||
fr,
|
||||
&mut propagated_outlives_requirements,
|
||||
errors_buffer,
|
||||
);
|
||||
NLLRegionVariableOrigin::Existential => {
|
||||
// nothing to check here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -940,13 +931,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> RegionDefinition<'tcx> {
|
||||
fn new(origin: RegionVariableOrigin) -> Self {
|
||||
fn new(rv_origin: RegionVariableOrigin) -> Self {
|
||||
// Create a new region definition. Note that, for free
|
||||
// regions, these fields get updated later in
|
||||
// regions, the `external_name` field gets updated later in
|
||||
// `init_universal_regions`.
|
||||
|
||||
let origin = match rv_origin {
|
||||
RegionVariableOrigin::NLL(origin) => origin,
|
||||
_ => NLLRegionVariableOrigin::Existential,
|
||||
};
|
||||
|
||||
Self {
|
||||
origin,
|
||||
is_universal: false,
|
||||
external_name: None,
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ pub fn renumber_mir<'tcx>(infcx: &InferCtxt<'_, '_, 'tcx>, mir: &mut Mir<'tcx>)
|
||||
/// variables.
|
||||
pub fn renumber_regions<'tcx, T>(
|
||||
infcx: &InferCtxt<'_, '_, 'tcx>,
|
||||
ty_context: TyContext,
|
||||
value: &T,
|
||||
) -> T
|
||||
where
|
||||
@ -39,7 +38,7 @@ where
|
||||
infcx
|
||||
.tcx
|
||||
.fold_regions(value, &mut false, |_region, _depth| {
|
||||
let origin = NLLRegionVariableOrigin::Inferred(ty_context);
|
||||
let origin = NLLRegionVariableOrigin::Existential;
|
||||
infcx.next_nll_region_var(origin)
|
||||
})
|
||||
}
|
||||
@ -49,11 +48,11 @@ struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
|
||||
fn renumber_regions<T>(&mut self, ty_context: TyContext, value: &T) -> T
|
||||
fn renumber_regions<T>(&mut self, value: &T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
renumber_regions(self.infcx, ty_context, value)
|
||||
renumber_regions(self.infcx, value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +60,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
|
||||
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
|
||||
debug!("visit_ty(ty={:?}, ty_context={:?})", ty, ty_context);
|
||||
|
||||
*ty = self.renumber_regions(ty_context, ty);
|
||||
*ty = self.renumber_regions(ty);
|
||||
|
||||
debug!("visit_ty: ty={:?}", ty);
|
||||
}
|
||||
@ -69,8 +68,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
|
||||
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, location: Location) {
|
||||
debug!("visit_substs(substs={:?}, location={:?})", substs, location);
|
||||
|
||||
let ty_context = TyContext::Location(location);
|
||||
*substs = self.renumber_regions(ty_context, &{ *substs });
|
||||
*substs = self.renumber_regions(&{ *substs });
|
||||
|
||||
debug!("visit_substs: substs={:?}", substs);
|
||||
}
|
||||
@ -79,15 +77,13 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
|
||||
debug!("visit_region(region={:?}, location={:?})", region, location);
|
||||
|
||||
let old_region = *region;
|
||||
let ty_context = TyContext::Location(location);
|
||||
*region = self.renumber_regions(ty_context, &old_region);
|
||||
*region = self.renumber_regions(&old_region);
|
||||
|
||||
debug!("visit_region: region={:?}", region);
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, constant: &mut &'tcx ty::Const<'tcx>, location: Location) {
|
||||
let ty_context = TyContext::Location(location);
|
||||
*constant = self.renumber_regions(ty_context, &*constant);
|
||||
fn visit_const(&mut self, constant: &mut &'tcx ty::Const<'tcx>, _location: Location) {
|
||||
*constant = self.renumber_regions(&*constant);
|
||||
}
|
||||
|
||||
fn visit_generator_substs(&mut self,
|
||||
@ -99,8 +95,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
|
||||
location,
|
||||
);
|
||||
|
||||
let ty_context = TyContext::Location(location);
|
||||
*substs = self.renumber_regions(ty_context, substs);
|
||||
*substs = self.renumber_regions(substs);
|
||||
|
||||
debug!("visit_generator_substs: substs={:?}", substs);
|
||||
}
|
||||
@ -112,8 +107,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
|
||||
location
|
||||
);
|
||||
|
||||
let ty_context = TyContext::Location(location);
|
||||
*substs = self.renumber_regions(ty_context, substs);
|
||||
*substs = self.renumber_regions(substs);
|
||||
|
||||
debug!("visit_closure_substs: substs={:?}", substs);
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ use borrow_check::nll::renumber;
|
||||
use borrow_check::nll::universal_regions::UniversalRegions;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::infer::InferOk;
|
||||
use rustc::mir::visit::TyContext;
|
||||
use rustc::mir::*;
|
||||
use rustc::traits::query::type_op::custom::CustomTypeOp;
|
||||
use rustc::traits::{ObligationCause, PredicateObligations};
|
||||
@ -117,7 +116,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
||||
let anon_defn_ty = anon_defn_ty.subst(tcx, anon_decl.substs);
|
||||
let anon_defn_ty = renumber::renumber_regions(
|
||||
infcx,
|
||||
TyContext::Location(Location::START),
|
||||
&anon_defn_ty,
|
||||
);
|
||||
debug!(
|
||||
|
Loading…
Reference in New Issue
Block a user