Skip to content

Commit a658bb2

Browse files
committed
Paired source_info with extent; thread both through to pts where EndRegion will need construction.
1 parent cbed41a commit a658bb2

File tree

9 files changed

+40
-32
lines changed

9 files changed

+40
-32
lines changed

src/librustc_mir/build/block.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
2323
-> BlockAnd<()> {
2424
let Block { extent, opt_destruction_extent, span, stmts, expr, targeted_by_break } =
2525
self.hir.mirror(ast_block);
26-
self.in_opt_scope(opt_destruction_extent, block, move |this| {
27-
this.in_scope(extent, block, move |this| {
26+
self.in_opt_scope(opt_destruction_extent.map(|de|(de, source_info)), block, move |this| {
27+
this.in_scope((extent, source_info), block, move |this| {
2828
if targeted_by_break {
2929
// This is a `break`-able block (currently only `catch { ... }`)
3030
let exit_block = this.cfg.start_new_block();
@@ -69,16 +69,18 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
6969
// First we build all the statements in the block.
7070
let mut let_extent_stack = Vec::with_capacity(8);
7171
let outer_visibility_scope = this.visibility_scope;
72+
let source_info = this.source_info(span);
7273
for stmt in stmts {
7374
let Stmt { span: _, kind, opt_destruction_extent } = this.hir.mirror(stmt);
7475
match kind {
7576
StmtKind::Expr { scope, expr } => {
76-
unpack!(block = this.in_opt_scope(opt_destruction_extent, block, |this| {
77-
this.in_scope(scope, block, |this| {
78-
let expr = this.hir.mirror(expr);
79-
this.stmt_expr(block, expr)
80-
})
81-
}));
77+
unpack!(block = this.in_opt_scope(
78+
opt_destruction_extent.map(|de|(de, source_info)), block, |this| {
79+
this.in_scope((scope, source_info), block, |this| {
80+
let expr = this.hir.mirror(expr);
81+
this.stmt_expr(block, expr)
82+
})
83+
}));
8284
}
8385
StmtKind::Let { remainder_scope, init_scope, pattern, initializer } => {
8486
let tcx = this.hir.tcx();
@@ -95,9 +97,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
9597
// Evaluate the initializer, if present.
9698
if let Some(init) = initializer {
9799
unpack!(block = this.in_opt_scope(
98-
opt_destruction_extent, block, move |this| {
99-
this.in_scope(init_scope, block, move |this| {
100-
// FIXME #30046 ^~~~
100+
opt_destruction_extent.map(|de|(de, source_info)), block, move |this| {
101+
this.in_scope((init_scope, source_info), block, move |this| {
102+
// FIXME #30046 ^~~~
101103
this.expr_into_pattern(block, pattern, init)
102104
})
103105
}));
@@ -126,7 +128,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
126128
// Finally, we pop all the let scopes before exiting out from the scope of block
127129
// itself.
128130
for extent in let_extent_stack.into_iter().rev() {
129-
unpack!(block = this.pop_scope(extent, block));
131+
unpack!(block = this.pop_scope((extent, source_info), block));
130132
}
131133
// Restore the original visibility scope.
132134
this.visibility_scope = outer_visibility_scope;

src/librustc_mir/build/expr/as_lvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4040
let source_info = this.source_info(expr_span);
4141
match expr.kind {
4242
ExprKind::Scope { extent, value } => {
43-
this.in_scope(extent, block, |this| this.as_lvalue(block, value))
43+
this.in_scope((extent, source_info), block, |this| this.as_lvalue(block, value))
4444
}
4545
ExprKind::Field { lhs, name } => {
4646
let lvalue = unpack!(block = this.as_lvalue(block, lhs));

src/librustc_mir/build/expr/as_operand.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5656
let this = self;
5757

5858
if let ExprKind::Scope { extent, value } = expr.kind {
59+
let source_info = this.source_info(expr.span);
60+
let extent = (extent, source_info);
5961
return this.in_scope(extent, block, |this| {
6062
this.as_operand(block, scope, value)
6163
});

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5959

6060
match expr.kind {
6161
ExprKind::Scope { extent, value } => {
62+
let extent = (extent, source_info);
6263
this.in_scope(extent, block, |this| this.as_rvalue(block, scope, value))
6364
}
6465
ExprKind::Repeat { value, count } => {
@@ -99,7 +100,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
99100
// to start, malloc some memory of suitable type (thus far, uninitialized):
100101
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
101102
this.cfg.push_assign(block, source_info, &result, box_);
102-
this.in_scope(value_extents, block, |this| {
103+
this.in_scope((value_extents, source_info), block, |this| {
103104
// schedule a shallow free of that memory, lest we unwind:
104105
this.schedule_box_free(expr_span, value_extents, &result, value.ty);
105106
// initialize the box contents:

src/librustc_mir/build/expr/as_temp.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
3939
block, temp_lifetime, expr);
4040
let this = self;
4141

42+
let expr_span = expr.span;
43+
let source_info = this.source_info(expr_span);
4244
if let ExprKind::Scope { extent, value } = expr.kind {
43-
return this.in_scope(extent, block, |this| {
45+
return this.in_scope((extent, source_info), block, |this| {
4446
this.as_temp(block, temp_lifetime, value)
4547
});
4648
}
4749

4850
let expr_ty = expr.ty.clone();
49-
let expr_span = expr.span;
5051
let temp = this.temp(expr_ty.clone(), expr_span);
5152
let source_info = this.source_info(expr_span);
5253

src/librustc_mir/build/expr/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
3939

4040
match expr.kind {
4141
ExprKind::Scope { extent, value } => {
42+
let extent = (extent, source_info);
4243
this.in_scope(extent, block, |this| this.into(destination, block, value))
4344
}
4445
ExprKind::Block { body: ast_block } => {

src/librustc_mir/build/expr/stmt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
2424
match expr.kind {
2525
ExprKind::Scope { extent, value } => {
2626
let value = this.hir.mirror(value);
27-
this.in_scope(extent, block, |this| this.stmt_expr(block, value))
27+
this.in_scope((extent, source_info), block, |this| this.stmt_expr(block, value))
2828
}
2929
ExprKind::Assign { lhs, rhs } => {
3030
let lhs = this.hir.mirror(lhs);
@@ -81,7 +81,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
8181
*this.find_breakable_scope(expr_span, label);
8282
let continue_block = continue_block.expect(
8383
"Attempted to continue in non-continuable breakable block");
84-
this.exit_scope(expr_span, extent, block, continue_block);
84+
this.exit_scope(expr_span, (extent, source_info), block, continue_block);
8585
this.cfg.start_new_block().unit()
8686
}
8787
ExprKind::Break { label, value } => {
@@ -99,7 +99,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
9999
} else {
100100
this.cfg.push_assign_unit(block, source_info, &destination)
101101
}
102-
this.exit_scope(expr_span, extent, block, break_block);
102+
this.exit_scope(expr_span, (extent, source_info), block, break_block);
103103
this.cfg.start_new_block().unit()
104104
}
105105
ExprKind::Return { value } => {
@@ -116,7 +116,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
116116
};
117117
let extent = this.extent_of_return_scope();
118118
let return_block = this.return_block();
119-
this.exit_scope(expr_span, extent, block, return_block);
119+
this.exit_scope(expr_span, (extent, source_info), block, return_block);
120120
this.cfg.start_new_block().unit()
121121
}
122122
ExprKind::InlineAsm { asm, outputs, inputs } => {

src/librustc_mir/build/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
339339
let call_site_extent = CodeExtent::CallSiteScope(body.id());
340340
let arg_extent = CodeExtent::ParameterScope(body.id());
341341
let mut block = START_BLOCK;
342-
unpack!(block = builder.in_scope(call_site_extent, block, |builder| {
343-
unpack!(block = builder.in_scope(arg_extent, block, |builder| {
342+
let source_info = builder.source_info(span);
343+
unpack!(block = builder.in_scope((call_site_extent, source_info), block, |builder| {
344+
unpack!(block = builder.in_scope((arg_extent, source_info), block, |builder| {
344345
builder.args_and_body(block, &arguments, arg_extent, &body.value)
345346
}));
346347
// Attribute epilogue to function's closing brace

src/librustc_mir/build/scope.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
270270
}
271271

272272
pub fn in_opt_scope<F, R>(&mut self,
273-
opt_extent: Option<CodeExtent>,
273+
opt_extent: Option<(CodeExtent, SourceInfo)>,
274274
mut block: BasicBlock,
275275
f: F)
276276
-> BlockAnd<R>
277277
where F: FnOnce(&mut Builder<'a, 'gcx, 'tcx>) -> BlockAnd<R>
278278
{
279279
debug!("in_opt_scope(opt_extent={:?}, block={:?})", opt_extent, block);
280-
if let Some(extent) = opt_extent { self.push_scope(extent); }
280+
if let Some(extent) = opt_extent { self.push_scope(extent.0); }
281281
let rv = unpack!(block = f(self));
282282
if let Some(extent) = opt_extent {
283283
unpack!(block = self.pop_scope(extent, block));
@@ -289,14 +289,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
289289
/// Convenience wrapper that pushes a scope and then executes `f`
290290
/// to build its contents, popping the scope afterwards.
291291
pub fn in_scope<F, R>(&mut self,
292-
extent: CodeExtent,
292+
extent: (CodeExtent, SourceInfo),
293293
mut block: BasicBlock,
294294
f: F)
295295
-> BlockAnd<R>
296296
where F: FnOnce(&mut Builder<'a, 'gcx, 'tcx>) -> BlockAnd<R>
297297
{
298298
debug!("in_scope(extent={:?}, block={:?})", extent, block);
299-
self.push_scope(extent);
299+
self.push_scope(extent.0);
300300
let rv = unpack!(block = f(self));
301301
unpack!(block = self.pop_scope(extent, block));
302302
debug!("in_scope: exiting extent={:?} block={:?}", extent, block);
@@ -324,15 +324,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
324324
/// drops onto the end of `block` that are needed. This must
325325
/// match 1-to-1 with `push_scope`.
326326
pub fn pop_scope(&mut self,
327-
extent: CodeExtent,
327+
extent: (CodeExtent, SourceInfo),
328328
mut block: BasicBlock)
329329
-> BlockAnd<()> {
330330
debug!("pop_scope({:?}, {:?})", extent, block);
331331
// We need to have `cached_block`s available for all the drops, so we call diverge_cleanup
332332
// to make sure all the `cached_block`s are filled in.
333333
self.diverge_cleanup();
334334
let scope = self.scopes.pop().unwrap();
335-
assert_eq!(scope.extent, extent);
335+
assert_eq!(scope.extent, extent.0);
336336
unpack!(block = build_scope_drops(&mut self.cfg,
337337
&scope,
338338
&self.scopes,
@@ -348,11 +348,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
348348
/// module comment for details.
349349
pub fn exit_scope(&mut self,
350350
span: Span,
351-
extent: CodeExtent,
351+
extent: (CodeExtent, SourceInfo),
352352
mut block: BasicBlock,
353353
target: BasicBlock) {
354354
debug!("exit_scope(extent={:?}, block={:?}, target={:?})", extent, block, target);
355-
let scope_count = 1 + self.scopes.iter().rev().position(|scope| scope.extent == extent)
355+
let scope_count = 1 + self.scopes.iter().rev().position(|scope| scope.extent == extent.0)
356356
.unwrap_or_else(||{
357357
span_bug!(span, "extent {:?} does not enclose", extent)
358358
});
@@ -363,15 +363,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
363363
let mut rest = &mut self.scopes[(len - scope_count)..];
364364
while let Some((scope, rest_)) = {rest}.split_last_mut() {
365365
rest = rest_;
366-
block = if let Some(&e) = scope.cached_exits.get(&(target, extent)) {
366+
block = if let Some(&e) = scope.cached_exits.get(&(target, extent.0)) {
367367
self.cfg.terminate(block, scope.source_info(span),
368368
TerminatorKind::Goto { target: e });
369369
return;
370370
} else {
371371
let b = self.cfg.start_new_block();
372372
self.cfg.terminate(block, scope.source_info(span),
373373
TerminatorKind::Goto { target: b });
374-
scope.cached_exits.insert((target, extent), b);
374+
scope.cached_exits.insert((target, extent.0), b);
375375
b
376376
};
377377
unpack!(block = build_scope_drops(&mut self.cfg,

0 commit comments

Comments
 (0)