Skip to content

Commit 2121308

Browse files
committed
---
yaml --- r: 271477 b: refs/heads/auto c: 323d7f4 h: refs/heads/master i: 271475: f1e0fd1
1 parent 64c218d commit 2121308

File tree

11 files changed

+46
-37
lines changed

11 files changed

+46
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 464c02e336f15c6fedb7235e93ec6f8f69411b57
11+
refs/heads/auto: 323d7f4e98c2e6039efb8c9afda405c156d21299
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc/mir/repr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ pub struct VarDecl<'tcx> {
159159
pub mutability: Mutability,
160160
pub name: Name,
161161
pub ty: Ty<'tcx>,
162+
pub scope: ScopeId, // scope in which variable was declared
163+
pub span: Span, // span where variable was declared
162164
}
163165

164166
/// A "temp" is a temporary that we place on the stack. They are

branches/auto/src/librustc_mir/build/block.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
2020
ast_block: &'tcx hir::Block)
2121
-> BlockAnd<()> {
2222
let Block { extent, span, stmts, expr } = self.hir.mirror(ast_block);
23-
self.in_scope(extent, block, move |this| {
23+
self.in_scope(extent, block, move |this, _| {
2424
// This convoluted structure is to avoid using recursion as we walk down a list
2525
// of statements. Basically, the structure we get back is something like:
2626
//
@@ -42,7 +42,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
4242
let Stmt { span: _, kind } = this.hir.mirror(stmt);
4343
match kind {
4444
StmtKind::Expr { scope, expr } => {
45-
unpack!(block = this.in_scope(scope, block, |this| {
45+
unpack!(block = this.in_scope(scope, block, |this, _| {
4646
let expr = this.hir.mirror(expr);
4747
let temp = this.temp(expr.ty.clone());
4848
unpack!(block = this.into(&temp, block, expr));
@@ -51,14 +51,14 @@ impl<'a,'tcx> Builder<'a,'tcx> {
5151
}));
5252
}
5353
StmtKind::Let { remainder_scope, init_scope, pattern, initializer } => {
54-
this.push_scope(remainder_scope, block);
54+
let remainder_scope_id = this.push_scope(remainder_scope, block);
5555
let_extent_stack.push(remainder_scope);
56-
unpack!(block = this.in_scope(init_scope, block, move |this| {
56+
unpack!(block = this.in_scope(init_scope, block, move |this, _| {
5757
// FIXME #30046 ^~~~
5858
if let Some(init) = initializer {
59-
this.expr_into_pattern(block, remainder_scope, pattern, init)
59+
this.expr_into_pattern(block, remainder_scope_id, pattern, init)
6060
} else {
61-
this.declare_bindings(remainder_scope, &pattern);
61+
this.declare_bindings(remainder_scope_id, &pattern);
6262
block.unit()
6363
}
6464
}));

branches/auto/src/librustc_mir/build/expr/as_lvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3737
let expr_span = expr.span;
3838
match expr.kind {
3939
ExprKind::Scope { extent, value } => {
40-
this.in_scope(extent, block, |this| this.as_lvalue(block, value))
40+
this.in_scope(extent, block, |this, _| this.as_lvalue(block, value))
4141
}
4242
ExprKind::Field { lhs, name } => {
4343
let lvalue = unpack!(block = this.as_lvalue(block, lhs));

branches/auto/src/librustc_mir/build/expr/as_operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3535
let this = self;
3636

3737
if let ExprKind::Scope { extent, value } = expr.kind {
38-
return this.in_scope(extent, block, |this| this.as_operand(block, value));
38+
return this.in_scope(extent, block, |this, _| this.as_operand(block, value));
3939
}
4040

4141
let category = Category::of(&expr.kind).unwrap();

branches/auto/src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3737

3838
match expr.kind {
3939
ExprKind::Scope { extent, value } => {
40-
this.in_scope(extent, block, |this| this.as_rvalue(block, value))
40+
this.in_scope(extent, block, |this, _| this.as_rvalue(block, value))
4141
}
4242
ExprKind::InlineAsm { asm, outputs, inputs } => {
4343
let outputs = outputs.into_iter().map(|output| {
@@ -76,7 +76,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
7676
let result = this.temp(expr.ty);
7777
// to start, malloc some memory of suitable type (thus far, uninitialized):
7878
this.cfg.push_assign(block, expr_span, &result, Rvalue::Box(value.ty));
79-
this.in_scope(value_extents, block, |this| {
79+
this.in_scope(value_extents, block, |this, _| {
8080
// schedule a shallow free of that memory, lest we unwind:
8181
this.schedule_box_free(expr_span, value_extents, &result, value.ty);
8282
// initialize the box contents:

branches/auto/src/librustc_mir/build/expr/as_temp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3030
let this = self;
3131

3232
if let ExprKind::Scope { extent, value } = expr.kind {
33-
return this.in_scope(extent, block, |this| this.as_temp(block, value));
33+
return this.in_scope(extent, block, |this, _| this.as_temp(block, value));
3434
}
3535

3636
let expr_ty = expr.ty.clone();

branches/auto/src/librustc_mir/build/expr/into.rs

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

4040
match expr.kind {
4141
ExprKind::Scope { extent, value } => {
42-
this.in_scope(extent, block, |this| this.into(destination, block, value))
42+
this.in_scope(extent, block, |this, _| this.into(destination, block, value))
4343
}
4444
ExprKind::Block { body: ast_block } => {
4545
this.ast_block(destination, block, ast_block)

branches/auto/src/librustc_mir/build/matches/mod.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use build::{BlockAnd, BlockAndExtension, Builder};
1717
use rustc_data_structures::fnv::FnvHashMap;
1818
use rustc::middle::const_eval::ConstVal;
19-
use rustc::middle::region::CodeExtent;
2019
use rustc::middle::ty::{AdtDef, Ty};
2120
use rustc::mir::repr::*;
2221
use hair::*;
@@ -42,9 +41,9 @@ impl<'a,'tcx> Builder<'a,'tcx> {
4241
// suitable extent for all of the bindings in this match. It's
4342
// easiest to do this up front because some of these arms may
4443
// be unreachable or reachable multiple times.
45-
let var_extent = self.extent_of_innermost_scope();
44+
let var_scope_id = self.innermost_scope_id();
4645
for arm in &arms {
47-
self.declare_bindings(var_extent, &arm.patterns[0]);
46+
self.declare_bindings(var_scope_id, &arm.patterns[0]);
4847
}
4948

5049
let mut arm_blocks = ArmBlocks {
@@ -106,7 +105,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
106105

107106
pub fn expr_into_pattern(&mut self,
108107
mut block: BasicBlock,
109-
var_extent: CodeExtent, // lifetime of vars
108+
var_scope_id: ScopeId, // lifetime of vars
110109
irrefutable_pat: Pattern<'tcx>,
111110
initializer: ExprRef<'tcx>)
112111
-> BlockAnd<()> {
@@ -118,7 +117,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
118117
var,
119118
ty,
120119
subpattern: None } => {
121-
let index = self.declare_binding(var_extent,
120+
let index = self.declare_binding(var_scope_id,
122121
mutability,
123122
name,
124123
var,
@@ -131,19 +130,19 @@ impl<'a,'tcx> Builder<'a,'tcx> {
131130
}
132131
let lvalue = unpack!(block = self.as_lvalue(block, initializer));
133132
self.lvalue_into_pattern(block,
134-
var_extent,
133+
var_scope_id,
135134
irrefutable_pat,
136135
&lvalue)
137136
}
138137

139138
pub fn lvalue_into_pattern(&mut self,
140139
mut block: BasicBlock,
141-
var_extent: CodeExtent,
140+
var_scope_id: ScopeId,
142141
irrefutable_pat: Pattern<'tcx>,
143142
initializer: &Lvalue<'tcx>)
144143
-> BlockAnd<()> {
145144
// first, creating the bindings
146-
self.declare_bindings(var_extent, &irrefutable_pat);
145+
self.declare_bindings(var_scope_id, &irrefutable_pat);
147146

148147
// create a dummy candidate
149148
let mut candidate = Candidate {
@@ -170,29 +169,29 @@ impl<'a,'tcx> Builder<'a,'tcx> {
170169
block.unit()
171170
}
172171

173-
pub fn declare_bindings(&mut self, var_extent: CodeExtent, pattern: &Pattern<'tcx>) {
172+
pub fn declare_bindings(&mut self, var_scope_id: ScopeId, pattern: &Pattern<'tcx>) {
174173
match *pattern.kind {
175174
PatternKind::Binding { mutability, name, mode: _, var, ty, ref subpattern } => {
176-
self.declare_binding(var_extent, mutability, name, var, ty, pattern.span);
175+
self.declare_binding(var_scope_id, mutability, name, var, ty, pattern.span);
177176
if let Some(subpattern) = subpattern.as_ref() {
178-
self.declare_bindings(var_extent, subpattern);
177+
self.declare_bindings(var_scope_id, subpattern);
179178
}
180179
}
181180
PatternKind::Array { ref prefix, ref slice, ref suffix } |
182181
PatternKind::Slice { ref prefix, ref slice, ref suffix } => {
183182
for subpattern in prefix.iter().chain(slice).chain(suffix) {
184-
self.declare_bindings(var_extent, subpattern);
183+
self.declare_bindings(var_scope_id, subpattern);
185184
}
186185
}
187186
PatternKind::Constant { .. } | PatternKind::Range { .. } | PatternKind::Wild => {
188187
}
189188
PatternKind::Deref { ref subpattern } => {
190-
self.declare_bindings(var_extent, subpattern);
189+
self.declare_bindings(var_scope_id, subpattern);
191190
}
192191
PatternKind::Leaf { ref subpatterns } |
193192
PatternKind::Variant { ref subpatterns, .. } => {
194193
for subpattern in subpatterns {
195-
self.declare_bindings(var_extent, &subpattern.pattern);
194+
self.declare_bindings(var_scope_id, &subpattern.pattern);
196195
}
197196
}
198197
}
@@ -590,25 +589,28 @@ impl<'a,'tcx> Builder<'a,'tcx> {
590589
}
591590

592591
fn declare_binding(&mut self,
593-
var_extent: CodeExtent,
592+
var_scope_id: ScopeId,
594593
mutability: Mutability,
595594
name: Name,
596595
var_id: NodeId,
597596
var_ty: Ty<'tcx>,
598597
span: Span)
599598
-> u32
600599
{
601-
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, var_extent={:?}, span={:?})",
602-
var_id, name, var_ty, var_extent, span);
600+
debug!("declare_binding(var_id={:?}, name={:?}, var_ty={:?}, var_scope_id={:?}, span={:?})",
601+
var_id, name, var_ty, var_scope_id, span);
603602

604603
let index = self.var_decls.len();
605604
self.var_decls.push(VarDecl::<'tcx> {
605+
scope: var_scope_id,
606606
mutability: mutability,
607607
name: name,
608608
ty: var_ty.clone(),
609+
span: span,
609610
});
610611
let index = index as u32;
611-
self.schedule_drop(span, var_extent, &Lvalue::Var(index), var_ty);
612+
let extent = self.scope_auxiliary[var_scope_id.index()].extent;
613+
self.schedule_drop(span, extent, &Lvalue::Var(index), var_ty);
612614
self.var_indices.insert(var_id, index);
613615

614616
debug!("declare_binding: index={:?}", index);

branches/auto/src/librustc_mir/build/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
192192
ast_block: &'tcx hir::Block)
193193
-> BlockAnd<Vec<ArgDecl<'tcx>>>
194194
{
195-
self.in_scope(argument_extent, block, |this| {
195+
self.in_scope(argument_extent, block, |this, argument_scope_id| {
196196
// to start, translate the argument patterns and collect the argument types.
197197
let implicits = implicit_arguments.into_iter().map(|ty| (ty, None));
198198
let explicits = explicit_arguments.into_iter().map(|(ty, pat)| (ty, Some(pat)));
@@ -205,7 +205,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
205205
if let Some(pattern) = pattern {
206206
let pattern = this.hir.irrefutable_pat(pattern);
207207
unpack!(block = this.lvalue_into_pattern(block,
208-
argument_extent,
208+
argument_scope_id,
209209
pattern,
210210
&lvalue));
211211
}

branches/auto/src/librustc_mir/build/scope.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
208208
/// Convenience wrapper that pushes a scope and then executes `f`
209209
/// to build its contents, popping the scope afterwards.
210210
pub fn in_scope<F, R>(&mut self, extent: CodeExtent, mut block: BasicBlock, f: F) -> BlockAnd<R>
211-
where F: FnOnce(&mut Builder<'a, 'tcx>) -> BlockAnd<R>
211+
where F: FnOnce(&mut Builder<'a, 'tcx>, ScopeId) -> BlockAnd<R>
212212
{
213213
debug!("in_scope(extent={:?}, block={:?})", extent, block);
214-
self.push_scope(extent, block);
215-
let rv = unpack!(block = f(self));
214+
let id = self.push_scope(extent, block);
215+
let rv = unpack!(block = f(self, id));
216216
unpack!(block = self.pop_scope(extent, block));
217217
debug!("in_scope: exiting extent={:?} block={:?}", extent, block);
218218
block.and(rv)
@@ -222,7 +222,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
222222
/// scope and call `pop_scope` afterwards. Note that these two
223223
/// calls must be paired; using `in_scope` as a convenience
224224
/// wrapper maybe preferable.
225-
pub fn push_scope(&mut self, extent: CodeExtent, entry: BasicBlock) {
225+
pub fn push_scope(&mut self, extent: CodeExtent, entry: BasicBlock) -> ScopeId {
226226
debug!("push_scope({:?})", extent);
227227
let parent_id = self.scopes.last().map(|s| s.id);
228228
let id = ScopeId::new(self.scope_data_vec.vec.len());
@@ -240,6 +240,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
240240
dom: self.cfg.current_location(entry),
241241
postdoms: vec![]
242242
});
243+
id
243244
}
244245

245246
/// Pops a scope, which should have extent `extent`, adding any
@@ -321,6 +322,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
321322
}.unwrap_or_else(|| hir.span_bug(span, "no enclosing loop scope found?"))
322323
}
323324

325+
pub fn innermost_scope_id(&self) -> ScopeId {
326+
self.scopes.last().map(|scope| scope.id).unwrap()
327+
}
328+
324329
pub fn extent_of_innermost_scope(&self) -> CodeExtent {
325330
self.scopes.last().map(|scope| scope.extent).unwrap()
326331
}

0 commit comments

Comments
 (0)