From 7acaa73377e9ed8b337a66c968286e6581dc7b24 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 21 Dec 2013 15:51:39 -0800 Subject: [PATCH] librustc: De-`@mut` `ScopeInfo::cleanup_paths` --- src/librustc/middle/trans/base.rs | 15 +++++++++++---- src/librustc/middle/trans/common.rs | 13 ++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index ecd6258bf0f..f576d1cc97a 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1223,7 +1223,7 @@ pub fn simple_block_scope(parent: Option<@mut ScopeInfo>, loop_break: None, loop_label: None, cleanups: RefCell::new(~[]), - cleanup_paths: ~[], + cleanup_paths: RefCell::new(~[]), landing_pad: None, node_info: node_info, } @@ -1253,7 +1253,7 @@ pub fn loop_scope_block(bcx: @Block, loop_break: Some(loop_break), loop_label: loop_label, cleanups: RefCell::new(~[]), - cleanup_paths: ~[], + cleanup_paths: RefCell::new(~[]), landing_pad: None, node_info: opt_node_info, }), bcx.is_lpad, n, opt_node_info); @@ -1333,7 +1333,12 @@ pub fn cleanup_and_leave(bcx: @Block, let mut skip = 0; let mut dest = None; { - let r = (*inf).cleanup_paths.rev_iter().find(|cp| cp.target == leave); + let cleanup_paths = inf.cleanup_paths.borrow(); + let r = cleanup_paths.get() + .rev_iter() + .find(|cp| { + cp.target == leave + }); for cp in r.iter() { let cleanups = inf.cleanups.borrow(); if cp.size == cleanups.get().len() { @@ -1348,7 +1353,9 @@ pub fn cleanup_and_leave(bcx: @Block, let sub_cx = sub_block(bcx, "cleanup"); Br(bcx, sub_cx.llbb); let cleanups = inf.cleanups.borrow(); - inf.cleanup_paths.push(cleanup_path { + let mut cleanup_paths = inf.cleanup_paths + .borrow_mut(); + cleanup_paths.get().push(cleanup_path { target: leave, size: cleanups.get().len(), dest: sub_cx.llbb diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 9e25756fc49..9940bdac8d8 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -432,8 +432,15 @@ pub struct cleanup_path { pub fn shrink_scope_clean(scope_info: &mut ScopeInfo, size: uint) { scope_info.landing_pad = None; - scope_info.cleanup_paths = scope_info.cleanup_paths.iter() - .take_while(|&cu| cu.size <= size).map(|&x|x).collect(); + let new_cleanup_paths = { + let cleanup_paths = scope_info.cleanup_paths.borrow(); + cleanup_paths.get() + .iter() + .take_while(|&cu| cu.size <= size) + .map(|&x| x) + .collect() + }; + scope_info.cleanup_paths.set(new_cleanup_paths) } pub fn grow_scope_clean(scope_info: &mut ScopeInfo) { @@ -625,7 +632,7 @@ pub struct ScopeInfo { cleanups: RefCell<~[cleanup]>, // Existing cleanup paths that may be reused, indexed by destination and // cleared when the set of cleanups changes. - cleanup_paths: ~[cleanup_path], + cleanup_paths: RefCell<~[cleanup_path]>, // Unwinding landing pad. Also cleared when cleanups change. landing_pad: Option, // info about the AST node this scope originated from, if any