Skip to content

Commit 553c27c

Browse files
committed
librustc: De-mut some of trans
1 parent cdd6f38 commit 553c27c

File tree

5 files changed

+82
-68
lines changed

5 files changed

+82
-68
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,8 @@ pub fn need_invoke(bcx: block) -> bool {
866866
// Walk the scopes to look for cleanups
867867
let mut cur = bcx;
868868
loop {
869-
match cur.kind {
870-
block_scope(ref inf) => {
869+
match *cur.kind {
870+
block_scope(ref mut inf) => {
871871
for vec::each((*inf).cleanups) |cleanup| {
872872
match *cleanup {
873873
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
@@ -898,16 +898,21 @@ pub fn have_cached_lpad(bcx: block) -> bool {
898898
return res;
899899
}
900900

901-
pub fn in_lpad_scope_cx(bcx: block, f: fn(scope_info)) {
901+
pub fn in_lpad_scope_cx(bcx: block, f: fn(&mut scope_info)) {
902902
let mut bcx = bcx;
903903
loop {
904-
match bcx.kind {
905-
block_scope(ref inf) => {
906-
if (*inf).cleanups.len() > 0u || bcx.parent.is_none() {
907-
f((*inf)); return;
904+
{
905+
// XXX: Borrow check bug workaround.
906+
let kind: &mut block_kind = &mut *bcx.kind;
907+
match *kind {
908+
block_scope(ref mut inf) => {
909+
if inf.cleanups.len() > 0u || bcx.parent.is_none() {
910+
f(inf);
911+
return;
912+
}
913+
}
914+
_ => ()
908915
}
909-
}
910-
_ => ()
911916
}
912917
bcx = block_parent(bcx);
913918
}
@@ -1198,9 +1203,9 @@ pub fn simple_block_scope() -> block_kind {
11981203
block_scope(scope_info {
11991204
loop_break: None,
12001205
loop_label: None,
1201-
mut cleanups: ~[],
1202-
mut cleanup_paths: ~[],
1203-
mut landing_pad: None
1206+
cleanups: ~[],
1207+
cleanup_paths: ~[],
1208+
landing_pad: None
12041209
})
12051210
}
12061211

@@ -1226,9 +1231,9 @@ pub fn loop_scope_block(bcx: block,
12261231
return new_block(bcx.fcx, Some(bcx), block_scope(scope_info {
12271232
loop_break: Some(loop_break),
12281233
loop_label: loop_label,
1229-
mut cleanups: ~[],
1230-
mut cleanup_paths: ~[],
1231-
mut landing_pad: None
1234+
cleanups: ~[],
1235+
cleanup_paths: ~[],
1236+
landing_pad: None
12321237
}), bcx.is_lpad, n, opt_node_info);
12331238
}
12341239

@@ -1301,23 +1306,30 @@ pub fn cleanup_and_leave(bcx: block,
13011306
@fmt!("cleanup_and_leave(%s)", cur.to_str()));
13021307
}
13031308

1304-
match cur.kind {
1305-
block_scope(ref inf) if !inf.cleanups.is_empty() => {
1306-
for vec::find((*inf).cleanup_paths,
1307-
|cp| cp.target == leave).each |cp| {
1308-
Br(bcx, cp.dest);
1309-
return;
1309+
{
1310+
// XXX: Borrow check bug workaround.
1311+
let kind: &mut block_kind = &mut *cur.kind;
1312+
match *kind {
1313+
block_scope(ref mut inf) if !inf.cleanups.is_empty() => {
1314+
for vec::find((*inf).cleanup_paths,
1315+
|cp| cp.target == leave).each |cp| {
1316+
Br(bcx, cp.dest);
1317+
return;
1318+
}
1319+
let sub_cx = sub_block(bcx, ~"cleanup");
1320+
Br(bcx, sub_cx.llbb);
1321+
inf.cleanup_paths.push(cleanup_path {
1322+
target: leave,
1323+
dest: sub_cx.llbb
1324+
});
1325+
bcx = trans_block_cleanups_(sub_cx,
1326+
block_cleanups(cur),
1327+
is_lpad);
1328+
}
1329+
_ => ()
13101330
}
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-
bcx = trans_block_cleanups_(sub_cx, block_cleanups(cur), is_lpad);
1318-
}
1319-
_ => ()
13201331
}
1332+
13211333
match upto {
13221334
Some(bb) => { if cur.llbb == bb { break; } }
13231335
_ => ()

src/librustc/middle/trans/common.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ pub struct cleanup_path {
355355
dest: BasicBlockRef
356356
}
357357
358-
pub fn scope_clean_changed(scope_info: scope_info) {
358+
pub fn scope_clean_changed(scope_info: &mut scope_info) {
359359
if scope_info.cleanup_paths.len() > 0u { scope_info.cleanup_paths = ~[]; }
360360
scope_info.landing_pad = None;
361361
}
@@ -498,9 +498,9 @@ pub fn revoke_clean(cx: block, val: ValueRef) {
498498
}
499499

500500
pub fn block_cleanups(bcx: block) -> ~[cleanup] {
501-
match bcx.kind {
501+
match *bcx.kind {
502502
block_non_scope => ~[],
503-
block_scope(ref inf) => /*bad*/copy inf.cleanups
503+
block_scope(ref mut inf) => /*bad*/copy inf.cleanups
504504
}
505505
}
506506

@@ -524,12 +524,12 @@ pub struct scope_info {
524524
// A list of functions that must be run at when leaving this
525525
// block, cleaning up any variables that were introduced in the
526526
// block.
527-
mut cleanups: ~[cleanup],
527+
cleanups: ~[cleanup],
528528
// Existing cleanup paths that may be reused, indexed by destination and
529529
// cleared when the set of cleanups changes.
530-
mut cleanup_paths: ~[cleanup_path],
530+
cleanup_paths: ~[cleanup_path],
531531
// Unwinding landing pad. Also cleared when cleanups change.
532-
mut landing_pad: Option<BasicBlockRef>,
532+
landing_pad: Option<BasicBlockRef>,
533533
}
534534

535535
pub trait get_node_info {
@@ -574,11 +574,11 @@ pub struct block_ {
574574
// instructions into that block by way of this block context.
575575
// The block pointing to this one in the function's digraph.
576576
llbb: BasicBlockRef,
577-
mut terminated: bool,
578-
mut unreachable: bool,
577+
terminated: bool,
578+
unreachable: bool,
579579
parent: Option<block>,
580580
// The 'kind' of basic block this is.
581-
kind: block_kind,
581+
kind: @mut block_kind,
582582
// Is this block part of a landing pad?
583583
is_lpad: bool,
584584
// 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,
597597
terminated: false,
598598
unreachable: false,
599599
parent: parent,
600-
kind: kind,
600+
kind: @mut kind,
601601
is_lpad: is_lpad,
602602
node_info: node_info,
603603
fcx: fcx
604604
}
605605
}
606606

607-
/* This must be enum and not type, or trans goes into an infinite loop (#2572)
608-
*/
609-
pub enum block = @block_;
607+
pub type block = @mut block_;
610608

611609
pub fn mk_block(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind,
612610
is_lpad: bool, node_info: Option<NodeInfo>, fcx: fn_ctxt)
613611
-> block {
614-
block(@block_(llbb, parent, kind, is_lpad, node_info, fcx))
612+
@mut block_(llbb, parent, kind, is_lpad, node_info, fcx)
615613
}
616614

617615
// First two args are retptr, env
@@ -660,17 +658,21 @@ pub fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef {
660658
}
661659
}
662660

663-
pub fn in_scope_cx(cx: block, f: fn(scope_info)) {
661+
pub fn in_scope_cx(cx: block, f: &fn(&mut scope_info)) {
664662
let mut cur = cx;
665663
loop {
666-
match cur.kind {
667-
block_scope(ref inf) => {
668-
debug!("in_scope_cx: selected cur=%s (cx=%s)",
669-
cur.to_str(), cx.to_str());
670-
f((*inf));
671-
return;
672-
}
673-
_ => ()
664+
{
665+
// XXX: Borrow check bug workaround.
666+
let kind: &mut block_kind = &mut *cur.kind;
667+
match *kind {
668+
block_scope(ref mut inf) => {
669+
debug!("in_scope_cx: selected cur=%s (cx=%s)",
670+
cur.to_str(), cx.to_str());
671+
f(inf);
672+
return;
673+
}
674+
_ => ()
675+
}
674676
}
675677
cur = block_parent(cur);
676678
}

src/librustc/middle/trans/controlflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn trans_break_cont(bcx: block,
237237
let mut unwind = bcx;
238238
let mut target;
239239
loop {
240-
match unwind.kind {
240+
match *unwind.kind {
241241
block_scope(scope_info {
242242
loop_break: Some(brk),
243243
loop_label: l,

src/libsyntax/ext/base.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
196196
struct CtxtRepr {
197197
parse_sess: @mut parse::ParseSess,
198198
cfg: ast::crate_cfg,
199-
backtrace: Option<@ExpnInfo>,
199+
backtrace: @mut Option<@ExpnInfo>,
200200
mod_path: ~[ast::ident],
201201
trace_mac: bool
202202
}
@@ -205,33 +205,33 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
205205
fn parse_sess(@mut self) -> @mut parse::ParseSess { self.parse_sess }
206206
fn cfg(@mut self) -> ast::crate_cfg { self.cfg }
207207
fn call_site(@mut self) -> span {
208-
match self.backtrace {
208+
match *self.backtrace {
209209
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
210210
None => self.bug(~"missing top span")
211211
}
212212
}
213213
fn print_backtrace(@mut self) { }
214-
fn backtrace(@mut self) -> Option<@ExpnInfo> { self.backtrace }
214+
fn backtrace(@mut self) -> Option<@ExpnInfo> { *self.backtrace }
215215
fn mod_push(@mut self, i: ast::ident) { self.mod_path.push(i); }
216216
fn mod_pop(@mut self) { self.mod_path.pop(); }
217217
fn mod_path(@mut self) -> ~[ast::ident] { return self.mod_path; }
218218
fn bt_push(@mut self, ei: codemap::ExpnInfo) {
219219
match ei {
220220
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
221-
self.backtrace =
221+
*self.backtrace =
222222
Some(@ExpandedFrom(CallInfo {
223223
call_site: span {lo: cs.lo, hi: cs.hi,
224-
expn_info: self.backtrace},
224+
expn_info: *self.backtrace},
225225
callee: (*callee)}));
226226
}
227227
}
228228
}
229229
fn bt_pop(@mut self) {
230-
match self.backtrace {
230+
match *self.backtrace {
231231
Some(@ExpandedFrom(CallInfo {
232232
call_site: span {expn_info: prev, _}, _
233233
})) => {
234-
self.backtrace = prev
234+
*self.backtrace = prev
235235
}
236236
_ => self.bug(~"tried to pop without a push")
237237
}
@@ -280,7 +280,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
280280
let imp: @mut CtxtRepr = @mut CtxtRepr {
281281
parse_sess: parse_sess,
282282
cfg: cfg,
283-
backtrace: None,
283+
backtrace: @mut None,
284284
mod_path: ~[],
285285
trace_mac: false
286286
};

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::oldmap::HashMap;
2828
`~` */
2929
///an unzipping of `token_tree`s
3030
struct TtFrame {
31-
readme: ~[ast::token_tree],
31+
readme: @mut ~[ast::token_tree],
3232
idx: uint,
3333
dotdotdoted: bool,
3434
sep: Option<Token>,
@@ -60,7 +60,7 @@ pub fn new_tt_reader(sp_diag: span_handler,
6060
sp_diag: sp_diag,
6161
interner: itr,
6262
mut cur: @mut TtFrame {
63-
readme: src,
63+
readme: @mut src,
6464
idx: 0u,
6565
dotdotdoted: false,
6666
sep: None,
@@ -82,7 +82,7 @@ pub fn new_tt_reader(sp_diag: span_handler,
8282

8383
pure fn dup_tt_frame(f: @mut TtFrame) -> @mut TtFrame {
8484
@mut TtFrame {
85-
readme: f.readme,
85+
readme: @mut (copy *f.readme),
8686
idx: f.idx,
8787
dotdotdoted: f.dotdotdoted,
8888
sep: f.sep,
@@ -199,9 +199,9 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan {
199199
loop { /* because it's easiest, this handles `tt_delim` not starting
200200
with a `tt_tok`, even though it won't happen */
201201
match r.cur.readme[r.cur.idx] {
202-
tt_delim(copy tts) => {
202+
tt_delim(tts) => {
203203
r.cur = @mut TtFrame {
204-
readme: tts,
204+
readme: @mut copy tts,
205205
idx: 0u,
206206
dotdotdoted: false,
207207
sep: None,
@@ -242,7 +242,7 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan {
242242
r.repeat_len.push(len);
243243
r.repeat_idx.push(0u);
244244
r.cur = @mut TtFrame {
245-
readme: tts,
245+
readme: @mut copy tts,
246246
idx: 0u,
247247
dotdotdoted: true,
248248
sep: sep,

0 commit comments

Comments
 (0)