Skip to content

Commit a0342c8

Browse files
committed
Revert "Make into schedule drop for the destination"
This reverts commit 3702683.
1 parent 321ccbe commit a0342c8

File tree

13 files changed

+247
-466
lines changed

13 files changed

+247
-466
lines changed

src/librustc_mir/build/block.rs

+21-49
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
22
use crate::build::ForGuard::OutsideGuard;
33
use crate::build::matches::ArmHasGuard;
4-
use crate::build::scope::DropKind;
54
use crate::hair::*;
6-
use rustc::middle::region;
75
use rustc::mir::*;
86
use rustc::hir;
97
use syntax_pos::Span;
108

119
impl<'a, 'tcx> Builder<'a, 'tcx> {
12-
pub fn ast_block(
13-
&mut self,
14-
destination: &Place<'tcx>,
15-
scope: Option<region::Scope>,
16-
block: BasicBlock,
17-
ast_block: &'tcx hir::Block,
18-
source_info: SourceInfo,
19-
) -> BlockAnd<()> {
10+
pub fn ast_block(&mut self,
11+
destination: &Place<'tcx>,
12+
block: BasicBlock,
13+
ast_block: &'tcx hir::Block,
14+
source_info: SourceInfo)
15+
-> BlockAnd<()> {
2016
let Block {
2117
region_scope,
2218
opt_destruction_scope,
@@ -25,61 +21,37 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2521
expr,
2622
targeted_by_break,
2723
safety_mode
28-
} = self.hir.mirror(ast_block);
24+
} =
25+
self.hir.mirror(ast_block);
2926
self.in_opt_scope(opt_destruction_scope.map(|de|(de, source_info)), move |this| {
3027
this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
3128
if targeted_by_break {
3229
// This is a `break`-able block
3330
let exit_block = this.cfg.start_new_block();
34-
if let Some(scope) = scope {
35-
// Breakable blocks assign to their destination on each
36-
// `break`, as well as when they exit normally. So we
37-
// can't schedule the drop in the last expression like
38-
// normal blocks do.
39-
let local = destination.as_local()
40-
.expect("cannot schedule drop of non-Local place");
41-
this.schedule_drop(span, scope, local, DropKind::Value);
42-
}
4331
let block_exit = this.in_breakable_scope(
4432
None, exit_block, destination.clone(), |this| {
45-
this.ast_block_stmts(
46-
destination,
47-
None,
48-
block,
49-
span,
50-
stmts,
51-
expr,
52-
safety_mode,
53-
)
33+
this.ast_block_stmts(destination, block, span, stmts, expr,
34+
safety_mode)
5435
});
5536
this.cfg.terminate(unpack!(block_exit), source_info,
5637
TerminatorKind::Goto { target: exit_block });
5738
exit_block.unit()
5839
} else {
59-
this.ast_block_stmts(
60-
destination,
61-
scope,
62-
block,
63-
span,
64-
stmts,
65-
expr,
66-
safety_mode,
67-
)
40+
this.ast_block_stmts(destination, block, span, stmts, expr,
41+
safety_mode)
6842
}
6943
})
7044
})
7145
}
7246

73-
fn ast_block_stmts(
74-
&mut self,
75-
destination: &Place<'tcx>,
76-
scope: Option<region::Scope>,
77-
mut block: BasicBlock,
78-
span: Span,
79-
stmts: Vec<StmtRef<'tcx>>,
80-
expr: Option<ExprRef<'tcx>>,
81-
safety_mode: BlockSafety,
82-
) -> BlockAnd<()> {
47+
fn ast_block_stmts(&mut self,
48+
destination: &Place<'tcx>,
49+
mut block: BasicBlock,
50+
span: Span,
51+
stmts: Vec<StmtRef<'tcx>>,
52+
expr: Option<ExprRef<'tcx>>,
53+
safety_mode: BlockSafety)
54+
-> BlockAnd<()> {
8355
let this = self;
8456

8557
// This convoluted structure is to avoid using recursion as we walk down a list
@@ -205,7 +177,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
205177
this.block_context.currently_ignores_tail_results();
206178
this.block_context.push(BlockFrame::TailExpr { tail_result_is_ignored });
207179

208-
unpack!(block = this.into(destination, scope, block, expr));
180+
unpack!(block = this.into(destination, block, expr));
209181
let popped = this.block_context.pop();
210182

211183
assert!(popped.map_or(false, |bf|bf.is_tail_expr()));

src/librustc_mir/build/expr/as_rvalue.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
136136
this.cfg
137137
.push_assign(block, source_info, &Place::from(result), box_);
138138

139-
// Initialize the box contents. No scope is needed since the
140-
// `Box` is already scheduled to be dropped.
139+
// initialize the box contents:
141140
unpack!(
142141
block = this.into(
143142
&Place::from(result).deref(),
144-
None,
145-
block,
146-
value
143+
block, value
147144
)
148145
);
149146
block.and(Rvalue::Use(Operand::Move(Place::from(result))))

src/librustc_mir/build/expr/as_temp.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
109109
}
110110
}
111111

112-
unpack!(block = this.into(temp_place, temp_lifetime, block, expr));
112+
unpack!(block = this.into(temp_place, block, expr));
113+
114+
if let Some(temp_lifetime) = temp_lifetime {
115+
this.schedule_drop(
116+
expr_span,
117+
temp_lifetime,
118+
temp,
119+
DropKind::Value,
120+
);
121+
}
113122

114123
block.and(temp)
115124
}

src/librustc_mir/build/expr/into.rs

+9-37
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
33
use crate::build::expr::category::{Category, RvalueFunc};
44
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
5-
use crate::build::scope::DropKind;
65
use crate::hair::*;
7-
use rustc::middle::region;
86
use rustc::mir::*;
97
use rustc::ty;
108

@@ -13,18 +11,15 @@ use rustc_target::spec::abi::Abi;
1311
impl<'a, 'tcx> Builder<'a, 'tcx> {
1412
/// Compile `expr`, storing the result into `destination`, which
1513
/// is assumed to be uninitialized.
16-
/// If a `drop_scope` is provided, `destination` is scheduled to be dropped
17-
/// in `scope` once it has been initialized.
1814
pub fn into_expr(
1915
&mut self,
2016
destination: &Place<'tcx>,
21-
scope: Option<region::Scope>,
2217
mut block: BasicBlock,
2318
expr: Expr<'tcx>,
2419
) -> BlockAnd<()> {
2520
debug!(
26-
"into_expr(destination={:?}, scope={:?}, block={:?}, expr={:?})",
27-
destination, scope, block, expr
21+
"into_expr(destination={:?}, block={:?}, expr={:?})",
22+
destination, block, expr
2823
);
2924

3025
// since we frequently have to reference `self` from within a
@@ -40,14 +35,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4035
_ => false,
4136
};
4237

43-
let schedule_drop = move |this: &mut Self| {
44-
if let Some(drop_scope) = scope {
45-
let local = destination.as_local()
46-
.expect("cannot schedule drop of non-Local place");
47-
this.schedule_drop(expr_span, drop_scope, local, DropKind::Value);
48-
}
49-
};
50-
5138
if !expr_is_block_or_scope {
5239
this.block_context.push(BlockFrame::SubExpr);
5340
}
@@ -60,14 +47,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6047
} => {
6148
let region_scope = (region_scope, source_info);
6249
this.in_scope(region_scope, lint_level, |this| {
63-
this.into(destination, scope, block, value)
50+
this.into(destination, block, value)
6451
})
6552
}
6653
ExprKind::Block { body: ast_block } => {
67-
this.ast_block(destination, scope, block, ast_block, source_info)
54+
this.ast_block(destination, block, ast_block, source_info)
6855
}
6956
ExprKind::Match { scrutinee, arms } => {
70-
this.match_expr(destination, scope, expr_span, block, scrutinee, arms)
57+
this.match_expr(destination, expr_span, block, scrutinee, arms)
7158
}
7259
ExprKind::NeverToAny { source } => {
7360
let source = this.hir.mirror(source);
@@ -80,7 +67,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8067

8168
// This is an optimization. If the expression was a call then we already have an
8269
// unreachable block. Don't bother to terminate it and create a new one.
83-
schedule_drop(this);
8470
if is_call {
8571
block.unit()
8672
} else {
@@ -178,9 +164,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178164
TerminatorKind::Goto { target: loop_block },
179165
);
180166

181-
// Loops assign to their destination on each `break`. Since we
182-
// can't easily unschedule drops, we schedule the drop now.
183-
schedule_drop(this);
184167
this.in_breakable_scope(
185168
Some(loop_block),
186169
exit_block,
@@ -202,8 +185,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
202185
// introduce a unit temporary as the destination for the loop body.
203186
let tmp = this.get_unit_temp();
204187
// Execute the body, branching back to the test.
205-
// No scope is provided, since we've scheduled the drop above.
206-
let body_block_end = unpack!(this.into(&tmp, None, body_block, body));
188+
let body_block_end = unpack!(this.into(&tmp, body_block, body));
207189
this.cfg.terminate(
208190
body_block_end,
209191
source_info,
@@ -252,14 +234,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
252234
is_block_tail: None,
253235
});
254236
let ptr_temp = Place::from(ptr_temp);
255-
// No need for a scope, ptr_temp doesn't need drop
256-
let block = unpack!(this.into(&ptr_temp, None, block, ptr));
257-
// Maybe we should provide a scope here so that
258-
// `move_val_init` wouldn't leak on panic even with an
259-
// arbitrary `val` expression, but `schedule_drop`,
260-
// borrowck and drop elaboration all prevent us from
261-
// dropping `ptr_temp.deref()`.
262-
this.into(&ptr_temp.deref(), None, block, val)
237+
let block = unpack!(this.into(&ptr_temp, block, ptr));
238+
this.into(&ptr_temp.deref(), block, val)
263239
} else {
264240
let args: Vec<_> = args
265241
.into_iter()
@@ -289,12 +265,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
289265
from_hir_call,
290266
},
291267
);
292-
schedule_drop(this);
293268
success.unit()
294269
}
295270
}
296271
ExprKind::Use { source } => {
297-
this.into(destination, scope, block, source)
272+
this.into(destination, block, source)
298273
}
299274

300275
// These cases don't actually need a destination
@@ -321,7 +296,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
321296
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
322297
this.cfg
323298
.push_assign(block, source_info, destination, rvalue);
324-
schedule_drop(this);
325299
block.unit()
326300
}
327301
ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => {
@@ -341,7 +315,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
341315
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
342316
this.cfg
343317
.push_assign(block, source_info, destination, rvalue);
344-
schedule_drop(this);
345318
block.unit()
346319
}
347320

@@ -373,7 +346,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
373346

374347
let rvalue = unpack!(block = this.as_local_rvalue(block, expr));
375348
this.cfg.push_assign(block, source_info, destination, rvalue);
376-
schedule_drop(this);
377349
block.unit()
378350
}
379351
};

src/librustc_mir/build/into.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,26 @@
66
77
use crate::build::{BlockAnd, Builder};
88
use crate::hair::*;
9-
use rustc::middle::region;
109
use rustc::mir::*;
1110

1211
pub(in crate::build) trait EvalInto<'tcx> {
1312
fn eval_into(
1413
self,
1514
builder: &mut Builder<'_, 'tcx>,
1615
destination: &Place<'tcx>,
17-
scope: Option<region::Scope>,
1816
block: BasicBlock,
1917
) -> BlockAnd<()>;
2018
}
2119

2220
impl<'a, 'tcx> Builder<'a, 'tcx> {
23-
pub fn into<E>(
24-
&mut self,
25-
destination: &Place<'tcx>,
26-
scope: Option<region::Scope>,
27-
block: BasicBlock,
28-
expr: E,
29-
) -> BlockAnd<()>
30-
where
31-
E: EvalInto<'tcx>,
21+
pub fn into<E>(&mut self,
22+
destination: &Place<'tcx>,
23+
block: BasicBlock,
24+
expr: E)
25+
-> BlockAnd<()>
26+
where E: EvalInto<'tcx>
3227
{
33-
expr.eval_into(self, destination, scope, block)
28+
expr.eval_into(self, destination, block)
3429
}
3530
}
3631

@@ -39,11 +34,10 @@ impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
3934
self,
4035
builder: &mut Builder<'_, 'tcx>,
4136
destination: &Place<'tcx>,
42-
scope: Option<region::Scope>,
4337
block: BasicBlock,
4438
) -> BlockAnd<()> {
4539
let expr = builder.hir.mirror(self);
46-
builder.into_expr(destination, scope, block, expr)
40+
builder.into_expr(destination, block, expr)
4741
}
4842
}
4943

@@ -52,9 +46,8 @@ impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
5246
self,
5347
builder: &mut Builder<'_, 'tcx>,
5448
destination: &Place<'tcx>,
55-
scope: Option<region::Scope>,
5649
block: BasicBlock,
5750
) -> BlockAnd<()> {
58-
builder.into_expr(destination, scope, block, self)
51+
builder.into_expr(destination, block, self)
5952
}
6053
}

0 commit comments

Comments
 (0)