Skip to content

Commit 81af21f

Browse files
committed
Revert "Change trans::common::block to be a class"
This reverts commit 7236097.
1 parent ab9c900 commit 81af21f

File tree

3 files changed

+60
-69
lines changed

3 files changed

+60
-69
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import type_of::type_of; // Issue #1873
5050
import syntax::ast_map::{path, path_mod, path_name};
5151

5252
import std::smallintmap;
53-
import option::is_none;
5453

5554
// Destinations
5655

@@ -1212,8 +1211,7 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint,
12121211
}
12131212
}
12141213

1215-
// See [Note-arg-mode]
1216-
fn call_tydesc_glue_full(++cx: block, v: ValueRef, tydesc: ValueRef,
1214+
fn call_tydesc_glue_full(cx: block, v: ValueRef, tydesc: ValueRef,
12171215
field: uint, static_ti: option<@tydesc_info>) {
12181216
let _icx = cx.insn_ctxt("call_tydesc_glue_full");
12191217
lazily_emit_tydesc_glue(cx.ccx(), field, static_ti);
@@ -1251,9 +1249,8 @@ fn call_tydesc_glue_full(++cx: block, v: ValueRef, tydesc: ValueRef,
12511249
C_null(T_ptr(T_ptr(cx.ccx().tydesc_type))), llrawptr]);
12521250
}
12531251

1254-
// See [Note-arg-mode]
1255-
fn call_tydesc_glue(++cx: block, v: ValueRef, t: ty::t, field: uint)
1256-
-> block {
1252+
fn call_tydesc_glue(cx: block, v: ValueRef, t: ty::t, field: uint) ->
1253+
block {
12571254
let _icx = cx.insn_ctxt("call_tydesc_glue");
12581255
let mut ti = none;
12591256
let td = get_tydesc(cx.ccx(), t, ti);
@@ -3127,9 +3124,8 @@ fn body_contains_ret(body: ast::blk) -> bool {
31273124
cx.found
31283125
}
31293126

3130-
// See [Note-arg-mode]
31313127
fn trans_call_inner(
3132-
++in_cx: block,
3128+
in_cx: block,
31333129
call_info: option<node_info>,
31343130
fn_expr_ty: ty::t,
31353131
ret_ty: ty::t,
@@ -3257,8 +3253,8 @@ fn need_invoke(bcx: block) -> bool {
32573253
_ { }
32583254
}
32593255
cur = alt cur.parent {
3260-
some(next) { next }
3261-
none { ret false; }
3256+
parent_some(next) { next }
3257+
parent_none { ret false; }
32623258
}
32633259
}
32643260
}
@@ -3279,7 +3275,7 @@ fn in_lpad_scope_cx(bcx: block, f: fn(scope_info)) {
32793275
loop {
32803276
alt bcx.kind {
32813277
block_scope(inf) {
3282-
if inf.cleanups.len() > 0u || is_none(bcx.parent) {
3278+
if inf.cleanups.len() > 0u || bcx.parent == parent_none {
32833279
f(inf); ret;
32843280
}
32853281
}
@@ -3488,11 +3484,11 @@ fn add_root_cleanup(bcx: block, scope_id: ast::node_id,
34883484
some({id, _}) if id == scope_id { ret bcx_sid; }
34893485
_ {
34903486
alt bcx_sid.parent {
3491-
none {
3487+
parent_none {
34923488
bcx.tcx().sess.bug(
34933489
#fmt["no enclosing scope with id %d", scope_id]);
34943490
}
3495-
some(bcx_par) { bcx_par }
3491+
parent_some(bcx_par) { bcx_par }
34963492
}
34973493
}
34983494
}
@@ -3802,10 +3798,7 @@ fn do_spill(bcx: block, v: ValueRef, t: ty::t) -> ValueRef {
38023798

38033799
// Since this function does *not* root, it is the caller's responsibility to
38043800
// ensure that the referent is pointed to by a root.
3805-
// [Note-arg-mode]
3806-
// ++ mode is temporary, due to how borrowck treats enums. With hope,
3807-
// will go away anyway when we get rid of modes.
3808-
fn do_spill_noroot(++cx: block, v: ValueRef) -> ValueRef {
3801+
fn do_spill_noroot(cx: block, v: ValueRef) -> ValueRef {
38093802
let llptr = alloca(cx, val_ty(v));
38103803
Store(cx, v, llptr);
38113804
ret llptr;
@@ -3987,9 +3980,9 @@ fn trans_break_cont(bcx: block, to_end: bool)
39873980
_ {}
39883981
}
39893982
unwind = alt unwind.parent {
3990-
some(cx) { cx }
3983+
parent_some(cx) { cx }
39913984
// This is a return from a loop body block
3992-
none {
3985+
parent_none {
39933986
Store(bcx, C_bool(!to_end), bcx.fcx.llretptr);
39943987
cleanup_and_leave(bcx, none, some(bcx.fcx.llreturn));
39953988
Unreachable(bcx);
@@ -4107,7 +4100,7 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block {
41074100

41084101
// You probably don't want to use this one. See the
41094102
// next three functions instead.
4110-
fn new_block(cx: fn_ctxt, parent: option<block>, +kind: block_kind,
4103+
fn new_block(cx: fn_ctxt, parent: block_parent, +kind: block_kind,
41114104
name: str, opt_node_info: option<node_info>) -> block {
41124105

41134106
let s = if cx.ccx.sess.opts.save_temps || cx.ccx.sess.opts.debuginfo {
@@ -4116,10 +4109,19 @@ fn new_block(cx: fn_ctxt, parent: option<block>, +kind: block_kind,
41164109
let llbb: BasicBlockRef = str::as_c_str(s, {|buf|
41174110
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
41184111
});
4119-
let bcx = mk_block(llbb, parent, kind, opt_node_info, cx);
4120-
option::iter(parent) {|cx|
4112+
let bcx = @{llbb: llbb,
4113+
mut terminated: false,
4114+
mut unreachable: false,
4115+
parent: parent,
4116+
kind: kind,
4117+
node_info: opt_node_info,
4118+
fcx: cx};
4119+
alt parent {
4120+
parent_some(cx) {
41214121
if cx.unreachable { Unreachable(bcx); }
4122-
};
4122+
}
4123+
_ {}
4124+
}
41234125
ret bcx;
41244126
}
41254127

@@ -4130,20 +4132,20 @@ fn simple_block_scope() -> block_kind {
41304132

41314133
// Use this when you're at the top block of a function or the like.
41324134
fn top_scope_block(fcx: fn_ctxt, opt_node_info: option<node_info>) -> block {
4133-
ret new_block(fcx, none, simple_block_scope(),
4135+
ret new_block(fcx, parent_none, simple_block_scope(),
41344136
"function top level", opt_node_info);
41354137
}
41364138

41374139
fn scope_block(bcx: block,
41384140
opt_node_info: option<node_info>,
41394141
n: str) -> block {
4140-
ret new_block(bcx.fcx, some(bcx), simple_block_scope(),
4142+
ret new_block(bcx.fcx, parent_some(bcx), simple_block_scope(),
41414143
n, opt_node_info);
41424144
}
41434145

41444146
fn loop_scope_block(bcx: block, loop_break: block, n: str,
41454147
opt_node_info: option<node_info>) -> block {
4146-
ret new_block(bcx.fcx, some(bcx), block_scope({
4148+
ret new_block(bcx.fcx, parent_some(bcx), block_scope({
41474149
loop_break: some(loop_break),
41484150
mut cleanups: [],
41494151
mut cleanup_paths: [],
@@ -4154,11 +4156,17 @@ fn loop_scope_block(bcx: block, loop_break: block, n: str,
41544156

41554157
// Use this when you're making a general CFG BB within a scope.
41564158
fn sub_block(bcx: block, n: str) -> block {
4157-
new_block(bcx.fcx, some(bcx), block_non_scope, n, none)
4159+
ret new_block(bcx.fcx, parent_some(bcx), block_non_scope, n, none);
41584160
}
41594161

41604162
fn raw_block(fcx: fn_ctxt, llbb: BasicBlockRef) -> block {
4161-
mk_block(llbb, none, block_non_scope, none, fcx)
4163+
ret @{llbb: llbb,
4164+
mut terminated: false,
4165+
mut unreachable: false,
4166+
parent: parent_none,
4167+
kind: block_non_scope,
4168+
node_info: none,
4169+
fcx: fcx};
41624170
}
41634171

41644172

@@ -4233,8 +4241,8 @@ fn cleanup_and_leave(bcx: block, upto: option<BasicBlockRef>,
42334241
_ {}
42344242
}
42354243
cur = alt cur.parent {
4236-
some(next) { next }
4237-
none { assert is_none(upto); break; }
4244+
parent_some(next) { next }
4245+
parent_none { assert option::is_none(upto); break; }
42384246
};
42394247
}
42404248
alt leave {

src/rustc/middle/trans/common.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -350,44 +350,32 @@ type node_info = {
350350
// code. Each basic block we generate is attached to a function, typically
351351
// with many basic blocks per function. All the basic blocks attached to a
352352
// function are organized as a directed graph.
353-
class block_ {
353+
type block = @{
354354
// The BasicBlockRef returned from a call to
355355
// llvm::LLVMAppendBasicBlock(llfn, name), which adds a basic
356356
// block to the function pointed to by llfn. We insert
357357
// instructions into that block by way of this block context.
358358
// The block pointing to this one in the function's digraph.
359-
let llbb: BasicBlockRef;
360-
let mut terminated: bool;
361-
let mut unreachable: bool;
362-
let parent: option<block>;
359+
llbb: BasicBlockRef,
360+
mut terminated: bool,
361+
mut unreachable: bool,
362+
parent: block_parent,
363363
// The 'kind' of basic block this is.
364-
let kind: block_kind;
364+
kind: block_kind,
365365
// info about the AST node this block originated from, if any
366-
let node_info: option<node_info>;
366+
node_info: option<node_info>,
367367
// The function context for the function to which this block is
368368
// attached.
369-
let fcx: fn_ctxt;
370-
new(llbb: BasicBlockRef, parent: option<block>, -kind: block_kind,
371-
node_info: option<node_info>, fcx: fn_ctxt) {
372-
// sigh
373-
self.llbb = llbb; self.terminated = false; self.unreachable = false;
374-
self.parent = parent; self.kind = kind; self.node_info = node_info;
375-
self.fcx = fcx;
376-
}
377-
}
378-
379-
/* This must be enum and not type, or trans goes into an infinite loop (#2572)
380-
*/
381-
enum block = @block_;
382-
383-
fn mk_block(llbb: BasicBlockRef, parent: option<block>, -kind: block_kind,
384-
node_info: option<node_info>, fcx: fn_ctxt) -> block {
385-
block(@block_(llbb, parent, kind, node_info, fcx))
386-
}
369+
fcx: fn_ctxt
370+
};
387371

388372
// First two args are retptr, env
389373
const first_real_arg: uint = 2u;
390374

375+
// FIXME move blocks to a class once those are finished, and simply use
376+
// option<block> for this. (#2532)
377+
enum block_parent { parent_none, parent_some(block), }
378+
391379
type result = {bcx: block, val: ValueRef};
392380
type result_t = {bcx: block, val: ValueRef, ty: ty::t};
393381

@@ -424,11 +412,7 @@ fn in_scope_cx(cx: block, f: fn(scope_info)) {
424412
}
425413

426414
fn block_parent(cx: block) -> block {
427-
alt cx.parent {
428-
some(b) { b }
429-
none { cx.sess().bug(#fmt("block_parent called on root block %?",
430-
cx)); }
431-
}
415+
alt check cx.parent { parent_some(b) { b } }
432416
}
433417

434418
// Accessors

src/rustc/middle/trans/debuginfo.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ fn create_block(cx: block) -> @metadata<block_md> {
236236
let mut cx = cx;
237237
while option::is_none(cx.node_info) {
238238
alt cx.parent {
239-
some(b) { cx = b; }
240-
none { fail; }
239+
parent_some(b) { cx = b; }
240+
parent_none { fail; }
241241
}
242242
}
243243
let sp = option::get(cx.node_info).span;
@@ -254,8 +254,8 @@ fn create_block(cx: block) -> @metadata<block_md> {
254254
}*/
255255

256256
let parent = alt cx.parent {
257-
none { create_function(cx.fcx).node }
258-
some(bcx) { create_block(bcx).node }
257+
parent_none { create_function(cx.fcx).node }
258+
parent_some(bcx) { create_block(bcx).node }
259259
};
260260
let file_node = create_file(cx.ccx(), fname);
261261
let unique_id = alt cache.find(LexicalBlockTag) {
@@ -658,8 +658,8 @@ fn create_local_var(bcx: block, local: @ast::local)
658658
let tymd = create_ty(cx, ty, local.node.ty);
659659
let filemd = create_file(cx, loc.file.name);
660660
let context = alt bcx.parent {
661-
none { create_function(bcx.fcx).node }
662-
some(_) { create_block(bcx).node }
661+
parent_none { create_function(bcx.fcx).node }
662+
parent_some(_) { create_block(bcx).node }
663663
};
664664
let mdnode = create_var(tg, context, name, filemd.node,
665665
loc.line as int, tymd.node);
@@ -761,10 +761,9 @@ fn create_function(fcx: fn_ctxt) -> @metadata<subprogram_md> {
761761
(nm, decl.output, ctor_id)
762762
}
763763
ast_map::class_ctor(ctor,_) {
764-
// FIXME: output type may be wrong (#2194)
765-
(nm, ctor.node.dec.output, ctor.node.id)
764+
fcx.ccx.sess.span_bug(ctor.span, "create_function: \
765+
expected a resource ctor here"); }
766766
}
767-
}
768767
}
769768
ast_map::node_expr(expr) {
770769
alt expr.node {

0 commit comments

Comments
 (0)