Skip to content

Commit df88646

Browse files
committed
librustc: Don't schedule redundant cleanups.
1 parent bedc41b commit df88646

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

src/librustc/middle/trans/_match.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,16 +1255,13 @@ fn compare_values<'a>(
12551255
}
12561256

12571257
fn insert_lllocals<'a>(mut bcx: &'a Block<'a>,
1258-
bindings_map: &BindingsMap,
1259-
cleanup_scope: cleanup::ScopeId)
1258+
bindings_map: &BindingsMap)
12601259
-> &'a Block<'a> {
12611260
/*!
12621261
* For each binding in `data.bindings_map`, adds an appropriate entry into
1263-
* the `fcx.lllocals` map, scheduling cleanup in `cleanup_scope`.
1262+
* the `fcx.lllocals` map
12641263
*/
12651264

1266-
let fcx = bcx.fcx;
1267-
12681265
for (&ident, &binding_info) in bindings_map.iter() {
12691266
let llval = match binding_info.trmode {
12701267
// By value mut binding for a copy type: load from the ptr
@@ -1285,7 +1282,6 @@ fn insert_lllocals<'a>(mut bcx: &'a Block<'a>,
12851282
};
12861283

12871284
let datum = Datum::new(llval, binding_info.ty, Lvalue);
1288-
fcx.schedule_drop_mem(cleanup_scope, llval, binding_info.ty);
12891285

12901286
debug!("binding {:?} to {}",
12911287
binding_info.id,
@@ -1317,21 +1313,11 @@ fn compile_guard<'a, 'b>(
13171313
vec_map_to_str(vals, |v| bcx.val_to_str(*v)));
13181314
let _indenter = indenter();
13191315

1320-
// Lest the guard itself should fail, introduce a temporary cleanup
1321-
// scope for any non-ref bindings we create.
1322-
let temp_scope = bcx.fcx.push_custom_cleanup_scope();
1323-
1324-
let mut bcx = insert_lllocals(bcx, &data.bindings_map,
1325-
cleanup::CustomScope(temp_scope));
1316+
let mut bcx = insert_lllocals(bcx, &data.bindings_map);
13261317

13271318
let val = unpack_datum!(bcx, expr::trans(bcx, guard_expr));
13281319
let val = val.to_llbool(bcx);
13291320

1330-
// Cancel cleanups now that the guard successfully executed. If
1331-
// the guard was false, we will drop the values explicitly
1332-
// below. Otherwise, we'll add lvalue cleanups at the end.
1333-
bcx.fcx.pop_custom_cleanup_scope(temp_scope);
1334-
13351321
return with_cond(bcx, Not(bcx, val), |bcx| {
13361322
// Guard does not match: remove all bindings from the lllocals table
13371323
for (_, &binding_info) in data.bindings_map.iter() {
@@ -1884,12 +1870,9 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
18841870
for arm_data in arm_datas.iter() {
18851871
let mut bcx = arm_data.bodycx;
18861872

1887-
// insert bindings into the lllocals map and add cleanups
1888-
let cleanup_scope = fcx.push_custom_cleanup_scope();
1889-
bcx = insert_lllocals(bcx, &arm_data.bindings_map,
1890-
cleanup::CustomScope(cleanup_scope));
1873+
// insert bindings into the lllocals map
1874+
bcx = insert_lllocals(bcx, &arm_data.bindings_map);
18911875
bcx = expr::trans_into(bcx, &*arm_data.arm.body, dest);
1892-
bcx = fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
18931876
arm_cxs.push(bcx);
18941877
}
18951878

0 commit comments

Comments
 (0)