Skip to content

Commit 40498ba

Browse files
committed
simplify NLLRegionVariableOrigin
1 parent 145155d commit 40498ba

File tree

6 files changed

+71
-68
lines changed

6 files changed

+71
-68
lines changed

src/Cargo.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ dependencies = [
8787

8888
[[package]]
8989
name = "atty"
90-
version = "0.2.11"
90+
version = "0.2.10"
9191
source = "registry+https://github.com/rust-lang/crates.io-index"
9292
dependencies = [
9393
"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"
187187
name = "cargo"
188188
version = "0.30.0"
189189
dependencies = [
190-
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
190+
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
191191
"bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
192192
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
193193
"core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -303,7 +303,7 @@ version = "2.32.0"
303303
source = "registry+https://github.com/rust-lang/crates.io-index"
304304
dependencies = [
305305
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
306-
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
306+
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
307307
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
308308
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
309309
"textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -622,7 +622,7 @@ name = "env_logger"
622622
version = "0.5.10"
623623
source = "registry+https://github.com/rust-lang/crates.io-index"
624624
dependencies = [
625-
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
625+
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
626626
"humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
627627
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
628628
"regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1844,7 +1844,7 @@ name = "rustc-ap-rustc_errors"
18441844
version = "182.0.0"
18451845
source = "registry+https://github.com/rust-lang/crates.io-index"
18461846
dependencies = [
1847-
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
1847+
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
18481848
"rustc-ap-rustc_data_structures 182.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
18491849
"rustc-ap-serialize 182.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
18501850
"rustc-ap-syntax_pos 182.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2097,7 +2097,7 @@ dependencies = [
20972097
name = "rustc_errors"
20982098
version = "0.0.0"
20992099
dependencies = [
2100-
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
2100+
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
21012101
"rustc_data_structures 0.0.0",
21022102
"serialize 0.0.0",
21032103
"syntax_pos 0.0.0",
@@ -3056,7 +3056,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
30563056
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
30573057
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
30583058
"checksum assert_cli 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98589b0e465a6c510d95fceebd365bb79bedece7f6e18a480897f2015f85ec51"
3059-
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
3059+
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
30603060
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
30613061
"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
30623062
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"

src/librustc/infer/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,20 @@ pub enum NLLRegionVariableOrigin {
377377
// elsewhere. This origin indices we've got one of those.
378378
FreeRegion,
379379

380-
Inferred(::mir::visit::TyContext),
380+
Existential,
381+
}
382+
383+
impl NLLRegionVariableOrigin {
384+
pub fn is_universal(self) -> bool {
385+
match self {
386+
NLLRegionVariableOrigin::FreeRegion => true,
387+
NLLRegionVariableOrigin::Existential => false,
388+
}
389+
}
390+
391+
pub fn is_existential(self) -> bool {
392+
!self.is_universal()
393+
}
381394
}
382395

383396
#[derive(Copy, Clone, Debug)]

src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2727
writeln!(out, "| Free Region Mapping")?;
2828

2929
for region in self.regions() {
30-
if self.definitions[region].is_universal {
31-
let classification = self.universal_regions.region_classification(region).unwrap();
30+
if self.definitions[region].origin.is_universal() {
31+
let classification = self.universal_regions
32+
.region_classification(region)
33+
.unwrap();
3234
let outlived_by = self.universal_regions.regions_outlived_by(region);
3335
writeln!(
3436
out,

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
// except according to those terms.
1010

1111
use super::universal_regions::UniversalRegions;
12+
use borrow_check::nll::constraints::graph::ConstraintGraph;
1213
use borrow_check::nll::constraints::{
1314
ConstraintIndex, ConstraintSccIndex, ConstraintSet, OutlivesConstraint,
1415
};
15-
use borrow_check::nll::constraints::graph::ConstraintGraph;
1616
use borrow_check::nll::region_infer::values::ToElementIndex;
1717
use borrow_check::nll::type_check::Locations;
1818
use rustc::hir::def_id::DefId;
1919
use rustc::infer::canonical::QueryRegionConstraint;
2020
use rustc::infer::region_constraints::{GenericKind, VarInfos};
21-
use rustc::infer::InferCtxt;
22-
use rustc::infer::NLLRegionVariableOrigin;
23-
use rustc::infer::RegionVariableOrigin;
21+
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin, RegionVariableOrigin};
2422
use rustc::mir::{
2523
ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements, Local, Location,
2624
Mir,
@@ -85,17 +83,10 @@ pub struct RegionInferenceContext<'tcx> {
8583
}
8684

8785
struct RegionDefinition<'tcx> {
88-
/// Why we created this variable. Mostly these will be
89-
/// `RegionVariableOrigin::NLL`, but some variables get created
90-
/// elsewhere in the code with other causes (e.g., instantiation
91-
/// late-bound-regions).
92-
origin: RegionVariableOrigin,
93-
94-
/// True if this is a universally quantified region. This means a
95-
/// lifetime parameter that appears in the function signature (or,
96-
/// in the case of a closure, in the closure environment, which of
97-
/// course is also in the function signature).
98-
is_universal: bool,
86+
/// What kind of variable is this -- a free region? existential
87+
/// variable? etc. (See the `NLLRegionVariableOrigin` for more
88+
/// info.)
89+
origin: NLLRegionVariableOrigin,
9990

10091
/// If this is 'static or an early-bound region, then this is
10192
/// `Some(X)` where `X` is the name of the region.
@@ -287,12 +278,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
287278
for variable in universal_regions.universal_regions() {
288279
// These should be free-region variables.
289280
assert!(match self.definitions[variable].origin {
290-
RegionVariableOrigin::NLL(NLLRegionVariableOrigin::FreeRegion) => true,
291-
_ => false,
281+
NLLRegionVariableOrigin::FreeRegion => true,
282+
NLLRegionVariableOrigin::Existential => false,
292283
});
293284

294-
self.definitions[variable].is_universal = true;
295-
296285
// Add all nodes in the CFG to liveness constraints
297286
for point_index in elements.all_point_indices() {
298287
self.add_live_element(variable, point_index);
@@ -842,24 +831,26 @@ impl<'tcx> RegionInferenceContext<'tcx> {
842831
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'gcx>>>,
843832
errors_buffer: &mut Vec<Diagnostic>,
844833
) {
845-
// The universal regions are always found in a prefix of the
846-
// full list.
847-
let universal_definitions = self.definitions
848-
.iter_enumerated()
849-
.take_while(|(_, fr_definition)| fr_definition.is_universal);
850-
851-
// Go through each of the universal regions `fr` and check that
852-
// they did not grow too large, accumulating any requirements
853-
// for our caller into the `outlives_requirements` vector.
854-
for (fr, _) in universal_definitions {
855-
self.check_universal_region(
856-
infcx,
857-
mir,
858-
mir_def_id,
859-
fr,
860-
&mut propagated_outlives_requirements,
861-
errors_buffer,
862-
);
834+
for (fr, fr_definition) in self.definitions.iter_enumerated() {
835+
match fr_definition.origin {
836+
NLLRegionVariableOrigin::FreeRegion => {
837+
// Go through each of the universal regions `fr` and check that
838+
// they did not grow too large, accumulating any requirements
839+
// for our caller into the `outlives_requirements` vector.
840+
self.check_universal_region(
841+
infcx,
842+
mir,
843+
mir_def_id,
844+
fr,
845+
&mut propagated_outlives_requirements,
846+
errors_buffer,
847+
);
848+
}
849+
850+
NLLRegionVariableOrigin::Existential => {
851+
// nothing to check here
852+
}
853+
}
863854
}
864855
}
865856

@@ -940,13 +931,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
940931
}
941932

942933
impl<'tcx> RegionDefinition<'tcx> {
943-
fn new(origin: RegionVariableOrigin) -> Self {
934+
fn new(rv_origin: RegionVariableOrigin) -> Self {
944935
// Create a new region definition. Note that, for free
945-
// regions, these fields get updated later in
936+
// regions, the `external_name` field gets updated later in
946937
// `init_universal_regions`.
938+
939+
let origin = match rv_origin {
940+
RegionVariableOrigin::NLL(origin) => origin,
941+
_ => NLLRegionVariableOrigin::Existential,
942+
};
943+
947944
Self {
948945
origin,
949-
is_universal: false,
950946
external_name: None,
951947
}
952948
}

src/librustc_mir/borrow_check/nll/renumber.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub fn renumber_mir<'tcx>(infcx: &InferCtxt<'_, '_, 'tcx>, mir: &mut Mir<'tcx>)
2828
/// variables.
2929
pub fn renumber_regions<'tcx, T>(
3030
infcx: &InferCtxt<'_, '_, 'tcx>,
31-
ty_context: TyContext,
3231
value: &T,
3332
) -> T
3433
where
@@ -39,7 +38,7 @@ where
3938
infcx
4039
.tcx
4140
.fold_regions(value, &mut false, |_region, _depth| {
42-
let origin = NLLRegionVariableOrigin::Inferred(ty_context);
41+
let origin = NLLRegionVariableOrigin::Existential;
4342
infcx.next_nll_region_var(origin)
4443
})
4544
}
@@ -49,28 +48,27 @@ struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
4948
}
5049

5150
impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
52-
fn renumber_regions<T>(&mut self, ty_context: TyContext, value: &T) -> T
51+
fn renumber_regions<T>(&mut self, value: &T) -> T
5352
where
5453
T: TypeFoldable<'tcx>,
5554
{
56-
renumber_regions(self.infcx, ty_context, value)
55+
renumber_regions(self.infcx, value)
5756
}
5857
}
5958

6059
impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
6160
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
6261
debug!("visit_ty(ty={:?}, ty_context={:?})", ty, ty_context);
6362

64-
*ty = self.renumber_regions(ty_context, ty);
63+
*ty = self.renumber_regions(ty);
6564

6665
debug!("visit_ty: ty={:?}", ty);
6766
}
6867

6968
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, location: Location) {
7069
debug!("visit_substs(substs={:?}, location={:?})", substs, location);
7170

72-
let ty_context = TyContext::Location(location);
73-
*substs = self.renumber_regions(ty_context, &{ *substs });
71+
*substs = self.renumber_regions(&{ *substs });
7472

7573
debug!("visit_substs: substs={:?}", substs);
7674
}
@@ -79,15 +77,13 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
7977
debug!("visit_region(region={:?}, location={:?})", region, location);
8078

8179
let old_region = *region;
82-
let ty_context = TyContext::Location(location);
83-
*region = self.renumber_regions(ty_context, &old_region);
80+
*region = self.renumber_regions(&old_region);
8481

8582
debug!("visit_region: region={:?}", region);
8683
}
8784

88-
fn visit_const(&mut self, constant: &mut &'tcx ty::Const<'tcx>, location: Location) {
89-
let ty_context = TyContext::Location(location);
90-
*constant = self.renumber_regions(ty_context, &*constant);
85+
fn visit_const(&mut self, constant: &mut &'tcx ty::Const<'tcx>, _location: Location) {
86+
*constant = self.renumber_regions(&*constant);
9187
}
9288

9389
fn visit_generator_substs(&mut self,
@@ -99,8 +95,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
9995
location,
10096
);
10197

102-
let ty_context = TyContext::Location(location);
103-
*substs = self.renumber_regions(ty_context, substs);
98+
*substs = self.renumber_regions(substs);
10499

105100
debug!("visit_generator_substs: substs={:?}", substs);
106101
}
@@ -112,8 +107,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
112107
location
113108
);
114109

115-
let ty_context = TyContext::Location(location);
116-
*substs = self.renumber_regions(ty_context, substs);
110+
*substs = self.renumber_regions(substs);
117111

118112
debug!("visit_closure_substs: substs={:?}", substs);
119113
}

src/librustc_mir/borrow_check/nll/type_check/input_output.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use borrow_check::nll::renumber;
2121
use borrow_check::nll::universal_regions::UniversalRegions;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::infer::InferOk;
24-
use rustc::mir::visit::TyContext;
2524
use rustc::mir::*;
2625
use rustc::traits::query::type_op::custom::CustomTypeOp;
2726
use rustc::traits::{ObligationCause, PredicateObligations};
@@ -117,7 +116,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
117116
let anon_defn_ty = anon_defn_ty.subst(tcx, anon_decl.substs);
118117
let anon_defn_ty = renumber::renumber_regions(
119118
infcx,
120-
TyContext::Location(Location::START),
121119
&anon_defn_ty,
122120
);
123121
debug!(

0 commit comments

Comments
 (0)