Skip to content

Commit 9bded76

Browse files
committed
move @mut into scope_info
1 parent cc62680 commit 9bded76

File tree

4 files changed

+55
-54
lines changed

4 files changed

+55
-54
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use lib;
3434
use metadata::common::LinkMeta;
3535
use metadata::{csearch, cstore, encoder};
3636
use middle::astencode;
37-
use middle::borrowck::RootInfo;
3837
use middle::resolve;
3938
use middle::trans::_match;
4039
use middle::trans::adt;
@@ -62,7 +61,6 @@ use middle::trans::type_of::*;
6261
use middle::ty;
6362
use util::common::indenter;
6463
use util::ppaux::{Repr, ty_to_str};
65-
use util::ppaux;
6664

6765
use core::hash;
6866
use core::hashmap::{HashMap, HashSet};
@@ -887,11 +885,10 @@ pub fn need_invoke(bcx: block) -> bool {
887885
// Walk the scopes to look for cleanups
888886
let mut cur = bcx;
889887
loop {
890-
let current = &mut *cur;
891-
let kind = &mut *current.kind;
892-
match *kind {
893-
block_scope(ref mut inf) => {
894-
for vec::each((*inf).cleanups) |cleanup| {
888+
match cur.kind {
889+
block_scope(inf) => {
890+
let inf = &mut *inf; // FIXME(#5074) workaround old borrowck
891+
for vec::each(inf.cleanups) |cleanup| {
895892
match *cleanup {
896893
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
897894
if cleanup_type == normal_exit_and_unwind {
@@ -903,7 +900,7 @@ pub fn need_invoke(bcx: block) -> bool {
903900
}
904901
_ => ()
905902
}
906-
cur = match current.parent {
903+
cur = match cur.parent {
907904
Some(next) => next,
908905
None => return false
909906
}
@@ -925,11 +922,13 @@ pub fn in_lpad_scope_cx(bcx: block, f: &fn(si: &mut scope_info)) {
925922
let mut bcx = bcx;
926923
loop {
927924
{
928-
// FIXME #4280: Borrow check bug workaround.
929-
let kind: &mut block_kind = &mut *bcx.kind;
930-
match *kind {
931-
block_scope(ref mut inf) => {
932-
if inf.cleanups.len() > 0u || bcx.parent.is_none() {
925+
match bcx.kind {
926+
block_scope(inf) => {
927+
let len = { // FIXME(#5074) workaround old borrowck
928+
let inf = &mut *inf;
929+
inf.cleanups.len()
930+
};
931+
if len > 0u || bcx.parent.is_none() {
933932
f(inf);
934933
return;
935934
}
@@ -1194,7 +1193,7 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, kind: block_kind,
11941193
}
11951194

11961195
pub fn simple_block_scope() -> block_kind {
1197-
block_scope(scope_info {
1196+
block_scope(@mut scope_info {
11981197
loop_break: None,
11991198
loop_label: None,
12001199
cleanups: ~[],
@@ -1222,7 +1221,7 @@ pub fn loop_scope_block(bcx: block,
12221221
loop_label: Option<ident>,
12231222
n: ~str,
12241223
opt_node_info: Option<NodeInfo>) -> block {
1225-
return new_block(bcx.fcx, Some(bcx), block_scope(scope_info {
1224+
return new_block(bcx.fcx, Some(bcx), block_scope(@mut scope_info {
12261225
loop_break: Some(loop_break),
12271226
loop_label: loop_label,
12281227
cleanups: ~[],
@@ -1300,28 +1299,28 @@ pub fn cleanup_and_leave(bcx: block,
13001299
@fmt!("cleanup_and_leave(%s)", cur.to_str()));
13011300
}
13021301

1303-
{
1304-
// FIXME #4280: Borrow check bug workaround.
1305-
let kind: &mut block_kind = &mut *cur.kind;
1306-
match *kind {
1307-
block_scope(ref mut inf) if !inf.cleanups.is_empty() => {
1308-
for vec::find((*inf).cleanup_paths,
1309-
|cp| cp.target == leave).each |cp| {
1310-
Br(bcx, cp.dest);
1311-
return;
1312-
}
1313-
let sub_cx = sub_block(bcx, ~"cleanup");
1314-
Br(bcx, sub_cx.llbb);
1315-
inf.cleanup_paths.push(cleanup_path {
1316-
target: leave,
1317-
dest: sub_cx.llbb
1318-
});
1302+
match cur.kind {
1303+
block_scope(inf) if !inf.empty_cleanups() => {
1304+
let (sub_cx, inf_cleanups) = {
1305+
let inf = &mut *inf; // FIXME(#5074) workaround stage0
1306+
for vec::find((*inf).cleanup_paths,
1307+
|cp| cp.target == leave).each |cp| {
1308+
Br(bcx, cp.dest);
1309+
return;
1310+
}
1311+
let sub_cx = sub_block(bcx, ~"cleanup");
1312+
Br(bcx, sub_cx.llbb);
1313+
inf.cleanup_paths.push(cleanup_path {
1314+
target: leave,
1315+
dest: sub_cx.llbb
1316+
});
1317+
(sub_cx, copy inf.cleanups)
1318+
};
13191319
bcx = trans_block_cleanups_(sub_cx,
1320-
inf.cleanups,
1320+
inf_cleanups,
13211321
is_lpad);
1322-
}
1323-
_ => ()
13241322
}
1323+
_ => ()
13251324
}
13261325

13271326
match upto {

src/librustc/middle/trans/common.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
532532
// drop glue checks whether it is zero.
533533
pub fn revoke_clean(cx: block, val: ValueRef) {
534534
do in_scope_cx(cx) |scope_info| {
535+
let scope_info = &mut *scope_info; // FIXME(#5074) workaround borrowck
535536
let cleanup_pos = vec::position(
536537
scope_info.cleanups,
537538
|cu| match *cu {
@@ -550,9 +551,9 @@ pub fn revoke_clean(cx: block, val: ValueRef) {
550551
}
551552

552553
pub fn block_cleanups(bcx: block) -> ~[cleanup] {
553-
match *bcx.kind {
554+
match bcx.kind {
554555
block_non_scope => ~[],
555-
block_scope(ref mut inf) => /*bad*/copy inf.cleanups
556+
block_scope(inf) => /*bad*/copy inf.cleanups
556557
}
557558
}
558559

@@ -561,7 +562,7 @@ pub enum block_kind {
561562
// cleaned up. May correspond to an actual block in the language, but also
562563
// to an implicit scope, for example, calls introduce an implicit scope in
563564
// which the arguments are evaluated and cleaned up.
564-
block_scope(scope_info),
565+
block_scope(@mut scope_info),
565566

566567
// A non-scope block is a basic block created as a translation artifact
567568
// from translating code that expresses conditional logic rather than by
@@ -584,6 +585,12 @@ pub struct scope_info {
584585
landing_pad: Option<BasicBlockRef>,
585586
}
586587

588+
pub impl scope_info {
589+
fn empty_cleanups(&mut self) -> bool {
590+
self.cleanups.is_empty()
591+
}
592+
}
593+
587594
pub trait get_node_info {
588595
fn info(&self) -> Option<NodeInfo>;
589596
}
@@ -632,7 +639,7 @@ pub struct block_ {
632639
unreachable: bool,
633640
parent: Option<block>,
634641
// The 'kind' of basic block this is.
635-
kind: @mut block_kind,
642+
kind: block_kind,
636643
// Is this block part of a landing pad?
637644
is_lpad: bool,
638645
// 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,
651658
terminated: false,
652659
unreachable: false,
653660
parent: parent,
654-
kind: @mut kind,
661+
kind: kind,
655662
is_lpad: is_lpad,
656663
node_info: node_info,
657664
fcx: fcx
@@ -699,21 +706,17 @@ pub fn val_str(tn: @TypeNames, v: ValueRef) -> @str {
699706
return ty_str(tn, val_ty(v));
700707
}
701708

702-
pub fn in_scope_cx(cx: block, f: &fn(si: &mut scope_info)) {
709+
pub fn in_scope_cx(cx: block, f: &fn(si: @mut scope_info)) {
703710
let mut cur = cx;
704711
loop {
705-
{
706-
// XXX: Borrow check bug workaround.
707-
let kind: &mut block_kind = &mut *cur.kind;
708-
match *kind {
709-
block_scope(ref mut inf) => {
710-
debug!("in_scope_cx: selected cur=%s (cx=%s)",
711-
cur.to_str(), cx.to_str());
712-
f(inf);
713-
return;
714-
}
715-
_ => ()
712+
match cur.kind {
713+
block_scope(inf) => {
714+
debug!("in_scope_cx: selected cur=%s (cx=%s)",
715+
cur.to_str(), cx.to_str());
716+
f(inf);
717+
return;
716718
}
719+
_ => ()
717720
}
718721
cur = block_parent(cur);
719722
}

src/librustc/middle/trans/controlflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ pub fn trans_break_cont(bcx: block,
243243
let mut unwind = bcx;
244244
let mut target;
245245
loop {
246-
match *unwind.kind {
247-
block_scope(scope_info {
246+
match unwind.kind {
247+
block_scope(@scope_info {
248248
loop_break: Some(brk),
249249
loop_label: l,
250250
_

src/librustc/middle/trans/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ use back::abi;
123123
use lib;
124124
use lib::llvm::{ValueRef, TypeRef, llvm};
125125
use metadata::csearch;
126-
use middle::borrowck::root_map_key;
127126
use middle::trans::_match;
128127
use middle::trans::adt;
129128
use middle::trans::asm;

0 commit comments

Comments
 (0)