Skip to content

Commit 37961db

Browse files
committed
Auto merge of #55959 - matthewjasper:remove-end-region, r=nikomatsakis
Cleanup from lexical MIR borrowck removal Lexical MIR borrowck was removed months ago now, and `EndRegion`s are no longer used for MIRI verification. * Remove `rustc::mir::StatementKind::EndRegion` and the `-Zemit_end_regions` flag * Use `RegionVid` instead of `Region` in BorrowSet * Rewrite drop generation to create fewer goto terminators. r? @nikomatsakis
2 parents 2dd94c1 + 1d7fc0c commit 37961db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+207
-1560
lines changed

src/librustc/ich/impls_mir.rs

-3
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ for mir::StatementKind<'gcx> {
217217
mir::StatementKind::StorageDead(ref place) => {
218218
place.hash_stable(hcx, hasher);
219219
}
220-
mir::StatementKind::EndRegion(ref region_scope) => {
221-
region_scope.hash_stable(hcx, hasher);
222-
}
223220
mir::StatementKind::EscapeToRaw(ref place) => {
224221
place.hash_stable(hcx, hasher);
225222
}

src/librustc/mir/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use hir::def::CtorKind;
1616
use hir::def_id::DefId;
1717
use hir::{self, HirId, InlineAsm};
18-
use middle::region;
1918
use mir::interpret::{ConstValue, EvalErrorKind, Scalar};
2019
use mir::visit::MirVisitable;
2120
use rustc_apfloat::ieee::{Double, Single};
@@ -1789,10 +1788,6 @@ pub enum StatementKind<'tcx> {
17891788
/// for more details.
17901789
EscapeToRaw(Operand<'tcx>),
17911790

1792-
/// Mark one terminating point of a region scope (i.e. static region).
1793-
/// (The starting point(s) arise implicitly from borrows.)
1794-
EndRegion(region::Scope),
1795-
17961791
/// Encodes a user's type ascription. These need to be preserved
17971792
/// intact so that NLL can respect them. For example:
17981793
///
@@ -1846,8 +1841,6 @@ impl<'tcx> Debug for Statement<'tcx> {
18461841
match self.kind {
18471842
Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv),
18481843
FakeRead(ref cause, ref place) => write!(fmt, "FakeRead({:?}, {:?})", cause, place),
1849-
// (reuse lifetime rendering policy from ppaux.)
1850-
EndRegion(ref ce) => write!(fmt, "EndRegion({})", ty::ReScope(*ce)),
18511844
Retag { fn_entry, ref place } =>
18521845
write!(fmt, "Retag({}{:?})", if fn_entry { "[fn entry] " } else { "" }, place),
18531846
EscapeToRaw(ref place) => write!(fmt, "EscapeToRaw({:?})", place),
@@ -3028,7 +3021,6 @@ EnumTypeFoldableImpl! {
30283021
(StatementKind::InlineAsm) { asm, outputs, inputs },
30293022
(StatementKind::Retag) { fn_entry, place },
30303023
(StatementKind::EscapeToRaw)(place),
3031-
(StatementKind::EndRegion)(a),
30323024
(StatementKind::AscribeUserType)(a, v, b),
30333025
(StatementKind::Nop),
30343026
}

src/librustc/mir/visit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ macro_rules! make_mir_visitor {
377377
location
378378
);
379379
}
380-
StatementKind::EndRegion(_) => {}
381380
StatementKind::SetDiscriminant{ ref $($mutability)* place, .. } => {
382381
self.visit_place(
383382
place,

src/librustc/session/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11491149
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
11501150
identify_regions: bool = (false, parse_bool, [UNTRACKED],
11511151
"make unnamed regions display as '# (where # is some non-ident unique id)"),
1152-
emit_end_regions: bool = (false, parse_bool, [UNTRACKED],
1153-
"emit EndRegion as part of MIR; enable transforms that solely process EndRegion"),
11541152
borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED],
11551153
"select which borrowck is used (`ast`, `mir`, `migrate`, or `compare`)"),
11561154
two_phase_borrows: bool = (false, parse_bool, [UNTRACKED],

src/librustc/ty/context.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1540,13 +1540,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15401540
}
15411541
}
15421542

1543-
/// Should we emit EndRegion MIR statements? These are consumed by
1544-
/// MIR borrowck, but not when NLL is used.
1545-
pub fn emit_end_regions(self) -> bool {
1546-
self.sess.opts.debugging_opts.emit_end_regions ||
1547-
self.use_mir_borrowck()
1548-
}
1549-
15501543
#[inline]
15511544
pub fn local_crate_exports_generics(self) -> bool {
15521545
debug_assert!(self.sess.opts.share_generics());

src/librustc_codegen_ssa/mir/statement.rs

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
105105
bx
106106
}
107107
mir::StatementKind::FakeRead(..) |
108-
mir::StatementKind::EndRegion(..) |
109108
mir::StatementKind::Retag { .. } |
110109
mir::StatementKind::EscapeToRaw { .. } |
111110
mir::StatementKind::AscribeUserType(..) |

src/librustc_mir/borrow_check/borrow_set.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// except according to those terms.
1010

1111
use borrow_check::place_ext::PlaceExt;
12+
use borrow_check::nll::ToRegionVid;
1213
use dataflow::indexes::BorrowIndex;
1314
use dataflow::move_paths::MoveData;
1415
use rustc::mir::traversal;
1516
use rustc::mir::visit::{
1617
PlaceContext, Visitor, NonUseContext, MutatingUseContext, NonMutatingUseContext
1718
};
1819
use rustc::mir::{self, Location, Mir, Place, Local};
19-
use rustc::ty::{Region, TyCtxt};
20+
use rustc::ty::{RegionVid, TyCtxt};
2021
use rustc::util::nodemap::{FxHashMap, FxHashSet};
2122
use rustc_data_structures::indexed_vec::IndexVec;
2223
use rustc_data_structures::bit_set::BitSet;
@@ -42,7 +43,7 @@ crate struct BorrowSet<'tcx> {
4243

4344
/// Every borrow has a region; this maps each such regions back to
4445
/// its borrow-indexes.
45-
crate region_map: FxHashMap<Region<'tcx>, FxHashSet<BorrowIndex>>,
46+
crate region_map: FxHashMap<RegionVid, FxHashSet<BorrowIndex>>,
4647

4748
/// Map from local to all the borrows on that local
4849
crate local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
@@ -77,7 +78,7 @@ crate struct BorrowData<'tcx> {
7778
/// What kind of borrow this is
7879
crate kind: mir::BorrowKind,
7980
/// The region for which this borrow is live
80-
crate region: Region<'tcx>,
81+
crate region: RegionVid,
8182
/// Place from which we are borrowing
8283
crate borrowed_place: mir::Place<'tcx>,
8384
/// Place to which the borrow was stored
@@ -92,13 +93,7 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
9293
mir::BorrowKind::Unique => "uniq ",
9394
mir::BorrowKind::Mut { .. } => "mut ",
9495
};
95-
let region = self.region.to_string();
96-
let separator = if !region.is_empty() {
97-
" "
98-
} else {
99-
""
100-
};
101-
write!(w, "&{}{}{}{:?}", region, separator, kind, self.borrowed_place)
96+
write!(w, "&{:?} {}{:?}", self.region, kind, self.borrowed_place)
10297
}
10398
}
10499

@@ -189,7 +184,7 @@ struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
189184
idx_vec: IndexVec<BorrowIndex, BorrowData<'tcx>>,
190185
location_map: FxHashMap<Location, BorrowIndex>,
191186
activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
192-
region_map: FxHashMap<Region<'tcx>, FxHashSet<BorrowIndex>>,
187+
region_map: FxHashMap<RegionVid, FxHashSet<BorrowIndex>>,
193188
local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
194189

195190
/// When we encounter a 2-phase borrow statement, it will always
@@ -219,6 +214,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
219214
return;
220215
}
221216

217+
let region = region.to_region_vid();
218+
222219
let borrow = BorrowData {
223220
kind,
224221
region,
@@ -230,7 +227,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
230227
let idx = self.idx_vec.push(borrow);
231228
self.location_map.insert(location, idx);
232229

233-
self.insert_as_pending_if_two_phase(location, &assigned_place, region, kind, idx);
230+
self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
234231

235232
self.region_map.entry(region).or_default().insert(idx);
236233
if let Some(local) = borrowed_place.root_local() {
@@ -314,7 +311,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
314311
let borrow_data = &self.idx_vec[borrow_index];
315312
assert_eq!(borrow_data.reserve_location, location);
316313
assert_eq!(borrow_data.kind, kind);
317-
assert_eq!(borrow_data.region, region);
314+
assert_eq!(borrow_data.region, region.to_region_vid());
318315
assert_eq!(borrow_data.borrowed_place, *place);
319316
}
320317

@@ -347,13 +344,12 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
347344
&mut self,
348345
start_location: Location,
349346
assigned_place: &mir::Place<'tcx>,
350-
region: Region<'tcx>,
351347
kind: mir::BorrowKind,
352348
borrow_index: BorrowIndex,
353349
) {
354350
debug!(
355-
"Borrows::insert_as_pending_if_two_phase({:?}, {:?}, {:?}, {:?})",
356-
start_location, assigned_place, region, borrow_index,
351+
"Borrows::insert_as_pending_if_two_phase({:?}, {:?}, {:?})",
352+
start_location, assigned_place, borrow_index,
357353
);
358354

359355
if !self.allow_two_phase_borrow(kind) {

src/librustc_mir/borrow_check/mod.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use borrow_check::nll::region_infer::RegionInferenceContext;
1414
use rustc::hir;
1515
use rustc::hir::Node;
1616
use rustc::hir::def_id::DefId;
17-
use rustc::hir::map::definitions::DefPathData;
1817
use rustc::infer::InferCtxt;
1918
use rustc::lint::builtin::UNUSED_MUT;
2019
use rustc::middle::borrowck::SignalledError;
@@ -162,10 +161,6 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
162161
move_data: move_data,
163162
param_env: param_env,
164163
};
165-
let body_id = match tcx.def_key(def_id).disambiguated_data.data {
166-
DefPathData::StructCtor | DefPathData::EnumVariant(_) => None,
167-
_ => Some(tcx.hir.body_owned_by(id)),
168-
};
169164

170165
let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
171166
let mut flow_inits = FlowAtLocation::new(do_dataflow(
@@ -212,7 +207,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
212207
id,
213208
&attributes,
214209
&dead_unwinds,
215-
Borrows::new(tcx, mir, regioncx.clone(), def_id, body_id, &borrow_set),
210+
Borrows::new(tcx, mir, regioncx.clone(), &borrow_set),
216211
|rs, i| DebugFormatted::new(&rs.location(i)),
217212
));
218213
let flow_uninits = FlowAtLocation::new(do_dataflow(
@@ -592,10 +587,6 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
592587
self.consume_operand(context, (input, span), flow_state);
593588
}
594589
}
595-
StatementKind::EndRegion(ref _rgn) => {
596-
// ignored when consuming results (update to
597-
// flow_state already handled).
598-
}
599590
StatementKind::Nop
600591
| StatementKind::AscribeUserType(..)
601592
| StatementKind::Retag { .. }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
206206
let mir = self.mir;
207207
let tcx = self.infcx.tcx;
208208

209-
let borrow_region_vid = regioncx.to_region_vid(borrow.region);
209+
let borrow_region_vid = borrow.region;
210210
debug!(
211211
"explain_why_borrow_contains_point: borrow_region_vid={:?}",
212212
borrow_region_vid

src/librustc_mir/borrow_check/nll/invalidation.rs

-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
132132
self.consume_operand(context, input);
133133
}
134134
}
135-
// EndRegion matters to older NLL/MIR AST borrowck, not to alias NLL
136-
StatementKind::EndRegion(..) |
137135
StatementKind::Nop |
138136
StatementKind::AscribeUserType(..) |
139137
StatementKind::Retag { .. } |

src/librustc_mir/borrow_check/nll/renumber.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use rustc::ty::subst::Substs;
1212
use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, Ty, TypeFoldable};
13-
use rustc::mir::{BasicBlock, Location, Mir, Statement, StatementKind, UserTypeAnnotation};
13+
use rustc::mir::{Location, Mir, UserTypeAnnotation};
1414
use rustc::mir::visit::{MutVisitor, TyContext};
1515
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
1616

@@ -119,16 +119,4 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
119119

120120
debug!("visit_closure_substs: substs={:?}", substs);
121121
}
122-
123-
fn visit_statement(
124-
&mut self,
125-
block: BasicBlock,
126-
statement: &mut Statement<'tcx>,
127-
location: Location,
128-
) {
129-
if let StatementKind::EndRegion(_) = statement.kind {
130-
statement.kind = StatementKind::Nop;
131-
}
132-
self.super_statement(block, statement, location);
133-
}
134122
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13141314
| StatementKind::StorageLive(..)
13151315
| StatementKind::StorageDead(..)
13161316
| StatementKind::InlineAsm { .. }
1317-
| StatementKind::EndRegion(_)
13181317
| StatementKind::Retag { .. }
13191318
| StatementKind::EscapeToRaw { .. }
13201319
| StatementKind::Nop => {}

src/librustc_mir/build/cfg.rs

-26
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
//! Routines for manipulating the control-flow graph.
1515
1616
use build::CFG;
17-
use rustc::middle::region;
1817
use rustc::mir::*;
19-
use rustc::ty::TyCtxt;
2018

2119
impl<'tcx> CFG<'tcx> {
2220
pub fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
@@ -45,30 +43,6 @@ impl<'tcx> CFG<'tcx> {
4543
self.block_data_mut(block).statements.push(statement);
4644
}
4745

48-
pub fn push_end_region<'a, 'gcx:'a+'tcx>(&mut self,
49-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
50-
block: BasicBlock,
51-
source_info: SourceInfo,
52-
region_scope: region::Scope) {
53-
if tcx.emit_end_regions() {
54-
if let region::ScopeData::CallSite = region_scope.data {
55-
// The CallSite scope (aka the root scope) is sort of weird, in that it is
56-
// supposed to "separate" the "interior" and "exterior" of a closure. Being
57-
// that, it is not really a part of the region hierarchy, but for some
58-
// reason it *is* considered a part of it.
59-
//
60-
// It should die a hopefully painful death with NLL, so let's leave this hack
61-
// for now so that nobody can complain about soundness.
62-
return
63-
}
64-
65-
self.push(block, Statement {
66-
source_info,
67-
kind: StatementKind::EndRegion(region_scope),
68-
});
69-
}
70-
}
71-
7246
pub fn push_assign(&mut self,
7347
block: BasicBlock,
7448
source_info: SourceInfo,

0 commit comments

Comments
 (0)