Skip to content

Commit db7a6ca

Browse files
committed
---
yaml --- r: 4729 b: refs/heads/master c: 03174b4 h: refs/heads/master i: 4727: e6805d1 v: v3
1 parent 21ddaec commit db7a6ca

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
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: 27169387fe615269fa79d0d904d96be0226d628a
2+
refs/heads/master: 03174b437916fb8d5d1294e1a16042283ade6979

trunk/src/comp/middle/trans.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ fn make_drop_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
14201420
maybe_free_ivec_heap_part(rslt.bcx, v1, tm.ty)
14211421
}
14221422
ty::ty_box(_) { decr_refcnt_maybe_free(cx, v0, v0, t) }
1423-
ty::ty_uniq(_) { fail "drop uniq unimplemented"; }
1423+
ty::ty_uniq(_) { trans_shared_free(cx, cx.build.Load(v0)) }
14241424
ty::ty_obj(_) {
14251425
let box_cell =
14261426
cx.build.GEP(v0, ~[C_int(0), C_int(abi::obj_field_box)]);
@@ -2311,6 +2311,7 @@ fn copy_val(cx: &@block_ctxt, action: copy_action, dst: ValueRef,
23112311
// FIXME: We always zero out the source. Ideally we would detect the
23122312
// case where a variable is always deinitialized by block exit and thus
23132313
// doesn't need to be dropped.
2314+
// FIXME: This can return only a block_ctxt, not a result.
23142315
fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
23152316
src: &lval_result, t: &ty::t) -> result {
23162317
let src_val = src.res.val;
@@ -2322,18 +2323,18 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
23222323
} else if (ty::type_is_nil(bcx_tcx(cx), t) ||
23232324
ty::type_is_bot(bcx_tcx(cx), t)) {
23242325
ret rslt(cx, C_nil());
2325-
} else if (ty::type_is_boxed(bcx_tcx(cx), t)) {
2326+
} else if (ty::type_is_unique(bcx_tcx(cx), t) ||
2327+
ty::type_is_boxed(bcx_tcx(cx), t)) {
23262328
if src.is_mem { src_val = cx.build.Load(src_val); }
23272329
if action == DROP_EXISTING {
23282330
cx = drop_ty(cx, cx.build.Load(dst), t).bcx;
23292331
}
23302332
cx.build.Store(src_val, dst);
2331-
if src.is_mem {
2332-
ret zero_alloca(cx, src.res.val, t);
2333-
} else { // It must be a temporary
2334-
revoke_clean(cx, src_val);
2335-
ret rslt(cx, C_nil());
2336-
}
2333+
if src.is_mem { ret zero_alloca(cx, src.res.val, t); }
2334+
2335+
// If we're here, it must be a temporary.
2336+
revoke_clean(cx, src_val);
2337+
ret rslt(cx, C_nil());
23372338
} else if (ty::type_is_structural(bcx_tcx(cx), t) ||
23382339
ty::type_has_dynamic_size(bcx_tcx(cx), t)) {
23392340
if action == DROP_EXISTING { cx = drop_ty(cx, dst, t).bcx; }
@@ -2356,7 +2357,8 @@ fn move_val_if_temp(cx: @block_ctxt, action: copy_action, dst: ValueRef,
23562357
if src.is_mem {
23572358
ret copy_val(cx, action, dst, load_if_immediate(cx, src.res.val, t),
23582359
t);
2359-
} else { ret move_val(cx, action, dst, src, t); }
2360+
}
2361+
ret move_val(cx, action, dst, src, t);
23602362
}
23612363

23622364
fn trans_lit_istr(cx: &@block_ctxt, s: str) -> result {
@@ -4092,6 +4094,7 @@ fn trans_lval_gen(cx: &@block_ctxt, e: &@ast::expr) -> lval_result {
40924094
};
40934095
ret lval_mem(sub.bcx, val);
40944096
}
4097+
ast::expr_uniq(contents) { ret trans_uniq(cx, contents); }
40954098
ast::expr_self_method(ident) {
40964099
alt { cx.fcx.llself } {
40974100
some(pair) {
@@ -5346,6 +5349,25 @@ fn trans_put(cx: &@block_ctxt, e: &option::t[@ast::expr]) -> result {
53465349
ret rslt(bcx, C_nil());
53475350
}
53485351

5352+
fn trans_uniq(cx: &@block_ctxt, contents: &@ast::expr) -> lval_result {
5353+
let bcx = cx;
5354+
5355+
let contents_ty = ty::expr_ty(bcx_tcx(bcx), contents);
5356+
let r = size_of(bcx, contents_ty);
5357+
bcx = r.bcx;
5358+
let llsz = r.val;
5359+
5360+
let llptrty = T_ptr(type_of_or_i8(bcx, contents_ty));
5361+
5362+
r = trans_shared_malloc(bcx, llptrty, llsz);
5363+
bcx = r.bcx;
5364+
let llptrptr = r.val;
5365+
5366+
let llptr = bcx.build.Load(llptrptr);
5367+
r = trans_expr_out(bcx, contents, save_in(llptr));
5368+
ret lval_val(r.bcx, llptrptr);
5369+
}
5370+
53495371
fn trans_break_cont(sp: &span, cx: &@block_ctxt, to_end: bool) -> result {
53505372
let bcx = cx;
53515373
// Locate closest loop block, outputting cleanup as we go.

trunk/src/comp/middle/ty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export type_is_structural;
175175
export type_is_copyable;
176176
export type_is_tup_like;
177177
export type_is_str;
178+
export type_is_unique;
178179
export type_owns_heap_mem;
179180
export type_autoderef;
180181
export type_param;
@@ -934,6 +935,10 @@ fn type_is_boxed(cx: &ctxt, ty: &t) -> bool {
934935
}
935936
}
936937

938+
fn type_is_unique(cx: &ctxt, ty: &t) -> bool {
939+
alt struct(cx, ty) { ty_uniq(_) { ret true; } _ { ret false; } }
940+
}
941+
937942
fn type_is_scalar(cx: &ctxt, ty: &t) -> bool {
938943
alt struct(cx, ty) {
939944
ty_nil. { ret true; }

0 commit comments

Comments
 (0)