move @mut into scope_info

This commit is contained in:
Niko Matsakis 2013-05-02 21:15:36 -04:00
parent cc62680cc9
commit 9bded76260
4 changed files with 55 additions and 54 deletions

View File

@ -34,7 +34,6 @@ use lib;
use metadata::common::LinkMeta;
use metadata::{csearch, cstore, encoder};
use middle::astencode;
use middle::borrowck::RootInfo;
use middle::resolve;
use middle::trans::_match;
use middle::trans::adt;
@ -62,7 +61,6 @@ use middle::trans::type_of::*;
use middle::ty;
use util::common::indenter;
use util::ppaux::{Repr, ty_to_str};
use util::ppaux;
use core::hash;
use core::hashmap::{HashMap, HashSet};
@ -887,11 +885,10 @@ pub fn need_invoke(bcx: block) -> bool {
// Walk the scopes to look for cleanups
let mut cur = bcx;
loop {
let current = &mut *cur;
let kind = &mut *current.kind;
match *kind {
block_scope(ref mut inf) => {
for vec::each((*inf).cleanups) |cleanup| {
match cur.kind {
block_scope(inf) => {
let inf = &mut *inf; // FIXME(#5074) workaround old borrowck
for vec::each(inf.cleanups) |cleanup| {
match *cleanup {
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
if cleanup_type == normal_exit_and_unwind {
@ -903,7 +900,7 @@ pub fn need_invoke(bcx: block) -> bool {
}
_ => ()
}
cur = match current.parent {
cur = match cur.parent {
Some(next) => next,
None => return false
}
@ -925,11 +922,13 @@ pub fn in_lpad_scope_cx(bcx: block, f: &fn(si: &mut scope_info)) {
let mut bcx = bcx;
loop {
{
// FIXME #4280: Borrow check bug workaround.
let kind: &mut block_kind = &mut *bcx.kind;
match *kind {
block_scope(ref mut inf) => {
if inf.cleanups.len() > 0u || bcx.parent.is_none() {
match bcx.kind {
block_scope(inf) => {
let len = { // FIXME(#5074) workaround old borrowck
let inf = &mut *inf;
inf.cleanups.len()
};
if len > 0u || bcx.parent.is_none() {
f(inf);
return;
}
@ -1194,7 +1193,7 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, kind: block_kind,
}
pub fn simple_block_scope() -> block_kind {
block_scope(scope_info {
block_scope(@mut scope_info {
loop_break: None,
loop_label: None,
cleanups: ~[],
@ -1222,7 +1221,7 @@ pub fn loop_scope_block(bcx: block,
loop_label: Option<ident>,
n: ~str,
opt_node_info: Option<NodeInfo>) -> block {
return new_block(bcx.fcx, Some(bcx), block_scope(scope_info {
return new_block(bcx.fcx, Some(bcx), block_scope(@mut scope_info {
loop_break: Some(loop_break),
loop_label: loop_label,
cleanups: ~[],
@ -1300,28 +1299,28 @@ pub fn cleanup_and_leave(bcx: block,
@fmt!("cleanup_and_leave(%s)", cur.to_str()));
}
{
// FIXME #4280: Borrow check bug workaround.
let kind: &mut block_kind = &mut *cur.kind;
match *kind {
block_scope(ref mut inf) if !inf.cleanups.is_empty() => {
for vec::find((*inf).cleanup_paths,
|cp| cp.target == leave).each |cp| {
Br(bcx, cp.dest);
return;
}
let sub_cx = sub_block(bcx, ~"cleanup");
Br(bcx, sub_cx.llbb);
inf.cleanup_paths.push(cleanup_path {
target: leave,
dest: sub_cx.llbb
});
match cur.kind {
block_scope(inf) if !inf.empty_cleanups() => {
let (sub_cx, inf_cleanups) = {
let inf = &mut *inf; // FIXME(#5074) workaround stage0
for vec::find((*inf).cleanup_paths,
|cp| cp.target == leave).each |cp| {
Br(bcx, cp.dest);
return;
}
let sub_cx = sub_block(bcx, ~"cleanup");
Br(bcx, sub_cx.llbb);
inf.cleanup_paths.push(cleanup_path {
target: leave,
dest: sub_cx.llbb
});
(sub_cx, copy inf.cleanups)
};
bcx = trans_block_cleanups_(sub_cx,
inf.cleanups,
inf_cleanups,
is_lpad);
}
_ => ()
}
_ => ()
}
match upto {

View File

@ -532,6 +532,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
// drop glue checks whether it is zero.
pub fn revoke_clean(cx: block, val: ValueRef) {
do in_scope_cx(cx) |scope_info| {
let scope_info = &mut *scope_info; // FIXME(#5074) workaround borrowck
let cleanup_pos = vec::position(
scope_info.cleanups,
|cu| match *cu {
@ -550,9 +551,9 @@ pub fn revoke_clean(cx: block, val: ValueRef) {
}
pub fn block_cleanups(bcx: block) -> ~[cleanup] {
match *bcx.kind {
match bcx.kind {
block_non_scope => ~[],
block_scope(ref mut inf) => /*bad*/copy inf.cleanups
block_scope(inf) => /*bad*/copy inf.cleanups
}
}
@ -561,7 +562,7 @@ pub enum block_kind {
// cleaned up. May correspond to an actual block in the language, but also
// to an implicit scope, for example, calls introduce an implicit scope in
// which the arguments are evaluated and cleaned up.
block_scope(scope_info),
block_scope(@mut scope_info),
// A non-scope block is a basic block created as a translation artifact
// from translating code that expresses conditional logic rather than by
@ -584,6 +585,12 @@ pub struct scope_info {
landing_pad: Option<BasicBlockRef>,
}
pub impl scope_info {
fn empty_cleanups(&mut self) -> bool {
self.cleanups.is_empty()
}
}
pub trait get_node_info {
fn info(&self) -> Option<NodeInfo>;
}
@ -632,7 +639,7 @@ pub struct block_ {
unreachable: bool,
parent: Option<block>,
// The 'kind' of basic block this is.
kind: @mut block_kind,
kind: block_kind,
// Is this block part of a landing pad?
is_lpad: bool,
// info about the AST node this block originated from, if any
@ -651,7 +658,7 @@ pub fn block_(llbb: BasicBlockRef, parent: Option<block>, kind: block_kind,
terminated: false,
unreachable: false,
parent: parent,
kind: @mut kind,
kind: kind,
is_lpad: is_lpad,
node_info: node_info,
fcx: fcx
@ -699,21 +706,17 @@ pub fn val_str(tn: @TypeNames, v: ValueRef) -> @str {
return ty_str(tn, val_ty(v));
}
pub fn in_scope_cx(cx: block, f: &fn(si: &mut scope_info)) {
pub fn in_scope_cx(cx: block, f: &fn(si: @mut scope_info)) {
let mut cur = cx;
loop {
{
// XXX: Borrow check bug workaround.
let kind: &mut block_kind = &mut *cur.kind;
match *kind {
block_scope(ref mut inf) => {
debug!("in_scope_cx: selected cur=%s (cx=%s)",
cur.to_str(), cx.to_str());
f(inf);
return;
}
_ => ()
match cur.kind {
block_scope(inf) => {
debug!("in_scope_cx: selected cur=%s (cx=%s)",
cur.to_str(), cx.to_str());
f(inf);
return;
}
_ => ()
}
cur = block_parent(cur);
}

View File

@ -243,8 +243,8 @@ pub fn trans_break_cont(bcx: block,
let mut unwind = bcx;
let mut target;
loop {
match *unwind.kind {
block_scope(scope_info {
match unwind.kind {
block_scope(@scope_info {
loop_break: Some(brk),
loop_label: l,
_

View File

@ -123,7 +123,6 @@ use back::abi;
use lib;
use lib::llvm::{ValueRef, TypeRef, llvm};
use metadata::csearch;
use middle::borrowck::root_map_key;
use middle::trans::_match;
use middle::trans::adt;
use middle::trans::asm;