Skip to content

Commit 37a6d16

Browse files
committed
---
yaml --- r: 147635 b: refs/heads/try2 c: 89a85e4 h: refs/heads/master i: 147633: 1493e66 147631: 9257fa9 v: v3
1 parent 67ff933 commit 37a6d16

File tree

3 files changed

+82
-55
lines changed

3 files changed

+82
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3b1a7b5ca9406c2cedf24f6b14c21720e2b3b470
8+
refs/heads/try2: 89a85e45c5e29f4b465b01ac0afa3986b19ababf
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,8 @@ pub fn need_invoke(bcx: @Block) -> bool {
971971
loop {
972972
cur_scope = match cur_scope {
973973
Some(inf) => {
974-
for cleanup in inf.cleanups.iter() {
974+
let cleanups = inf.cleanups.borrow();
975+
for cleanup in cleanups.get().iter() {
975976
match *cleanup {
976977
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
977978
if cleanup_type == normal_exit_and_unwind {
@@ -1221,7 +1222,7 @@ pub fn simple_block_scope(parent: Option<@mut ScopeInfo>,
12211222
parent: parent,
12221223
loop_break: None,
12231224
loop_label: None,
1224-
cleanups: ~[],
1225+
cleanups: RefCell::new(~[]),
12251226
cleanup_paths: ~[],
12261227
landing_pad: None,
12271228
node_info: node_info,
@@ -1251,7 +1252,7 @@ pub fn loop_scope_block(bcx: @Block,
12511252
parent: None,
12521253
loop_break: Some(loop_break),
12531254
loop_label: loop_label,
1254-
cleanups: ~[],
1255+
cleanups: RefCell::new(~[]),
12551256
cleanup_paths: ~[],
12561257
landing_pad: None,
12571258
node_info: opt_node_info,
@@ -1334,7 +1335,8 @@ pub fn cleanup_and_leave(bcx: @Block,
13341335
{
13351336
let r = (*inf).cleanup_paths.rev_iter().find(|cp| cp.target == leave);
13361337
for cp in r.iter() {
1337-
if cp.size == inf.cleanups.len() {
1338+
let cleanups = inf.cleanups.borrow();
1339+
if cp.size == cleanups.get().len() {
13381340
Br(bcx, cp.dest);
13391341
return;
13401342
}
@@ -1345,12 +1347,13 @@ pub fn cleanup_and_leave(bcx: @Block,
13451347
}
13461348
let sub_cx = sub_block(bcx, "cleanup");
13471349
Br(bcx, sub_cx.llbb);
1350+
let cleanups = inf.cleanups.borrow();
13481351
inf.cleanup_paths.push(cleanup_path {
13491352
target: leave,
1350-
size: inf.cleanups.len(),
1353+
size: cleanups.get().len(),
13511354
dest: sub_cx.llbb
13521355
});
1353-
(sub_cx, dest, inf.cleanups.tailn(skip).to_owned())
1356+
(sub_cx, dest, cleanups.get().tailn(skip).to_owned())
13541357
};
13551358
bcx = trans_block_cleanups_(sub_cx,
13561359
inf_cleanups,
@@ -1394,8 +1397,11 @@ pub fn cleanup_block(bcx: @Block, upto: Option<BasicBlockRef>) -> @Block{
13941397
let mut cur_scope = cur.scope.get();
13951398
loop {
13961399
cur_scope = match cur_scope {
1397-
Some (inf) => {
1398-
bcx = trans_block_cleanups_(bcx, inf.cleanups.to_owned(), false);
1400+
Some(inf) => {
1401+
let cleanups = inf.cleanups.borrow();
1402+
bcx = trans_block_cleanups_(bcx,
1403+
cleanups.get().to_owned(),
1404+
false);
13991405
inf.parent
14001406
}
14011407
None => break
@@ -1443,7 +1449,7 @@ pub fn with_scope(bcx: @Block,
14431449
let scope = simple_block_scope(bcx.scope.get(), opt_node_info);
14441450
bcx.scope.set(Some(scope));
14451451
let ret = f(bcx);
1446-
let ret = trans_block_cleanups_(ret, (scope.cleanups).clone(), false);
1452+
let ret = trans_block_cleanups_(ret, scope.cleanups.get(), false);
14471453
bcx.scope.set(scope.parent);
14481454
ret
14491455
}
@@ -1458,9 +1464,7 @@ pub fn with_scope_result(bcx: @Block,
14581464
let scope = simple_block_scope(bcx.scope.get(), opt_node_info);
14591465
bcx.scope.set(Some(scope));
14601466
let Result { bcx: out_bcx, val } = f(bcx);
1461-
let out_bcx = trans_block_cleanups_(out_bcx,
1462-
(scope.cleanups).clone(),
1463-
false);
1467+
let out_bcx = trans_block_cleanups_(out_bcx, scope.cleanups.get(), false);
14641468
bcx.scope.set(scope.parent);
14651469

14661470
rslt(out_bcx, val)

branches/try2/src/librustc/middle/trans/common.rs

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,14 @@ pub fn add_clean(bcx: @Block, val: ValueRef, t: ty::t) {
457457

458458
let cleanup_type = cleanup_type(bcx.tcx(), t);
459459
in_scope_cx(bcx, None, |scope_info| {
460-
scope_info.cleanups.push(clean(@TypeDroppingCleanupFunction {
461-
val: val,
462-
t: t,
463-
} as @CleanupFunction,
464-
cleanup_type));
460+
{
461+
let mut cleanups = scope_info.cleanups.borrow_mut();
462+
cleanups.get().push(clean(@TypeDroppingCleanupFunction {
463+
val: val,
464+
t: t,
465+
} as @CleanupFunction,
466+
cleanup_type));
467+
}
465468
grow_scope_clean(scope_info);
466469
})
467470
}
@@ -473,12 +476,15 @@ pub fn add_clean_temp_immediate(cx: @Block, val: ValueRef, ty: ty::t) {
473476
ty.repr(cx.tcx()));
474477
let cleanup_type = cleanup_type(cx.tcx(), ty);
475478
in_scope_cx(cx, None, |scope_info| {
476-
scope_info.cleanups.push(clean_temp(val,
477-
@ImmediateTypeDroppingCleanupFunction {
478-
val: val,
479-
t: ty,
480-
} as @CleanupFunction,
481-
cleanup_type));
479+
{
480+
let mut cleanups = scope_info.cleanups.borrow_mut();
481+
cleanups.get().push(clean_temp(val,
482+
@ImmediateTypeDroppingCleanupFunction {
483+
val: val,
484+
t: ty,
485+
} as @CleanupFunction,
486+
cleanup_type));
487+
}
482488
grow_scope_clean(scope_info);
483489
})
484490
}
@@ -502,12 +508,15 @@ pub fn add_clean_temp_mem_in_scope_(bcx: @Block, scope_id: Option<ast::NodeId>,
502508
t.repr(bcx.tcx()));
503509
let cleanup_type = cleanup_type(bcx.tcx(), t);
504510
in_scope_cx(bcx, scope_id, |scope_info| {
505-
scope_info.cleanups.push(clean_temp(val,
506-
@TypeDroppingCleanupFunction {
507-
val: val,
508-
t: t,
509-
} as @CleanupFunction,
510-
cleanup_type));
511+
{
512+
let mut cleanups = scope_info.cleanups.borrow_mut();
513+
cleanups.get().push(clean_temp(val,
514+
@TypeDroppingCleanupFunction {
515+
val: val,
516+
t: t,
517+
} as @CleanupFunction,
518+
cleanup_type));
519+
}
511520
grow_scope_clean(scope_info);
512521
})
513522
}
@@ -531,16 +540,19 @@ pub fn add_clean_return_to_mut(bcx: @Block,
531540
bcx.val_to_str(frozen_val_ref),
532541
bcx.val_to_str(bits_val_ref));
533542
in_scope_cx(bcx, Some(scope_id), |scope_info| {
534-
scope_info.cleanups.push(clean_temp(
535-
frozen_val_ref,
536-
@WriteGuardReleasingCleanupFunction {
537-
root_key: root_key,
538-
frozen_val_ref: frozen_val_ref,
539-
bits_val_ref: bits_val_ref,
540-
filename_val: filename_val,
541-
line_val: line_val,
542-
} as @CleanupFunction,
543-
normal_exit_only));
543+
{
544+
let mut cleanups = scope_info.cleanups.borrow_mut();
545+
cleanups.get().push(clean_temp(
546+
frozen_val_ref,
547+
@WriteGuardReleasingCleanupFunction {
548+
root_key: root_key,
549+
frozen_val_ref: frozen_val_ref,
550+
bits_val_ref: bits_val_ref,
551+
filename_val: filename_val,
552+
line_val: line_val,
553+
} as @CleanupFunction,
554+
normal_exit_only));
555+
}
544556
grow_scope_clean(scope_info);
545557
})
546558
}
@@ -558,9 +570,12 @@ pub fn add_clean_free(cx: @Block, ptr: ValueRef, heap: heap) {
558570
}
559571
};
560572
in_scope_cx(cx, None, |scope_info| {
561-
scope_info.cleanups.push(clean_temp(ptr,
562-
free_fn,
563-
normal_exit_and_unwind));
573+
{
574+
let mut cleanups = scope_info.cleanups.borrow_mut();
575+
cleanups.get().push(clean_temp(ptr,
576+
free_fn,
577+
normal_exit_and_unwind));
578+
}
564579
grow_scope_clean(scope_info);
565580
})
566581
}
@@ -571,16 +586,23 @@ pub fn add_clean_free(cx: @Block, ptr: ValueRef, heap: heap) {
571586
// drop glue checks whether it is zero.
572587
pub fn revoke_clean(cx: @Block, val: ValueRef) {
573588
in_scope_cx(cx, None, |scope_info| {
574-
let cleanup_pos = scope_info.cleanups.iter().position(
575-
|cu| match *cu {
576-
clean_temp(v, _, _) if v == val => true,
577-
_ => false
578-
});
589+
let cleanup_pos = {
590+
let mut cleanups = scope_info.cleanups.borrow_mut();
591+
cleanups.get().iter().position(|cu| {
592+
match *cu {
593+
clean_temp(v, _, _) if v == val => true,
594+
_ => false
595+
}
596+
})
597+
};
579598
for i in cleanup_pos.iter() {
580-
scope_info.cleanups =
581-
vec::append(scope_info.cleanups.slice(0u, *i).to_owned(),
582-
scope_info.cleanups.slice(*i + 1u,
583-
scope_info.cleanups.len()));
599+
let new_cleanups = {
600+
let cleanups = scope_info.cleanups.borrow();
601+
vec::append(cleanups.get().slice(0u, *i).to_owned(),
602+
cleanups.get().slice(*i + 1u, cleanups.get()
603+
.len()))
604+
};
605+
scope_info.cleanups.set(new_cleanups);
584606
shrink_scope_clean(scope_info, *i);
585607
}
586608
})
@@ -589,7 +611,7 @@ pub fn revoke_clean(cx: @Block, val: ValueRef) {
589611
pub fn block_cleanups(bcx: &Block) -> ~[cleanup] {
590612
match bcx.scope.get() {
591613
None => ~[],
592-
Some(inf) => inf.cleanups.clone(),
614+
Some(inf) => inf.cleanups.get(),
593615
}
594616
}
595617

@@ -600,7 +622,7 @@ pub struct ScopeInfo {
600622
// A list of functions that must be run at when leaving this
601623
// block, cleaning up any variables that were introduced in the
602624
// block.
603-
cleanups: ~[cleanup],
625+
cleanups: RefCell<~[cleanup]>,
604626
// Existing cleanup paths that may be reused, indexed by destination and
605627
// cleared when the set of cleanups changes.
606628
cleanup_paths: ~[cleanup_path],
@@ -612,7 +634,8 @@ pub struct ScopeInfo {
612634

613635
impl ScopeInfo {
614636
pub fn empty_cleanups(&mut self) -> bool {
615-
self.cleanups.is_empty()
637+
let cleanups = self.cleanups.borrow();
638+
cleanups.get().is_empty()
616639
}
617640
}
618641

0 commit comments

Comments
 (0)