Skip to content

Commit 6c10d74

Browse files
committed
Remove the GraphExtents, the design of which seems bogus. They carried
the right information, but it's hard to maintain in the face of optimizations, and in the form that the analyses probably actually want.
1 parent 29a3fe3 commit 6c10d74

File tree

7 files changed

+33
-100
lines changed

7 files changed

+33
-100
lines changed

src/librustc_mir/build/cfg.rs

-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ impl<'tcx> CFG<'tcx> {
2626
&mut self.basic_blocks[blk.index()]
2727
}
2828

29-
pub fn end_point(&self, block: BasicBlock) -> ExecutionPoint {
30-
ExecutionPoint {
31-
block: block,
32-
statement: self.block_data(block).statements.len() as u32,
33-
}
34-
}
35-
3629
pub fn start_new_block(&mut self) -> BasicBlock {
3730
let node_index = self.basic_blocks.len();
3831
self.basic_blocks.push(BasicBlockData::new(Terminator::Diverge));

src/librustc_mir/build/expr/as_rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
7070
this.cfg.push_assign(block, expr_span, &result, rvalue);
7171

7272
// schedule a shallow free of that memory, lest we unwind:
73-
let extent = this.extent_of_innermost_scope().unwrap();
73+
let extent = this.extent_of_innermost_scope();
7474
this.schedule_drop(expr_span, extent, DropKind::Free, &result, value_ty);
7575

7676
// initialize the box contents:

src/librustc_mir/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
206206
}
207207
ExprKind::Return { value } => {
208208
unpack!(block = this.into(&Lvalue::ReturnPointer, block, value));
209-
let extent = this.extent_of_outermost_scope().unwrap();
209+
let extent = this.extent_of_outermost_scope();
210210
this.exit_scope(expr_span, extent, block, END_BLOCK);
211211
this.cfg.start_new_block().unit()
212212
}

src/librustc_mir/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
4242
// suitable extent for all of the bindings in this match. It's
4343
// easiest to do this up front because some of these arms may
4444
// be unreachable or reachable multiple times.
45-
let var_extent = self.extent_of_innermost_scope().unwrap();
45+
let var_extent = self.extent_of_innermost_scope();
4646
for arm in &arms {
4747
self.declare_bindings(var_extent, &arm.patterns[0]);
4848
}

src/librustc_mir/build/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use syntax::codemap::Span;
1919

2020
struct Builder<'a, 'tcx: 'a> {
2121
hir: Cx<'a, 'tcx>,
22-
extents: FnvHashMap<CodeExtent, Vec<GraphExtent>>,
2322
cfg: CFG<'tcx>,
2423
scopes: Vec<scope::Scope<'tcx>>,
2524
loop_scopes: Vec<scope::LoopScope>,
@@ -92,7 +91,6 @@ pub fn construct<'a,'tcx>(mut hir: Cx<'a,'tcx>,
9291
let mut builder = Builder {
9392
hir: hir,
9493
cfg: cfg,
95-
extents: FnvHashMap(),
9694
scopes: vec![],
9795
loop_scopes: vec![],
9896
temp_decls: temp_decls,
@@ -117,7 +115,6 @@ pub fn construct<'a,'tcx>(mut hir: Cx<'a,'tcx>,
117115

118116
Mir {
119117
basic_blocks: builder.cfg.basic_blocks,
120-
extents: builder.extents,
121118
var_decls: builder.var_decls,
122119
arg_decls: arg_decls,
123120
temp_decls: builder.temp_decls,

src/librustc_mir/build/scope.rs

+30-43
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ use syntax::codemap::Span;
9494

9595
pub struct Scope<'tcx> {
9696
extent: CodeExtent,
97-
exits: Vec<ExecutionPoint>,
9897
drops: Vec<(DropKind, Span, Lvalue<'tcx>)>,
9998
cached_block: Option<BasicBlock>,
10099
}
@@ -116,7 +115,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
116115
-> BlockAnd<R>
117116
where F: FnOnce(&mut Builder<'a, 'tcx>) -> BlockAnd<R>
118117
{
119-
let extent = self.extent_of_innermost_scope().unwrap();
118+
let extent = self.extent_of_innermost_scope();
120119
let loop_scope = LoopScope {
121120
extent: extent.clone(),
122121
continue_block: loop_block,
@@ -128,60 +127,50 @@ impl<'a,'tcx> Builder<'a,'tcx> {
128127
r
129128
}
130129

131-
/// Start a scope. The closure `f` should translate the contents
132-
/// of the scope. See module comment for more details.
133-
pub fn in_scope<F, R>(&mut self, extent: CodeExtent, block: BasicBlock, f: F) -> BlockAnd<R>
130+
/// Convenience wrapper that pushes a scope and then executes `f`
131+
/// to build its contents, popping the scope afterwards.
132+
pub fn in_scope<F, R>(&mut self, extent: CodeExtent, mut block: BasicBlock, f: F) -> BlockAnd<R>
134133
where F: FnOnce(&mut Builder<'a, 'tcx>) -> BlockAnd<R>
135134
{
136135
debug!("in_scope(extent={:?}, block={:?})", extent, block);
136+
self.push_scope(extent, block);
137+
let rv = unpack!(block = f(self));
138+
assert_eq!(self.extent_of_innermost_scope(), extent);
139+
self.pop_scope(block);
140+
debug!("in_scope: exiting extent={:?} block={:?}", extent, block);
141+
block.and(rv)
142+
}
137143

138-
let start_point = self.cfg.end_point(block);
144+
/// Push a scope onto the stack. You can then build code in this
145+
/// scope and call `pop_scope` afterwards. Note that these two
146+
/// calls must be paired; using `in_scope` as a convenience
147+
/// wrapper maybe preferable.
148+
pub fn push_scope(&mut self, extent: CodeExtent, block: BasicBlock) {
149+
debug!("push_scope({:?}, {:?})", extent, block);
139150

140151
// push scope, execute `f`, then pop scope again
141152
self.scopes.push(Scope {
142153
extent: extent.clone(),
143154
drops: vec![],
144-
exits: vec![],
145155
cached_block: None,
146156
});
147-
let BlockAnd(fallthrough_block, rv) = f(self);
148-
let mut scope = self.scopes.pop().unwrap();
157+
}
158+
159+
/// Pops the innermost scope, adding any drops onto the end of
160+
/// `block` that are needed. This must match 1-to-1 with
161+
/// `push_scope`.
162+
pub fn pop_scope(&mut self, block: BasicBlock) {
163+
debug!("pop_scope({:?})", block);
164+
let scope = self.scopes.pop().unwrap();
149165

150166
// add in any drops needed on the fallthrough path (any other
151167
// exiting paths, such as those that arise from `break`, will
152168
// have drops already)
153169
for (kind, span, lvalue) in scope.drops {
154-
self.cfg.push_drop(fallthrough_block, span, kind, &lvalue);
170+
self.cfg.push_drop(block, span, kind, &lvalue);
155171
}
156-
157-
// add the implicit fallthrough edge
158-
scope.exits.push(self.cfg.end_point(fallthrough_block));
159-
160-
// compute the extent from start to finish and store it in the graph
161-
let graph_extent = self.graph_extent(start_point, scope.exits);
162-
self.extents.entry(extent)
163-
.or_insert(vec![])
164-
.push(graph_extent);
165-
166-
debug!("in_scope: exiting extent={:?} fallthrough_block={:?}", extent, fallthrough_block);
167-
fallthrough_block.and(rv)
168172
}
169173

170-
/// Creates a graph extent (SEME region) from an entry point and
171-
/// exit points.
172-
fn graph_extent(&self, entry: ExecutionPoint, exits: Vec<ExecutionPoint>) -> GraphExtent {
173-
if exits.len() == 1 && entry.block == exits[0].block {
174-
GraphExtent {
175-
entry: entry,
176-
exit: GraphExtentExit::Statement(exits[0].statement),
177-
}
178-
} else {
179-
GraphExtent {
180-
entry: entry,
181-
exit: GraphExtentExit::Points(exits),
182-
}
183-
}
184-
}
185174

186175
/// Finds the loop scope for a given label. This is used for
187176
/// resolving `break` and `continue`.
@@ -232,8 +221,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
232221
for &(kind, drop_span, ref lvalue) in &scope.drops {
233222
self.cfg.push_drop(block, drop_span, kind, lvalue);
234223
}
235-
236-
scope.exits.push(self.cfg.end_point(block));
237224
}
238225

239226
self.cfg.terminate(block, Terminator::Goto { target: target });
@@ -272,12 +259,12 @@ impl<'a,'tcx> Builder<'a,'tcx> {
272259
}
273260
}
274261

275-
pub fn extent_of_innermost_scope(&self) -> Option<CodeExtent> {
276-
self.scopes.last().map(|scope| scope.extent)
262+
pub fn extent_of_innermost_scope(&self) -> CodeExtent {
263+
self.scopes.last().map(|scope| scope.extent).unwrap()
277264
}
278265

279-
pub fn extent_of_outermost_scope(&self) -> Option<CodeExtent> {
280-
self.scopes.first().map(|scope| scope.extent)
266+
pub fn extent_of_outermost_scope(&self) -> CodeExtent {
267+
self.scopes.first().map(|scope| scope.extent).unwrap()
281268
}
282269
}
283270

src/librustc_mir/repr.rs

-44
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010

1111
use rustc::middle::const_eval::ConstVal;
1212
use rustc::middle::def_id::DefId;
13-
use rustc::middle::region::CodeExtent;
1413
use rustc::middle::subst::Substs;
1514
use rustc::middle::ty::{AdtDef, ClosureSubsts, FnOutput, Region, Ty};
1615
use rustc_back::slice;
17-
use rustc_data_structures::fnv::FnvHashMap;
1816
use rustc_front::hir::InlineAsm;
1917
use syntax::ast::Name;
2018
use syntax::codemap::Span;
@@ -156,48 +154,6 @@ pub struct ArgDecl<'tcx> {
156154
pub ty: Ty<'tcx>,
157155
}
158156

159-
///////////////////////////////////////////////////////////////////////////
160-
// Graph extents
161-
162-
/// A moment in the flow of execution. It corresponds to a point in
163-
/// between two statements:
164-
///
165-
/// BB[block]:
166-
/// <--- if statement == 0
167-
/// STMT[0]
168-
/// <--- if statement == 1
169-
/// STMT[1]
170-
/// ...
171-
/// <--- if statement == n-1
172-
/// STMT[n-1]
173-
/// <--- if statement == n
174-
///
175-
/// where the block has `n` statements.
176-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
177-
pub struct ExecutionPoint {
178-
pub block: BasicBlock,
179-
pub statement: u32,
180-
}
181-
182-
/// A single-entry-multiple-exit region in the graph. We build one of
183-
/// these for every node-id during MIR construction. By construction
184-
/// we are assured that the entry dominates all points within, and
185-
/// that, for every interior point X, it is postdominated by some exit.
186-
pub struct GraphExtent {
187-
pub entry: ExecutionPoint,
188-
pub exit: GraphExtentExit,
189-
}
190-
191-
pub enum GraphExtentExit {
192-
/// `Statement(X)`: a very common special case covering a span
193-
/// that is local to a single block. It starts at the entry point
194-
/// and extends until the start of statement `X` (non-inclusive).
195-
Statement(u32),
196-
197-
/// The more general case where the exits are a set of points.
198-
Points(Vec<ExecutionPoint>),
199-
}
200-
201157
///////////////////////////////////////////////////////////////////////////
202158
// BasicBlock
203159

0 commit comments

Comments
 (0)