Skip to content

Commit ffc6a00

Browse files
committed
---
yaml --- r: 7981 b: refs/heads/snap-stage3 c: 3116643 h: refs/heads/master i: 7979: 9aac43c v: v3
1 parent b8d52ff commit ffc6a00

27 files changed

+599
-585
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c36207bfb82f794f17fc5854d4ae50284eddf329
4+
refs/heads/snap-stage3: 31166438063236e6d2ad021cf2169fce2b3839b4
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/mk/rt.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ RUNTIME_CS_$(1) := \
6161
rt/rust_cc.cpp \
6262
rt/rust_debug.cpp \
6363
rt/memory_region.cpp \
64-
rt/boxed_region.cpp \
6564
rt/test/rust_test_harness.cpp \
6665
rt/test/rust_test_runtime.cpp \
6766
rt/test/rust_test_util.cpp \

branches/snap-stage3/mk/target.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# If you are making non-backwards compatible changes to the runtime,
88
# set this flag to 1. It will cause stage1 to use the snapshot
99
# runtime rather than the runtime from the working directory.
10-
USE_SNAPSHOT_RUNTIME=1
10+
USE_SNAPSHOT_RUNTIME=0
1111

1212
define TARGET_STAGE_N
1313

branches/snap-stage3/src/comp/back/abi.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ const frame_glue_fns_field_drop: int = 1;
2626

2727
const frame_glue_fns_field_reloc: int = 2;
2828

29-
const box_field_refcnt: int = 0;
30-
const box_field_tydesc: int = 1;
31-
const box_field_prev: int = 2;
32-
const box_field_next: int = 3;
33-
const box_field_body: int = 4;
29+
// n.b. must be same as cbox_elt_refcnt
30+
const box_rc_field_refcnt: int = 0;
31+
const box_rc_field_body: int = 1;
3432

3533
const general_code_alignment: int = 16;
3634

@@ -61,9 +59,13 @@ const cmp_glue_op_le: uint = 2u;
6159
const fn_field_code: int = 0;
6260
const fn_field_box: int = 1;
6361

64-
// closures, see trans_closure.rs
65-
const closure_body_ty_params: int = 0;
66-
const closure_body_bindings: int = 1;
62+
// closure_box, see trans_closure.rs
63+
//
64+
// n.b. the refcnt must be compatible with a normal box
65+
const cbox_elt_refcnt: int = 0;
66+
const cbox_elt_tydesc: int = 1;
67+
const cbox_elt_ty_params: int = 2;
68+
const cbox_elt_bindings: int = 3;
6769

6870
const vec_elt_fill: int = 0;
6971

branches/snap-stage3/src/comp/back/upcall.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type upcalls =
1111
{_fail: ValueRef,
1212
malloc: ValueRef,
1313
free: ValueRef,
14-
validate_box: ValueRef,
1514
shared_malloc: ValueRef,
1615
shared_free: ValueRef,
1716
mark: ValueRef,
@@ -53,12 +52,10 @@ fn declare_upcalls(targ_cfg: @session::config,
5352
T_ptr(T_i8()),
5453
size_t]),
5554
malloc:
56-
d("malloc", [T_ptr(tydesc_type)],
55+
d("malloc", [size_t, T_ptr(tydesc_type)],
5756
T_ptr(T_i8())),
5857
free:
5958
dv("free", [T_ptr(T_i8()), int_t]),
60-
validate_box:
61-
dv("validate_box", [T_ptr(T_i8())]),
6259
shared_malloc:
6360
d("shared_malloc", [size_t, T_ptr(tydesc_type)],
6461
T_ptr(T_i8())),

branches/snap-stage3/src/comp/middle/trans/alt.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import syntax::ast_util::{dummy_sp};
1414
import syntax::ast::def_id;
1515
import syntax::codemap::span;
1616
import syntax::print::pprust::pat_to_str;
17-
import back::abi;
1817

1918
import common::*;
2019

@@ -466,7 +465,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
466465
// Unbox in case of a box field
467466
if any_box_pat(m, col) {
468467
let box = Load(bcx, val);
469-
let unboxed = GEPi(bcx, box, [0, abi::box_field_body]);
468+
let unboxed = GEPi(bcx, box, [0, back::abi::box_rc_field_body]);
470469
compile_submatch(bcx, enter_box(m, col, val), [unboxed] + vals_left,
471470
f, exits);
472471
ret;
@@ -777,7 +776,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
777776
ast::pat_box(inner) {
778777
let box = Load(bcx, val);
779778
let unboxed =
780-
GEPi(bcx, box, [0, abi::box_field_body]);
779+
GEPi(bcx, box, [0, back::abi::box_rc_field_body]);
781780
bcx = bind_irrefutable_pat(bcx, inner, unboxed, true);
782781
}
783782
ast::pat_uniq(inner) {

branches/snap-stage3/src/comp/middle/trans/base.rs

Lines changed: 51 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn type_of_fn(cx: @crate_ctxt, inputs: [ty::arg],
9191
atys += [out_ty];
9292

9393
// Arg 1: Environment
94-
atys += [T_opaque_box_ptr(cx)];
94+
atys += [T_opaque_cbox_ptr(cx)];
9595

9696
// Args >2: ty params, if not acquired via capture...
9797
for bounds in params {
@@ -193,7 +193,7 @@ fn type_of_inner(cx: @crate_ctxt, t: ty::t)
193193
T_struct(tys)
194194
}
195195
ty::ty_opaque_closure_ptr(_) {
196-
T_opaque_box_ptr(cx)
196+
T_opaque_cbox_ptr(cx)
197197
}
198198
ty::ty_constr(subt,_) {
199199
// FIXME: could be a constraint on ty_fn
@@ -764,54 +764,54 @@ fn trans_shared_malloc(cx: @block_ctxt, llptr_ty: TypeRef, llsize: ValueRef)
764764
ret rslt(cx, PointerCast(cx, rval, llptr_ty));
765765
}
766766

767-
// Returns a pointer to the body for the box. The box may be an opaque
768-
// box. The result will be casted to the type of body_t, if it is statically
769-
// known.
770-
//
771-
// The runtime equivalent is box_body() in "rust_internal.h".
772-
fn opaque_box_body(bcx: @block_ctxt,
773-
body_t: ty::t,
774-
boxptr: ValueRef) -> ValueRef {
775-
let ccx = bcx_ccx(bcx);
776-
let boxptr = PointerCast(bcx, boxptr, T_ptr(T_box_header(ccx)));
777-
let bodyptr = GEPi(bcx, boxptr, [1]);
778-
if check type_has_static_size(ccx, body_t) {
779-
PointerCast(bcx, bodyptr, T_ptr(type_of(ccx, body_t)))
780-
} else {
781-
PointerCast(bcx, bodyptr, T_ptr(T_i8()))
782-
}
783-
}
784-
785767
// trans_malloc_boxed_raw: expects an unboxed type and returns a pointer to
786-
// enough space for a box of that type. This includes a rust_opaque_box
787-
// header.
788-
fn trans_malloc_boxed_raw(bcx: @block_ctxt, t: ty::t,
789-
&static_ti: option<@tydesc_info>) -> result {
790-
let bcx = bcx;
791-
let ccx = bcx_ccx(bcx);
768+
// enough space for something of that type, along with space for a reference
769+
// count; in other words, it allocates a box for something of that type.
770+
fn trans_malloc_boxed_raw(cx: @block_ctxt, t: ty::t) -> result {
771+
let bcx = cx;
772+
773+
// Synthesize a fake box type structurally so we have something
774+
// to measure the size of.
775+
776+
// We synthesize two types here because we want both the type of the
777+
// pointer and the pointee. boxed_body is the type that we measure the
778+
// size of; box_ptr is the type that's converted to a TypeRef and used as
779+
// the pointer cast target in trans_raw_malloc.
780+
781+
// The mk_int here is the space being
782+
// reserved for the refcount.
783+
let boxed_body = ty::mk_tup(bcx_tcx(bcx), [ty::mk_int(bcx_tcx(cx)), t]);
784+
let box_ptr = ty::mk_imm_box(bcx_tcx(bcx), t);
785+
let r = size_of(cx, boxed_body);
786+
let llsz = r.val; bcx = r.bcx;
792787

793788
// Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
794789
// wants.
795-
let box_ptr = ty::mk_imm_box(bcx_tcx(bcx), t);
790+
// FIXME: Could avoid this check with a postcondition on mk_imm_box?
791+
// (requires Issue #586)
792+
let ccx = bcx_ccx(bcx);
796793
check (type_has_static_size(ccx, box_ptr));
797794
let llty = type_of(ccx, box_ptr);
798795

799-
// Get the tydesc for the body:
800-
let {bcx, val: lltydesc} = get_tydesc(bcx, t, true, static_ti).result;
796+
let ti = none;
797+
let tydesc_result = get_tydesc(bcx, t, true, ti);
798+
let lltydesc = tydesc_result.result.val; bcx = tydesc_result.result.bcx;
801799

802-
// Allocate space:
803-
let rval = Call(bcx, ccx.upcalls.malloc, [lltydesc]);
804-
ret rslt(bcx, PointerCast(bcx, rval, llty));
800+
let rval = Call(cx, ccx.upcalls.malloc,
801+
[llsz, lltydesc]);
802+
ret rslt(cx, PointerCast(cx, rval, llty));
805803
}
806804

807805
// trans_malloc_boxed: usefully wraps trans_malloc_box_raw; allocates a box,
808806
// initializes the reference count to 1, and pulls out the body and rc
809-
fn trans_malloc_boxed(bcx: @block_ctxt, t: ty::t) ->
807+
fn trans_malloc_boxed(cx: @block_ctxt, t: ty::t) ->
810808
{bcx: @block_ctxt, box: ValueRef, body: ValueRef} {
811-
let ti = none;
812-
let {bcx, val:box} = trans_malloc_boxed_raw(bcx, t, ti);
813-
let body = GEPi(bcx, box, [0, abi::box_field_body]);
814-
ret {bcx: bcx, box: box, body: body};
809+
let res = trans_malloc_boxed_raw(cx, t);
810+
let box = res.val;
811+
let rc = GEPi(res.bcx, box, [0, abi::box_rc_field_refcnt]);
812+
Store(res.bcx, C_int(bcx_ccx(cx), 1), rc);
813+
let body = GEPi(res.bcx, box, [0, abi::box_rc_field_body]);
814+
ret {bcx: res.bcx, box: res.val, body: body};
815815
}
816816

817817
// Type descriptor and type glue stuff
@@ -1231,8 +1231,8 @@ fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) {
12311231

12321232
fn incr_refcnt_of_boxed(cx: @block_ctxt, box_ptr: ValueRef) -> @block_ctxt {
12331233
let ccx = bcx_ccx(cx);
1234-
maybe_validate_box(cx, box_ptr);
1235-
let rc_ptr = GEPi(cx, box_ptr, [0, abi::box_field_refcnt]);
1234+
let rc_ptr =
1235+
GEPi(cx, box_ptr, [0, abi::box_rc_field_refcnt]);
12361236
let rc = Load(cx, rc_ptr);
12371237
rc = Add(cx, rc, C_int(ccx, 1));
12381238
Store(cx, rc, rc_ptr);
@@ -1243,7 +1243,7 @@ fn free_box(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt {
12431243
ret alt ty::struct(bcx_tcx(bcx), t) {
12441244
ty::ty_box(body_mt) {
12451245
let v = PointerCast(bcx, v, type_of_1(bcx, t));
1246-
let body = GEPi(bcx, v, [0, abi::box_field_body]);
1246+
let body = GEPi(bcx, v, [0, abi::box_rc_field_body]);
12471247
let bcx = drop_ty(bcx, body, body_mt.ty);
12481248
trans_free_if_not_gc(bcx, v)
12491249
}
@@ -1274,7 +1274,7 @@ fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) {
12741274
let ccx = bcx_ccx(bcx);
12751275
let llbox_ty = T_opaque_iface_ptr(ccx);
12761276
let b = PointerCast(bcx, v, llbox_ty);
1277-
let body = GEPi(bcx, b, [0, abi::box_field_body]);
1277+
let body = GEPi(bcx, b, [0, abi::box_rc_field_body]);
12781278
let tydescptr = GEPi(bcx, body, [0, 0]);
12791279
let tydesc = Load(bcx, tydescptr);
12801280
let ti = none;
@@ -1375,31 +1375,18 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: ast::def_id,
13751375
ret next_cx;
13761376
}
13771377

1378-
fn maybe_validate_box(_cx: @block_ctxt, _box_ptr: ValueRef) {
1379-
// Uncomment this when debugging annoying use-after-free
1380-
// bugs. But do not commit with this uncommented! Big performance hit.
1381-
1382-
// let cx = _cx, box_ptr = _box_ptr;
1383-
// let ccx = bcx_ccx(cx);
1384-
// warn_not_to_commit(ccx, "validate_box() is uncommented");
1385-
// let raw_box_ptr = PointerCast(cx, box_ptr, T_ptr(T_i8()));
1386-
// Call(cx, ccx.upcalls.validate_box, [raw_box_ptr]);
1387-
}
1388-
13891378
fn decr_refcnt_maybe_free(cx: @block_ctxt, box_ptr: ValueRef, t: ty::t)
13901379
-> @block_ctxt {
13911380
let ccx = bcx_ccx(cx);
1392-
1393-
maybe_validate_box(cx, box_ptr);
1394-
13951381
let rc_adj_cx = new_sub_block_ctxt(cx, "rc--");
13961382
let free_cx = new_sub_block_ctxt(cx, "free");
13971383
let next_cx = new_sub_block_ctxt(cx, "next");
13981384
let llbox_ty = T_opaque_iface_ptr(ccx);
13991385
let box_ptr = PointerCast(cx, box_ptr, llbox_ty);
14001386
let null_test = IsNull(cx, box_ptr);
14011387
CondBr(cx, null_test, next_cx.llbb, rc_adj_cx.llbb);
1402-
let rc_ptr = GEPi(rc_adj_cx, box_ptr, [0, abi::box_field_refcnt]);
1388+
let rc_ptr =
1389+
GEPi(rc_adj_cx, box_ptr, [0, abi::box_rc_field_refcnt]);
14031390
let rc = Load(rc_adj_cx, rc_ptr);
14041391
rc = Sub(rc_adj_cx, rc, C_int(ccx, 1));
14051392
Store(rc_adj_cx, rc, rc_ptr);
@@ -1410,6 +1397,7 @@ fn decr_refcnt_maybe_free(cx: @block_ctxt, box_ptr: ValueRef, t: ty::t)
14101397
ret next_cx;
14111398
}
14121399

1400+
14131401
// Structural comparison: a rather involved form of glue.
14141402
fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: str) {
14151403
if cx.sess.opts.save_temps {
@@ -2220,7 +2208,7 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
22202208
while true {
22212209
alt ty::struct(ccx.tcx, t1) {
22222210
ty::ty_box(mt) {
2223-
let body = GEPi(cx, v1, [0, abi::box_field_body]);
2211+
let body = GEPi(cx, v1, [0, abi::box_rc_field_body]);
22242212
t1 = mt.ty;
22252213

22262214
// Since we're changing levels of box indirection, we may have
@@ -2526,7 +2514,7 @@ type lval_maybe_callee = {bcx: @block_ctxt,
25262514
generic: option<generic_info>};
25272515

25282516
fn null_env_ptr(bcx: @block_ctxt) -> ValueRef {
2529-
C_null(T_opaque_box_ptr(bcx_ccx(bcx)))
2517+
C_null(T_opaque_cbox_ptr(bcx_ccx(bcx)))
25302518
}
25312519

25322520
fn lval_from_local_var(bcx: @block_ctxt, r: local_var_result) -> lval_result {
@@ -2802,7 +2790,7 @@ fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
28022790
let val =
28032791
alt ty::struct(ccx.tcx, t) {
28042792
ty::ty_box(_) {
2805-
GEPi(sub.bcx, sub.val, [0, abi::box_field_body])
2793+
GEPi(sub.bcx, sub.val, [0, abi::box_rc_field_body])
28062794
}
28072795
ty::ty_res(_, _, _) {
28082796
GEPi(sub.bcx, sub.val, [0, 1])
@@ -3172,7 +3160,7 @@ fn trans_call_inner(in_cx: @block_ctxt, fn_expr_ty: ty::t,
31723160
let llenv, dict_param = none;
31733161
alt f_res.env {
31743162
null_env {
3175-
llenv = llvm::LLVMGetUndef(T_opaque_box_ptr(bcx_ccx(cx)));
3163+
llenv = llvm::LLVMGetUndef(T_opaque_cbox_ptr(bcx_ccx(cx)));
31763164
}
31773165
self_env(e) { llenv = e; }
31783166
dict_env(dict, e) { llenv = e; dict_param = some(dict); }
@@ -3477,8 +3465,6 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
34773465
let tcx = bcx_tcx(bcx);
34783466
debuginfo::update_source_pos(bcx, e.span);
34793467

3480-
#debug["trans_expr(%s,%?)", expr_to_str(e), dest];
3481-
34823468
if expr_is_lval(bcx, e) {
34833469
ret lval_to_dps(bcx, e, dest);
34843470
}
@@ -4012,8 +3998,6 @@ fn zero_alloca(cx: @block_ctxt, llptr: ValueRef, t: ty::t)
40123998
}
40133999

40144000
fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
4015-
#debug["trans_expr(%s)", stmt_to_str(s)];
4016-
40174001
if (!bcx_ccx(cx).sess.opts.no_asm_comments) {
40184002
add_span_comment(cx, s.span, stmt_to_str(s));
40194003
}
@@ -5138,7 +5122,8 @@ fn fill_fn_pair(bcx: @block_ctxt, pair: ValueRef, llfn: ValueRef,
51385122
let code_cell = GEPi(bcx, pair, [0, abi::fn_field_code]);
51395123
Store(bcx, llfn, code_cell);
51405124
let env_cell = GEPi(bcx, pair, [0, abi::fn_field_box]);
5141-
let llenvblobptr = PointerCast(bcx, llenvptr, T_opaque_box_ptr(ccx));
5125+
let llenvblobptr =
5126+
PointerCast(bcx, llenvptr, T_opaque_cbox_ptr(ccx));
51425127
Store(bcx, llenvblobptr, env_cell);
51435128
}
51445129

@@ -5606,8 +5591,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
56065591
shape_cx: shape::mk_ctxt(llmod),
56075592
gc_cx: gc::mk_ctxt(),
56085593
crate_map: crate_map,
5609-
dbg_cx: dbg_cx,
5610-
mutable do_not_commit_warning_issued: false};
5594+
dbg_cx: dbg_cx};
56115595
let cx = new_local_ctxt(ccx);
56125596
collect_items(ccx, crate);
56135597
trans_constants(ccx, crate);

branches/snap-stage3/src/comp/middle/trans/build.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, ModuleRef};
88
import lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False,
99
CallConv};
1010
import common::{block_ctxt, T_ptr, T_nil, T_i8, T_i1, T_void,
11-
T_fn, val_ty, bcx_ccx, C_i32, val_str};
11+
T_fn, val_ty, bcx_ccx, C_i32};
1212

1313
fn B(cx: @block_ctxt) -> BuilderRef {
1414
let b = *cx.fcx.lcx.ccx.builder;
@@ -95,10 +95,6 @@ fn Invoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
9595
if cx.unreachable { ret; }
9696
assert (!cx.terminated);
9797
cx.terminated = true;
98-
#debug["Invoke(%s with arguments (%s))",
99-
val_str(bcx_ccx(cx).tn, Fn),
100-
str::connect(vec::map(Args, {|a|val_str(bcx_ccx(cx).tn, a)}),
101-
", ")];
10298
unsafe {
10399
llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
104100
vec::len(Args) as c_uint, Then, Catch,

0 commit comments

Comments
 (0)