Skip to content

Commit e9ad977

Browse files
committed
---
yaml --- r: 4908 b: refs/heads/master c: e58c48b h: refs/heads/master v: v3
1 parent 16cd427 commit e9ad977

File tree

6 files changed

+83
-15
lines changed

6 files changed

+83
-15
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: bead045f2724e3a256a2123a844b079f82047dd4
2+
refs/heads/master: e58c48bddae60e21dc8958407dadf6d187b78ea9

trunk/src/comp/back/upcall.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type upcalls =
4343
ivec_spill: ValueRef,
4444
ivec_resize_shared: ValueRef,
4545
ivec_spill_shared: ValueRef,
46+
ivec_push: ValueRef,
4647
cmp_type: ValueRef,
4748
log_type: ValueRef,
4849
dynastack_mark: ValueRef,
@@ -101,6 +102,9 @@ fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
101102
ivec_spill_shared:
102103
d("ivec_spill_shared", [T_ptr(T_opaque_ivec()), T_int()],
103104
T_void()),
105+
ivec_push:
106+
d("ivec_push", [T_ptr(T_opaque_ivec()), T_ptr(tydesc_type),
107+
T_ptr(T_i8())], T_void()),
104108
cmp_type:
105109
dr("cmp_type",
106110
[T_ptr(T_i1()), taskptr_type, T_ptr(tydesc_type),

trunk/src/comp/middle/trans.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,16 +4351,32 @@ fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) ->
43514351
ret rslt(bcx, C_nil());
43524352
}
43534353
ast::expr_assign_op(op, dst, src) {
4354-
let t = ty::expr_ty(bcx_tcx(cx), src);
4354+
let tcx = bcx_tcx(cx);
4355+
let t = ty::expr_ty(tcx, src);
43554356
let lhs_res = trans_lval(cx, dst);
43564357
assert (lhs_res.is_mem);
4357-
// FIXME Fill in lhs_res.res.bcx.sp
43584358

4359+
// Special case for `+= [x]`
4360+
alt ty::struct(tcx, t) {
4361+
ty::ty_vec(_) {
4362+
alt src.node {
4363+
ast::expr_vec(args, _) {
4364+
let bcx = ivec::trans_append_literal
4365+
(lhs_res.res.bcx, lhs_res.res.val, t, args);
4366+
ret rslt(bcx, C_nil());
4367+
}
4368+
_ {}
4369+
}
4370+
}
4371+
_ {}
4372+
}
4373+
4374+
// FIXME Fill in lhs_res.res.bcx.sp
43594375
let rhs_res = trans_expr(lhs_res.res.bcx, src);
4360-
if ty::type_is_sequence(bcx_tcx(cx), t) {
4376+
if ty::type_is_sequence(tcx, t) {
43614377
alt op {
43624378
ast::add. {
4363-
if ty::sequence_is_interior(bcx_tcx(cx), t) {
4379+
if ty::sequence_is_interior(tcx, t) {
43644380
ret ivec::trans_append(rhs_res.bcx, t, lhs_res.res.val,
43654381
rhs_res.val);
43664382
}

trunk/src/comp/middle/trans_ivec.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import trans::{call_memmove, trans_shared_malloc, llsize_of,
1111
new_sub_block_ctxt};
1212
import trans_common::*;
1313

14-
export trans_ivec, get_len_and_data, duplicate_heap_part, trans_add,
15-
trans_append, alloc_with_heap;
16-
1714
fn alloc_with_heap(bcx: @block_ctxt, typ: &ty::t, vecsz: uint) ->
1815
{bcx: @block_ctxt,
1916
unit_ty: ty::t,
@@ -342,15 +339,13 @@ fn reserve_space(cx: &@block_ctxt, llunitty: TypeRef, v: ValueRef,
342339
stack_no_spill_cx.llbb, stack_spill_cx.llbb]);
343340
ret rslt(next_cx, data_ptr);
344341
}
345-
fn trans_append(cx: &@block_ctxt, t: ty::t, orig_lhs: ValueRef,
346-
orig_rhs: ValueRef) -> result {
342+
fn trans_append(cx: &@block_ctxt, t: ty::t, lhs: ValueRef,
343+
rhs: ValueRef) -> result {
347344
// Cast to opaque interior vector types if necessary.
348-
let lhs;
349-
let rhs;
350345
if ty::type_has_dynamic_size(bcx_tcx(cx), t) {
351-
lhs = cx.build.PointerCast(orig_lhs, T_ptr(T_opaque_ivec()));
352-
rhs = cx.build.PointerCast(orig_rhs, T_ptr(T_opaque_ivec()));
353-
} else { lhs = orig_lhs; rhs = orig_rhs; }
346+
lhs = cx.build.PointerCast(lhs, T_ptr(T_opaque_ivec()));
347+
rhs = cx.build.PointerCast(rhs, T_ptr(T_opaque_ivec()));
348+
}
354349

355350
let unit_ty = ty::sequence_element_type(bcx_tcx(cx), t);
356351
let llunitty = type_of_or_i8(cx, unit_ty);
@@ -448,6 +443,24 @@ fn trans_append(cx: &@block_ctxt, t: ty::t, orig_lhs: ValueRef,
448443
ret rslt(next_cx, C_nil());
449444
}
450445

446+
fn trans_append_literal(bcx: &@block_ctxt, v: ValueRef, vec_ty: ty::t,
447+
vals: &[@ast::expr]) -> @block_ctxt {
448+
let elt_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty);
449+
let ti = none;
450+
let {bcx, val: td} = get_tydesc(bcx, elt_ty, false, ti).result;
451+
trans::lazily_emit_all_tydesc_glue(bcx, ti);
452+
let opaque_v = bcx.build.PointerCast(v, T_ptr(T_opaque_ivec()));
453+
for val in vals {
454+
let {bcx: e_bcx, val: elt} = trans::trans_expr(bcx, val);
455+
bcx = e_bcx;
456+
let spilled = trans::spill_if_immediate(bcx, elt, elt_ty);
457+
bcx.build.Call(bcx_ccx(bcx).upcalls.ivec_push,
458+
[bcx.fcx.lltaskptr, opaque_v, td,
459+
bcx.build.PointerCast(spilled, T_ptr(T_i8()))]);
460+
}
461+
ret bcx;
462+
}
463+
451464
type alloc_result =
452465
{bcx: @block_ctxt,
453466
llptr: ValueRef,
@@ -756,3 +769,13 @@ fn duplicate_heap_part(cx: &@block_ctxt, orig_vptr: ValueRef,
756769

757770
ret rslt(next_cx, C_nil());
758771
}
772+
//
773+
// Local Variables:
774+
// mode: rust
775+
// fill-column: 78;
776+
// indent-tabs-mode: nil
777+
// c-basic-offset: 4
778+
// buffer-file-coding-system: utf-8-unix
779+
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
780+
// End:
781+
//

trunk/src/rt/rust_upcall.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,30 @@ upcall_ivec_spill_shared(rust_task *task,
394394
v->payload.ptr = heap_part;
395395
}
396396

397+
extern "C" CDECL void
398+
upcall_ivec_push(rust_task* task, rust_ivec* v, type_desc* elt_ty, void* x) {
399+
LOG_UPCALL_ENTRY(task);
400+
bool is_interior = v->fill || !v->payload.ptr;
401+
size_t sz = elt_ty->size;
402+
size_t old_fill = is_interior ? v->fill : v->payload.ptr->fill;
403+
size_t new_sz = sz + old_fill;
404+
if (new_sz > v->alloc) {
405+
if (is_interior) {
406+
upcall_ivec_spill_shared(task, v, new_sz);
407+
is_interior = false;
408+
} else {
409+
upcall_ivec_resize_shared(task, v, new_sz);
410+
}
411+
} else {
412+
if (is_interior) v->fill = new_sz;
413+
else v->payload.ptr->fill = new_sz;
414+
}
415+
uint8_t* dataptr = is_interior ? &v->payload.data[0]
416+
: &v->payload.ptr->data[0];
417+
copy_elements(task, elt_ty, dataptr + old_fill, x, sz);
418+
}
419+
420+
397421
/**
398422
* Returns a token that can be used to deallocate all of the allocated space
399423
* space in the dynamic stack.

trunk/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ upcall_get_type_desc
8989
upcall_grow_task
9090
upcall_ivec_resize_shared
9191
upcall_ivec_spill_shared
92+
upcall_ivec_push
9293
upcall_kill
9394
upcall_log_double
9495
upcall_log_float

0 commit comments

Comments
 (0)