Skip to content

Commit 2c76491

Browse files
committed
---
yaml --- r: 5569 b: refs/heads/master c: 94db38a h: refs/heads/master i: 5567: 5030aad v: v3
1 parent ed553d4 commit 2c76491

File tree

5 files changed

+91
-97
lines changed

5 files changed

+91
-97
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 92d63ffa65b801e43b91927f8b23f0767bc42cd2
2+
refs/heads/master: 94db38a530c820005443fdac890f6d862f63e9d9

trunk/src/comp/middle/trans.rs

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,50 +2178,45 @@ fn node_type(cx: @crate_ctxt, sp: span, id: ast::node_id) -> TypeRef {
21782178
type_of(cx, sp, ty)
21792179
}
21802180

2181-
fn trans_unary(cx: @block_ctxt, op: ast::unop, e: @ast::expr,
2182-
id: ast::node_id) -> result {
2183-
let e_ty = ty::expr_ty(bcx_tcx(cx), e);
2181+
fn trans_unary(bcx: @block_ctxt, op: ast::unop, e: @ast::expr,
2182+
id: ast::node_id, dest: dest) -> @block_ctxt {
2183+
if dest == ignore { ret trans_expr_dps(bcx, e, ignore); }
2184+
let e_ty = ty::expr_ty(bcx_tcx(bcx), e);
21842185
alt op {
21852186
ast::not. {
2186-
let sub = trans_expr(cx, e);
2187-
ret rslt(sub.bcx, Not(sub.bcx, sub.val));
2187+
let {bcx, val} = trans_expr(bcx, e);
2188+
ret store_in_dest(bcx, Not(bcx, val), dest);
21882189
}
21892190
ast::neg. {
2190-
let sub = trans_expr(cx, e);
2191-
if ty::struct(bcx_tcx(cx), e_ty) == ty::ty_float {
2192-
ret rslt(sub.bcx, FNeg(sub.bcx, sub.val));
2193-
} else { ret rslt(sub.bcx, Neg(sub.bcx, sub.val)); }
2191+
let {bcx, val} = trans_expr(bcx, e);
2192+
let neg = if ty::struct(bcx_tcx(bcx), e_ty) == ty::ty_float {
2193+
FNeg(bcx, val)
2194+
} else { Neg(bcx, val) };
2195+
ret store_in_dest(bcx, neg, dest);
21942196
}
21952197
ast::box(_) {
2196-
let lv = trans_lval(cx, e);
2197-
let box_ty = node_id_type(bcx_ccx(lv.bcx), id);
2198-
let sub = trans_malloc_boxed(lv.bcx, e_ty);
2199-
let body = sub.body;
2200-
add_clean_temp(cx, sub.box, box_ty);
2201-
2198+
let {bcx, box, body} = trans_malloc_boxed(bcx, e_ty);
2199+
add_clean_free(bcx, box, false);
22022200
// Cast the body type to the type of the value. This is needed to
22032201
// make tags work, since tags have a different LLVM type depending
22042202
// on whether they're boxed or not.
2205-
let sub_ccx = bcx_ccx(sub.bcx);
2206-
if check type_has_static_size(sub_ccx, e_ty) {
2203+
let ccx = bcx_ccx(bcx);
2204+
if check type_has_static_size(ccx, e_ty) {
22072205
let e_sp = e.span;
2208-
let llety = T_ptr(type_of(sub_ccx, e_sp, e_ty));
2209-
body = PointerCast(sub.bcx, body, llety);
2210-
} else {
2211-
} // FIXME: can remove the else{} once we have
2212-
// a new snapshot
2213-
2214-
2215-
let bcx = move_val_if_temp(sub.bcx, INIT, body, lv, e_ty);
2216-
ret rslt(bcx, sub.box);
2206+
let llety = T_ptr(type_of(ccx, e_sp, e_ty));
2207+
body = PointerCast(bcx, body, llety);
2208+
}
2209+
bcx = trans_expr_save_in(bcx, e, body);
2210+
revoke_clean(bcx, box);
2211+
ret store_in_dest(bcx, box, dest);
22172212
}
22182213
ast::uniq(_) {
2219-
ret trans_uniq::trans_uniq(cx, e, id);
2214+
ret trans_uniq::trans_uniq(bcx, e, id, dest);
22202215
}
22212216
ast::deref. {
2222-
bcx_ccx(cx).sess.bug("deref expressions should have been \
2223-
translated using trans_lval(), not \
2224-
trans_unary()");
2217+
bcx_ccx(bcx).sess.bug("deref expressions should have been \
2218+
translated using trans_lval(), not \
2219+
trans_unary()");
22252220
}
22262221
}
22272222
}
@@ -2498,7 +2493,7 @@ fn join_returns(parent_cx: @block_ctxt, in_cxs: [@block_ctxt],
24982493
ret out;
24992494
}
25002495

2501-
// Used to put an immediate value in a dest
2496+
// Used to put an immediate value in a dest.
25022497
fn store_in_dest(bcx: @block_ctxt, val: ValueRef, dest: dest) -> @block_ctxt {
25032498
alt dest {
25042499
ignore. {}
@@ -4092,23 +4087,23 @@ fn trans_rec(bcx: @block_ctxt, fields: [ast::field],
40924087
let ty_fields = alt ty::struct(bcx_tcx(bcx), t) { ty::ty_rec(f) { f } };
40934088
let temp_cleanups = [], i = 0;
40944089
for tf in ty_fields {
4095-
let gep = GEP_tup_like_1(bcx, t, addr, [0, i]);
4096-
bcx = gep.bcx;
4090+
let dst = GEP_tup_like_1(bcx, t, addr, [0, i]);
4091+
bcx = dst.bcx;
40974092
// FIXME make this {|f| str::eq(f.node.ident, tf.ident)} again when
40984093
// bug #913 is fixed
40994094
fn test(n: str, f: ast::field) -> bool { str::eq(f.node.ident, n) }
41004095
alt vec::find(bind test(tf.ident, _), fields) {
41014096
some(f) {
4102-
bcx = trans_expr_save_in(bcx, f.node.expr, gep.val);
4097+
bcx = trans_expr_save_in(bcx, f.node.expr, dst.val);
41034098
}
41044099
none. {
41054100
let base = GEP_tup_like_1(bcx, t, base_val, [0, i]);
41064101
let val = load_if_immediate(base.bcx, base.val, tf.mt.ty);
4107-
bcx = copy_val(base.bcx, INIT, gep.val, val, tf.mt.ty);
4102+
bcx = copy_val(base.bcx, INIT, dst.val, val, tf.mt.ty);
41084103
}
41094104
}
4110-
add_clean_temp_mem(bcx, addr, tf.mt.ty);
4111-
temp_cleanups += [addr];
4105+
add_clean_temp_mem(bcx, dst.val, tf.mt.ty);
4106+
temp_cleanups += [dst.val];
41124107
i += 1;
41134108
}
41144109
// Now revoke the cleanups as we pass responsibility for the data
@@ -4193,9 +4188,6 @@ fn trans_expr(cx: @block_ctxt, e: @ast::expr) -> result {
41934188
if sub.is_mem { v = load_if_immediate(sub.bcx, v, t); }
41944189
ret rslt(sub.bcx, v);
41954190
}
4196-
ast::expr_unary(op, x) {
4197-
ret trans_unary(cx, op, x, e.id);
4198-
}
41994191
// Fall through to DPS-style
42004192
_ {
42014193
ret dps_to_result(cx, {|bcx, dest| trans_expr_dps(bcx, e, dest)},
@@ -4259,6 +4251,12 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
42594251
ast::expr_lit(lit) { ret trans_lit(bcx, *lit, dest); }
42604252
ast::expr_vec(args, _) { ret tvec::trans_vec(bcx, args, e.id, dest); }
42614253
ast::expr_binary(op, x, y) { ret trans_binary(bcx, op, x, y, dest); }
4254+
ast::expr_unary(op, x) {
4255+
if op == ast::deref {
4256+
ret trans_expr_backwards_compat(bcx, e, dest);
4257+
}
4258+
ret trans_unary(bcx, op, x, e.id, dest);
4259+
}
42624260

42634261
ast::expr_break. {
42644262
assert dest == ignore;
@@ -4365,40 +4363,43 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
43654363

43664364
ast::expr_mac(_) { ret bcx_ccx(bcx).sess.bug("unexpanded macro"); }
43674365
// Convert back from result to DPS
4368-
_ {
4369-
let lv = trans_lval(bcx, e);
4370-
let {bcx, val, is_mem} = lv;
4371-
let ty = ty::expr_ty(bcx_tcx(bcx), e);
4372-
alt dest {
4373-
by_val(cell) {
4374-
if !is_mem {
4375-
revoke_clean(bcx, val);
4376-
*cell = val;
4377-
} else if ty::type_is_unique(bcx_tcx(bcx), ty) {
4378-
// Do a song and a dance to work around the fact that take_ty
4379-
// for unique boxes overwrites the pointer.
4380-
let oldval = Load(bcx, val);
4381-
bcx = take_ty(bcx, val, ty);
4382-
*cell = Load(bcx, val);
4383-
Store(bcx, oldval, val);
4384-
} else {
4385-
bcx = take_ty(bcx, val, ty);
4386-
*cell = Load(bcx, val);
4387-
}
4388-
}
4389-
by_ref(cell) {
4390-
assert is_mem;
4366+
_ { ret trans_expr_backwards_compat(bcx, e, dest); }
4367+
}
4368+
}
4369+
4370+
fn trans_expr_backwards_compat(bcx: @block_ctxt, e: @ast::expr, dest: dest)
4371+
-> @block_ctxt {
4372+
let lv = trans_lval(bcx, e);
4373+
let {bcx, val, is_mem} = lv;
4374+
let ty = ty::expr_ty(bcx_tcx(bcx), e);
4375+
alt dest {
4376+
by_val(cell) {
4377+
if !is_mem {
4378+
revoke_clean(bcx, val);
43914379
*cell = val;
4392-
}
4393-
save_in(loc) { bcx = move_val_if_temp(bcx, INIT, loc, lv, ty); }
4394-
overwrite(loc, _) {
4395-
bcx = move_val_if_temp(bcx, DROP_EXISTING, loc, lv, ty);
4396-
}
4397-
ignore. {}
4380+
} else if ty::type_is_unique(bcx_tcx(bcx), ty) {
4381+
// Do a song and a dance to work around the fact that take_ty
4382+
// for unique boxes overwrites the pointer.
4383+
let oldval = Load(bcx, val);
4384+
bcx = take_ty(bcx, val, ty);
4385+
*cell = Load(bcx, val);
4386+
Store(bcx, oldval, val);
4387+
} else {
4388+
bcx = take_ty(bcx, val, ty);
4389+
*cell = Load(bcx, val);
43984390
}
4399-
ret bcx;
44004391
}
4392+
by_ref(cell) {
4393+
assert is_mem;
4394+
*cell = val;
4395+
}
4396+
save_in(loc) { bcx = move_val_if_temp(bcx, INIT, loc, lv, ty); }
4397+
overwrite(loc, _) {
4398+
bcx = move_val_if_temp(bcx, DROP_EXISTING, loc, lv, ty);
4399+
}
4400+
ignore. {}
44014401
}
4402+
ret bcx;
44024403
}
44034404

44044405
// We pass structural values around the compiler "by pointer" and

trunk/src/comp/middle/trans_common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ fn add_clean_temp_mem(cx: @block_ctxt, val: ValueRef, ty: ty::t) {
288288
scope_cx.cleanups += [clean_temp(val, bind drop_ty(_, val, ty))];
289289
scope_cx.lpad_dirty = true;
290290
}
291+
fn add_clean_free(cx: @block_ctxt, ptr: ValueRef, shared: bool) {
292+
let scope_cx = find_scope_cx(cx);
293+
let free_fn = if shared { bind trans::trans_shared_free(_, ptr) }
294+
else { bind trans::trans_non_gc_free(_, ptr) };
295+
scope_cx.cleanups += [clean_temp(ptr, free_fn)];
296+
scope_cx.lpad_dirty = true;
297+
}
291298

292299
// Note that this only works for temporaries. We should, at some point, move
293300
// to a system where we can also cancel the cleanup on local variables, but

trunk/src/comp/middle/trans_uniq.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import trans::{
1313
trans_shared_free,
1414
drop_ty,
1515
new_sub_block_ctxt,
16-
load_if_immediate
16+
load_if_immediate,
17+
dest
1718
};
1819

1920
export trans_uniq, make_free_glue, type_is_unique_box, copy_val,
@@ -23,31 +24,15 @@ pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
2324
ty::type_is_unique_box(bcx_tcx(bcx), ty)
2425
}
2526

26-
fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
27-
node_id: ast::node_id) -> result {
28-
let bcx = cx;
29-
30-
let lv = trans_lval(bcx, contents);
31-
bcx = lv.bcx;
32-
33-
let uniq_ty = node_id_type(bcx_ccx(cx), node_id);
34-
35-
if ty::type_is_bot(bcx_tcx(bcx), uniq_ty) {
36-
// FIXME: Seems to work, obviously not 'right'. Story of my life.
37-
// Probably works because the builder turns lv.val into undef
38-
ret rslt(bcx, lv.val);
39-
}
40-
27+
fn trans_uniq(bcx: @block_ctxt, contents: @ast::expr,
28+
node_id: ast::node_id, dest: dest) -> @block_ctxt {
29+
let uniq_ty = node_id_type(bcx_ccx(bcx), node_id);
4130
check type_is_unique_box(bcx, uniq_ty);
42-
let content_ty = content_ty(bcx, uniq_ty);
4331
let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty);
44-
45-
add_clean_temp(bcx, llptr, uniq_ty);
46-
47-
bcx = move_val_if_temp(bcx, INIT, llptr, lv,
48-
content_ty);
49-
50-
ret rslt(bcx, llptr);
32+
add_clean_free(bcx, llptr, true);
33+
bcx = trans::trans_expr_save_in(bcx, contents, llptr);
34+
revoke_clean(bcx, llptr);
35+
ret trans::store_in_dest(bcx, llptr, dest);
5136
}
5237

5338
fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t)

trunk/src/comp/middle/trans_vec.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id,
116116
llunitty: llunitty} =
117117
alloc(bcx, vec_ty, vec::len(args), dest);
118118

119+
let vptr = Load(bcx, vptrptr);
120+
add_clean_free(bcx, vptr, true);
119121
// Store the individual elements.
120122
let dataptr = get_dataptr(bcx, vptrptr, llunitty);
121-
add_clean_temp_mem(bcx, vptrptr, vec_ty);
122-
let i = 0u, temp_cleanups = [vptrptr];
123+
let i = 0u, temp_cleanups = [vptr];
123124
for e in args {
124125
let lv = trans_lval(bcx, e);
125126
bcx = lv.bcx;

0 commit comments

Comments
 (0)