librustc: De-mut some of trans
This commit is contained in:
parent
cdd6f38220
commit
553c27c515
|
@ -866,8 +866,8 @@ pub fn need_invoke(bcx: block) -> bool {
|
|||
// Walk the scopes to look for cleanups
|
||||
let mut cur = bcx;
|
||||
loop {
|
||||
match cur.kind {
|
||||
block_scope(ref inf) => {
|
||||
match *cur.kind {
|
||||
block_scope(ref mut inf) => {
|
||||
for vec::each((*inf).cleanups) |cleanup| {
|
||||
match *cleanup {
|
||||
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
|
||||
|
@ -898,16 +898,21 @@ pub fn have_cached_lpad(bcx: block) -> bool {
|
|||
return res;
|
||||
}
|
||||
|
||||
pub fn in_lpad_scope_cx(bcx: block, f: fn(scope_info)) {
|
||||
pub fn in_lpad_scope_cx(bcx: block, f: fn(&mut scope_info)) {
|
||||
let mut bcx = bcx;
|
||||
loop {
|
||||
match bcx.kind {
|
||||
block_scope(ref inf) => {
|
||||
if (*inf).cleanups.len() > 0u || bcx.parent.is_none() {
|
||||
f((*inf)); return;
|
||||
{
|
||||
// XXX: 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() {
|
||||
f(inf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
bcx = block_parent(bcx);
|
||||
}
|
||||
|
@ -1198,9 +1203,9 @@ pub fn simple_block_scope() -> block_kind {
|
|||
block_scope(scope_info {
|
||||
loop_break: None,
|
||||
loop_label: None,
|
||||
mut cleanups: ~[],
|
||||
mut cleanup_paths: ~[],
|
||||
mut landing_pad: None
|
||||
cleanups: ~[],
|
||||
cleanup_paths: ~[],
|
||||
landing_pad: None
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1226,9 +1231,9 @@ pub fn loop_scope_block(bcx: block,
|
|||
return new_block(bcx.fcx, Some(bcx), block_scope(scope_info {
|
||||
loop_break: Some(loop_break),
|
||||
loop_label: loop_label,
|
||||
mut cleanups: ~[],
|
||||
mut cleanup_paths: ~[],
|
||||
mut landing_pad: None
|
||||
cleanups: ~[],
|
||||
cleanup_paths: ~[],
|
||||
landing_pad: None
|
||||
}), bcx.is_lpad, n, opt_node_info);
|
||||
}
|
||||
|
||||
|
@ -1301,23 +1306,30 @@ pub fn cleanup_and_leave(bcx: block,
|
|||
@fmt!("cleanup_and_leave(%s)", cur.to_str()));
|
||||
}
|
||||
|
||||
match cur.kind {
|
||||
block_scope(ref inf) if !inf.cleanups.is_empty() => {
|
||||
for vec::find((*inf).cleanup_paths,
|
||||
|cp| cp.target == leave).each |cp| {
|
||||
Br(bcx, cp.dest);
|
||||
return;
|
||||
{
|
||||
// XXX: 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
|
||||
});
|
||||
bcx = trans_block_cleanups_(sub_cx,
|
||||
block_cleanups(cur),
|
||||
is_lpad);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
let sub_cx = sub_block(bcx, ~"cleanup");
|
||||
Br(bcx, sub_cx.llbb);
|
||||
(*inf).cleanup_paths.push(cleanup_path {
|
||||
target: leave,
|
||||
dest: sub_cx.llbb
|
||||
});
|
||||
bcx = trans_block_cleanups_(sub_cx, block_cleanups(cur), is_lpad);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
||||
match upto {
|
||||
Some(bb) => { if cur.llbb == bb { break; } }
|
||||
_ => ()
|
||||
|
|
|
@ -355,7 +355,7 @@ pub struct cleanup_path {
|
|||
dest: BasicBlockRef
|
||||
}
|
||||
|
||||
pub fn scope_clean_changed(scope_info: scope_info) {
|
||||
pub fn scope_clean_changed(scope_info: &mut scope_info) {
|
||||
if scope_info.cleanup_paths.len() > 0u { scope_info.cleanup_paths = ~[]; }
|
||||
scope_info.landing_pad = None;
|
||||
}
|
||||
|
@ -498,9 +498,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 inf) => /*bad*/copy inf.cleanups
|
||||
block_scope(ref mut inf) => /*bad*/copy inf.cleanups
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -524,12 +524,12 @@ pub struct scope_info {
|
|||
// A list of functions that must be run at when leaving this
|
||||
// block, cleaning up any variables that were introduced in the
|
||||
// block.
|
||||
mut cleanups: ~[cleanup],
|
||||
cleanups: ~[cleanup],
|
||||
// Existing cleanup paths that may be reused, indexed by destination and
|
||||
// cleared when the set of cleanups changes.
|
||||
mut cleanup_paths: ~[cleanup_path],
|
||||
cleanup_paths: ~[cleanup_path],
|
||||
// Unwinding landing pad. Also cleared when cleanups change.
|
||||
mut landing_pad: Option<BasicBlockRef>,
|
||||
landing_pad: Option<BasicBlockRef>,
|
||||
}
|
||||
|
||||
pub trait get_node_info {
|
||||
|
@ -574,11 +574,11 @@ pub struct block_ {
|
|||
// instructions into that block by way of this block context.
|
||||
// The block pointing to this one in the function's digraph.
|
||||
llbb: BasicBlockRef,
|
||||
mut terminated: bool,
|
||||
mut unreachable: bool,
|
||||
terminated: bool,
|
||||
unreachable: bool,
|
||||
parent: Option<block>,
|
||||
// The 'kind' of basic block this is.
|
||||
kind: block_kind,
|
||||
kind: @mut block_kind,
|
||||
// Is this block part of a landing pad?
|
||||
is_lpad: bool,
|
||||
// info about the AST node this block originated from, if any
|
||||
|
@ -597,21 +597,19 @@ pub fn block_(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind,
|
|||
terminated: false,
|
||||
unreachable: false,
|
||||
parent: parent,
|
||||
kind: kind,
|
||||
kind: @mut kind,
|
||||
is_lpad: is_lpad,
|
||||
node_info: node_info,
|
||||
fcx: fcx
|
||||
}
|
||||
}
|
||||
|
||||
/* This must be enum and not type, or trans goes into an infinite loop (#2572)
|
||||
*/
|
||||
pub enum block = @block_;
|
||||
pub type block = @mut block_;
|
||||
|
||||
pub fn mk_block(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind,
|
||||
is_lpad: bool, node_info: Option<NodeInfo>, fcx: fn_ctxt)
|
||||
-> block {
|
||||
block(@block_(llbb, parent, kind, is_lpad, node_info, fcx))
|
||||
@mut block_(llbb, parent, kind, is_lpad, node_info, fcx)
|
||||
}
|
||||
|
||||
// First two args are retptr, env
|
||||
|
@ -660,17 +658,21 @@ pub fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn in_scope_cx(cx: block, f: fn(scope_info)) {
|
||||
pub fn in_scope_cx(cx: block, f: &fn(&mut scope_info)) {
|
||||
let mut cur = cx;
|
||||
loop {
|
||||
match cur.kind {
|
||||
block_scope(ref inf) => {
|
||||
debug!("in_scope_cx: selected cur=%s (cx=%s)",
|
||||
cur.to_str(), cx.to_str());
|
||||
f((*inf));
|
||||
return;
|
||||
}
|
||||
_ => ()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
cur = block_parent(cur);
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ pub fn trans_break_cont(bcx: block,
|
|||
let mut unwind = bcx;
|
||||
let mut target;
|
||||
loop {
|
||||
match unwind.kind {
|
||||
match *unwind.kind {
|
||||
block_scope(scope_info {
|
||||
loop_break: Some(brk),
|
||||
loop_label: l,
|
||||
|
|
|
@ -196,7 +196,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
|
|||
struct CtxtRepr {
|
||||
parse_sess: @mut parse::ParseSess,
|
||||
cfg: ast::crate_cfg,
|
||||
backtrace: Option<@ExpnInfo>,
|
||||
backtrace: @mut Option<@ExpnInfo>,
|
||||
mod_path: ~[ast::ident],
|
||||
trace_mac: bool
|
||||
}
|
||||
|
@ -205,33 +205,33 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
|
|||
fn parse_sess(@mut self) -> @mut parse::ParseSess { self.parse_sess }
|
||||
fn cfg(@mut self) -> ast::crate_cfg { self.cfg }
|
||||
fn call_site(@mut self) -> span {
|
||||
match self.backtrace {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
|
||||
None => self.bug(~"missing top span")
|
||||
}
|
||||
}
|
||||
fn print_backtrace(@mut self) { }
|
||||
fn backtrace(@mut self) -> Option<@ExpnInfo> { self.backtrace }
|
||||
fn backtrace(@mut self) -> Option<@ExpnInfo> { *self.backtrace }
|
||||
fn mod_push(@mut self, i: ast::ident) { self.mod_path.push(i); }
|
||||
fn mod_pop(@mut self) { self.mod_path.pop(); }
|
||||
fn mod_path(@mut self) -> ~[ast::ident] { return self.mod_path; }
|
||||
fn bt_push(@mut self, ei: codemap::ExpnInfo) {
|
||||
match ei {
|
||||
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
|
||||
self.backtrace =
|
||||
*self.backtrace =
|
||||
Some(@ExpandedFrom(CallInfo {
|
||||
call_site: span {lo: cs.lo, hi: cs.hi,
|
||||
expn_info: self.backtrace},
|
||||
expn_info: *self.backtrace},
|
||||
callee: (*callee)}));
|
||||
}
|
||||
}
|
||||
}
|
||||
fn bt_pop(@mut self) {
|
||||
match self.backtrace {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(CallInfo {
|
||||
call_site: span {expn_info: prev, _}, _
|
||||
})) => {
|
||||
self.backtrace = prev
|
||||
*self.backtrace = prev
|
||||
}
|
||||
_ => self.bug(~"tried to pop without a push")
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
|
|||
let imp: @mut CtxtRepr = @mut CtxtRepr {
|
||||
parse_sess: parse_sess,
|
||||
cfg: cfg,
|
||||
backtrace: None,
|
||||
backtrace: @mut None,
|
||||
mod_path: ~[],
|
||||
trace_mac: false
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@ use std::oldmap::HashMap;
|
|||
`~` */
|
||||
///an unzipping of `token_tree`s
|
||||
struct TtFrame {
|
||||
readme: ~[ast::token_tree],
|
||||
readme: @mut ~[ast::token_tree],
|
||||
idx: uint,
|
||||
dotdotdoted: bool,
|
||||
sep: Option<Token>,
|
||||
|
@ -60,7 +60,7 @@ pub fn new_tt_reader(sp_diag: span_handler,
|
|||
sp_diag: sp_diag,
|
||||
interner: itr,
|
||||
mut cur: @mut TtFrame {
|
||||
readme: src,
|
||||
readme: @mut src,
|
||||
idx: 0u,
|
||||
dotdotdoted: false,
|
||||
sep: None,
|
||||
|
@ -82,7 +82,7 @@ pub fn new_tt_reader(sp_diag: span_handler,
|
|||
|
||||
pure fn dup_tt_frame(f: @mut TtFrame) -> @mut TtFrame {
|
||||
@mut TtFrame {
|
||||
readme: f.readme,
|
||||
readme: @mut (copy *f.readme),
|
||||
idx: f.idx,
|
||||
dotdotdoted: f.dotdotdoted,
|
||||
sep: f.sep,
|
||||
|
@ -199,9 +199,9 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan {
|
|||
loop { /* because it's easiest, this handles `tt_delim` not starting
|
||||
with a `tt_tok`, even though it won't happen */
|
||||
match r.cur.readme[r.cur.idx] {
|
||||
tt_delim(copy tts) => {
|
||||
tt_delim(tts) => {
|
||||
r.cur = @mut TtFrame {
|
||||
readme: tts,
|
||||
readme: @mut copy tts,
|
||||
idx: 0u,
|
||||
dotdotdoted: false,
|
||||
sep: None,
|
||||
|
@ -242,7 +242,7 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan {
|
|||
r.repeat_len.push(len);
|
||||
r.repeat_idx.push(0u);
|
||||
r.cur = @mut TtFrame {
|
||||
readme: tts,
|
||||
readme: @mut copy tts,
|
||||
idx: 0u,
|
||||
dotdotdoted: true,
|
||||
sep: sep,
|
||||
|
|
Loading…
Reference in New Issue