Skip to content

Commit bba856b

Browse files
committed
---
yaml --- r: 4882 b: refs/heads/master c: 1a45a84 h: refs/heads/master v: v3
1 parent 8a1ffa5 commit bba856b

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
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: 3948f132d9236fe46c225ccae6973daa950aa190
2+
refs/heads/master: 1a45a84e73a92e8a985b382e8461723acd361220

trunk/src/comp/middle/trans.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,10 @@ fn emit_tydescs(ccx: &@crate_ctxt) {
12721272
}
12731273
}
12741274

1275-
fn make_copy_glue(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, t: ty::t) {
1275+
// NOTE this is currently just a complicated way to do memmove. I'm working on
1276+
// a representation of ivecs that will need pointers into itself, which must
1277+
// be adjusted when copying. Will flesh this out when the time comes.
1278+
fn make_copy_glue(cx: &@block_ctxt, src: ValueRef, dst: ValueRef, t: ty::t) {
12761279
let bcx = memmove_ty(cx, dst, src, t).bcx;
12771280
build_return(bcx);
12781281
}
@@ -2369,9 +2372,12 @@ fn copy_val_no_check(cx: &@block_ctxt, action: copy_action, dst: ValueRef,
23692372
let bcx = if action == DROP_EXISTING {
23702373
drop_ty(cx, dst, t).bcx
23712374
} else { cx };
2372-
bcx = memmove_ty(bcx, dst, src, t).bcx;
2373-
bcx = take_ty(bcx, dst, t).bcx;
2374-
ret bcx;
2375+
if ty::type_needs_copy_glue(ccx.tcx, t) {
2376+
ret call_copy_glue(bcx, dst, src, t, true);
2377+
} else {
2378+
bcx = memmove_ty(bcx, dst, src, t).bcx;
2379+
ret take_ty(bcx, dst, t).bcx;
2380+
}
23752381
}
23762382
ccx.sess.bug("unexpected type in trans::copy_val_no_check: " +
23772383
ty_to_str(ccx.tcx, t));
@@ -2386,16 +2392,16 @@ fn copy_val_no_check(cx: &@block_ctxt, action: copy_action, dst: ValueRef,
23862392
fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
23872393
src: &lval_result, t: ty::t) -> @block_ctxt {
23882394
let src_val = src.res.val;
2389-
if ty::type_is_scalar(bcx_tcx(cx), t) ||
2390-
ty::type_is_native(bcx_tcx(cx), t) {
2395+
let tcx = bcx_tcx(cx);
2396+
if ty::type_is_scalar(tcx, t) ||
2397+
ty::type_is_native(tcx, t) {
23912398
if src.is_mem { src_val = cx.build.Load(src_val); }
23922399
cx.build.Store(src_val, dst);
23932400
ret cx;
2394-
} else if ty::type_is_nil(bcx_tcx(cx), t) ||
2395-
ty::type_is_bot(bcx_tcx(cx), t) {
2401+
} else if ty::type_is_nil(tcx, t) || ty::type_is_bot(tcx, t) {
23962402
ret cx;
2397-
} else if ty::type_is_unique(bcx_tcx(cx), t) ||
2398-
ty::type_is_boxed(bcx_tcx(cx), t) {
2403+
} else if ty::type_is_unique(tcx, t) ||
2404+
ty::type_is_boxed(tcx, t) {
23992405
if src.is_mem { src_val = cx.build.Load(src_val); }
24002406
if action == DROP_EXISTING {
24012407
cx = drop_ty(cx, cx.build.Load(dst), t).bcx;
@@ -2406,10 +2412,13 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
24062412
// If we're here, it must be a temporary.
24072413
revoke_clean(cx, src_val);
24082414
ret cx;
2409-
} else if ty::type_is_structural(bcx_tcx(cx), t) ||
2410-
ty::type_has_dynamic_size(bcx_tcx(cx), t) {
2415+
} else if type_is_structural_or_param(tcx, t) {
24112416
if action == DROP_EXISTING { cx = drop_ty(cx, dst, t).bcx; }
2412-
cx = memmove_ty(cx, dst, src_val, t).bcx;
2417+
if ty::type_needs_copy_glue(tcx, t) {
2418+
cx = call_copy_glue(cx, dst, src_val, t, false);
2419+
} else {
2420+
cx = memmove_ty(cx, dst, src_val, t).bcx;
2421+
}
24132422
if src.is_mem {
24142423
ret zero_alloca(cx, src_val, t).bcx;
24152424
} else { // Temporary value
@@ -2418,7 +2427,7 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
24182427
}
24192428
}
24202429
bcx_ccx(cx).sess.bug("unexpected type in trans::move_val: " +
2421-
ty_to_str(bcx_tcx(cx), t));
2430+
ty_to_str(tcx, t));
24222431
}
24232432

24242433
fn move_val_if_temp(cx: @block_ctxt, action: copy_action, dst: ValueRef,
@@ -5049,16 +5058,14 @@ fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) ->
50495058

50505059
let rhs_res = trans_lval(lhs_res.res.bcx, src);
50515060
let t = ty::expr_ty(bcx_tcx(cx), src);
5052-
let tmp_res = alloc_ty(rhs_res.res.bcx, t);
5061+
let {bcx, val: tmp_alloc} = alloc_ty(rhs_res.res.bcx, t);
50535062
// Swap through a temporary.
50545063

5055-
let move1_res =
5056-
memmove_ty(tmp_res.bcx, tmp_res.val, lhs_res.res.val, t);
5057-
let move2_res =
5058-
memmove_ty(move1_res.bcx, lhs_res.res.val, rhs_res.res.val, t);
5059-
let move3_res =
5060-
memmove_ty(move2_res.bcx, rhs_res.res.val, tmp_res.val, t);
5061-
ret rslt(move3_res.bcx, C_nil());
5064+
bcx = move_val(bcx, INIT, tmp_alloc, lhs_res, t);
5065+
bcx = move_val(bcx, INIT, lhs_res.res.val, rhs_res, t);
5066+
bcx = move_val(bcx, INIT, rhs_res.res.val,
5067+
lval_mem(bcx, tmp_alloc), t);
5068+
ret rslt(bcx, C_nil());
50625069
}
50635070
ast::expr_assign_op(op, dst, src) {
50645071
let t = ty::expr_ty(bcx_tcx(cx), src);

trunk/src/comp/middle/trans_alt.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,9 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: &@ast::pat, val: ValueRef,
526526
let ty = ty::node_id_to_monotype(ccx.tcx, pat.id);
527527
let llty = trans::type_of(ccx, pat.span, ty);
528528
let alloc = trans::alloca(bcx, llty);
529-
bcx = trans::memmove_ty(bcx, alloc, val, ty).bcx;
530-
let loaded = trans::load_if_immediate(bcx, alloc, ty);
531-
bcx = trans::take_ty(bcx, loaded, ty).bcx;
529+
bcx = trans::copy_val(bcx, trans::INIT, alloc,
530+
trans::load_if_immediate(bcx, val, ty), ty);
532531
table.insert(pat.id, alloc);
533-
trans_common::add_clean(bcx, alloc, ty);
534532
} else { table.insert(pat.id, val); }
535533
}
536534
ast::pat_tag(_, sub) {

trunk/src/comp/middle/ty.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export type_kind;
155155
export type_err;
156156
export type_err_to_str;
157157
export type_has_dynamic_size;
158+
export type_needs_copy_glue;
158159
export type_has_pointers;
159160
export type_needs_drop;
160161
export type_is_bool;
@@ -1175,6 +1176,17 @@ fn type_has_dynamic_size(cx: &ctxt, ty: t) -> bool {
11751176
});
11761177
}
11771178

1179+
fn type_needs_copy_glue(cx: &ctxt, ty: t) -> bool {
1180+
ret type_structurally_contains(cx, ty, fn(sty: &sty) -> bool {
1181+
ret alt sty {
1182+
ty_param(_, _) { true }
1183+
ty_vec(_) { true }
1184+
ty_istr. { true }
1185+
_ { false }
1186+
};
1187+
});
1188+
}
1189+
11781190
fn type_is_integral(cx: &ctxt, ty: t) -> bool {
11791191
alt struct(cx, ty) {
11801192
ty_int. { ret true; }

0 commit comments

Comments
 (0)