]> git.lizzy.rs Git - rust.git/commitdiff
simplify `NLLRegionVariableOrigin`
authorNiko Matsakis <niko@alum.mit.edu>
Sun, 22 Jul 2018 16:42:40 +0000 (19:42 +0300)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 25 Jul 2018 03:38:19 +0000 (06:38 +0300)
src/Cargo.lock
src/librustc/infer/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs
src/librustc_mir/borrow_check/nll/region_infer/mod.rs
src/librustc_mir/borrow_check/nll/renumber.rs
src/librustc_mir/borrow_check/nll/type_check/input_output.rs

index 8594e4ff1306d4c3f436b09ba58589eafce4430a..09baaeadaee43b58d8d7ec7af1ed7e75b412aed0 100644 (file)
@@ -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"
index 9283705b7b78e89dd5f23ff88939774b1dd43c0c..4677f6222d44a8aa68a409735059e7a7a34e939f 100644 (file)
@@ -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)]
index 3c73203706dcb633f019328719ea51c2be7a647e..dfcb185e21d1da6a833286d6be0ecd85f6597360 100644 (file)
@@ -27,8 +27,10 @@ pub(crate) fn dump_mir(&self, out: &mut dyn Write) -> io::Result<()> {
         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,
index 52f596f61c2e803beba22d2ff46402d28fcf9212..a74f4f5539fbc2140285f13015d58db500dc492c 100644 (file)
@@ -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 @@ fn init_universal_regions(&mut self) {
         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 @@ fn check_universal_regions<'gcx>(
         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);
-
-        // 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,
-            );
+        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,
+                    );
+                }
+
+                NLLRegionVariableOrigin::Existential => {
+                    // nothing to check here
+                }
+            }
         }
     }
 
@@ -940,13 +931,18 @@ fn check_universal_region<'gcx>(
 }
 
 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,
         }
     }
index 7edee42b78ff71eab23c338d74ffc0a662a082a9..e1bd8530629d97c80bd432a11cfcb077326ad8c1 100644 (file)
@@ -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 @@ pub fn renumber_regions<'tcx, T>(
     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 @@ fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
     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 @@ fn visit_region(&mut self, region: &mut ty::Region<'tcx>, location: Location) {
         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 @@ fn visit_generator_substs(&mut self,
             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 @@ fn visit_closure_substs(&mut self, substs: &mut ClosureSubsts<'tcx>, location: L
             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);
     }
index 770a0614811dc32ddcce753f8cc26e1f95c2bf4b..3d831bce5ce176ddd8550003c9886c535e092c61 100644 (file)
@@ -21,7 +21,6 @@
 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 @@ pub(super) fn equate_inputs_and_outputs(
                             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!(