Skip to content

Commit 1730d2e

Browse files
committed
Notify copy glue of dst-initialization and fix _vec.alloc issues in lib and runtime. Closes #109.
1 parent ede42cf commit 1730d2e

File tree

7 files changed

+41
-16
lines changed

7 files changed

+41
-16
lines changed

src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ TEST_XFAILS_X86 := test/run-pass/bind-obj-ctor.rs \
364364
test/run-pass/mutable-vec-drop.rs \
365365
test/run-pass/obj-as.rs \
366366
test/run-pass/task-comm.rs \
367-
test/run-pass/vec-alloc-append.rs \
368367
test/run-pass/vec-slice.rs \
369368
test/run-pass/task-comm-2.rs \
370369
test/run-pass/task-comm-3.rs \

src/boot/be/abi.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ let tydesc_field_free_glue = 5;;
7777
let tydesc_field_sever_glue = 6;;
7878
let tydesc_field_mark_glue = 7;;
7979
let tydesc_field_obj_drop_glue = 8;;
80-
let tydesc_field_cmp_glue = 9;;
81-
let tydesc_field_hash_glue = 10;;
80+
let tydesc_field_cmp_glue = 9;; (* FIXME these two aren't in the *)
81+
let tydesc_field_hash_glue = 10;; (* runtime's type_desc struct. *)
82+
let tydesc_field_stateflag = 11;;
8283

8384
let vec_elt_rc = 0;;
8485
let vec_elt_alloc = 1;;

src/boot/me/trans.ml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,9 @@ let trans_visitor
11121112
let fix fixup =
11131113
fixup_rel_word tydesc_fixup fixup
11141114
in
1115-
log cx "tydesc for %a has sz=%Ld, align=%Ld"
1116-
Ast.sprintf_ty t sz align;
1115+
let is_stateful = if type_has_state t then 1L else 0L in
1116+
log cx "tydesc for %a has sz=%Ld, align=%Ld, is_stateful=%Ld"
1117+
Ast.sprintf_ty t sz align is_stateful;
11171118
Asm.DEF
11181119
(tydesc_fixup,
11191120
Asm.SEQ
@@ -1145,6 +1146,7 @@ let trans_visitor
11451146
Asm.WORD (word_ty_mach, Asm.IMM 0L);
11461147
end
11471148
end;
1149+
Asm.WORD (word_ty_mach, Asm.IMM is_stateful);
11481150
|])
11491151
end
11501152

@@ -1715,13 +1717,23 @@ let trans_visitor
17151717
let dst = deref out_ptr in
17161718
let ty_params = deref (get_element_ptr args 0) in
17171719
let src = deref (get_element_ptr args 1) in
1718-
trans_copy_ty ty_params false dst ty src ty curr_iso
1720+
1721+
(* Translate copy code for the dst-initializing and
1722+
* dst-non-initializing cases and branch accordingly. *)
1723+
let initflag = get_element_ptr args 2 in
1724+
let jmps = trans_compare_simple Il.JNE (Il.Cell initflag) one in
1725+
trans_copy_ty ty_params true dst ty src ty curr_iso;
1726+
let skip_noninit_jmp = mark() in
1727+
emit (Il.jmp Il.JMP Il.CodeNone);
1728+
List.iter patch jmps;
1729+
trans_copy_ty ty_params false dst ty src ty curr_iso;
1730+
patch skip_noninit_jmp;
17191731
in
17201732
let ty_params_ptr = ty_params_covering ty in
17211733
let fty =
17221734
mk_ty_fn
17231735
(local_slot ty)
1724-
[| ty_params_ptr; alias_slot ty |]
1736+
[| ty_params_ptr; alias_slot ty; word_slot |]
17251737
in
17261738
get_typed_mem_glue g fty inner
17271739

@@ -3198,6 +3210,8 @@ let trans_visitor
31983210
iflog
31993211
(fun _ -> annotate
32003212
(Printf.sprintf "copy_ty: parametric copy %#d" i));
3213+
let initflag = if initializing then one else zero in
3214+
let initflag = Il.Reg (force_to_reg initflag) in
32013215
aliasing false src
32023216
begin
32033217
fun src ->
@@ -3206,7 +3220,7 @@ let trans_visitor
32063220
trans_call_dynamic_glue
32073221
td Abi.tydesc_field_copy_glue
32083222
(Some dst)
3209-
[| ty_params_ptr; src; |]
3223+
[| ty_params_ptr; src; initflag |]
32103224
None
32113225
end
32123226

@@ -4299,7 +4313,12 @@ let trans_visitor
42994313
[| vr; fp |]
43004314
None
43014315

4302-
and trans_vec_append dst_cell dst_ty src_oper src_ty =
4316+
and trans_vec_append
4317+
(dst_cell:Il.cell)
4318+
(dst_ty:Ast.ty)
4319+
(src_oper:Il.operand)
4320+
(src_ty:Ast.ty)
4321+
: unit =
43034322
let elt_ty = seq_unit_ty dst_ty in
43044323
let trim_trailing_null = dst_ty = Ast.TY_str in
43054324
assert (simplified_ty src_ty = simplified_ty dst_ty);

src/lib/_vec.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ native "rust" mod rustrt {
55
type vbuf;
66
fn vec_buf[T](vec[T] v) -> vbuf;
77
fn vec_len[T](vec[T] v) -> uint;
8-
fn vec_alloc[T](uint n_elts) -> vec[T];
8+
/* The T in vec_alloc[T, U] is the type of the vec to allocate. The
9+
* U is the type of an element in the vec. So to allocate a vec[U] we
10+
* want to invoke this as vec_alloc[vec[U], U]. */
11+
fn vec_alloc[T, U](uint n_elts) -> vec[U];
912
fn refcount[T](vec[T] v) -> uint;
1013
}
1114

1215
fn alloc[T](uint n_elts) -> vec[T] {
13-
ret rustrt.vec_alloc[T](n_elts);
16+
ret rustrt.vec_alloc[vec[T], T](n_elts);
1417
}
1518

1619
type init_op[T] = fn(uint i) -> T;

src/rt/rust_builtin.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ unsupervise(rust_task *task) {
9292
}
9393

9494
extern "C" CDECL rust_vec*
95-
vec_alloc(rust_task *task, type_desc *t, size_t n_elts)
95+
vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
9696
{
9797
rust_dom *dom = task->dom;
9898
task->log(rust_log::MEM,
99-
"vec_alloc %" PRIdPTR " elements of size %" PRIdPTR,
100-
n_elts, t->size);
101-
size_t fill = n_elts * t->size;
99+
"vec_alloc %" PRIdPTR " elements of size %" PRIdPTR,
100+
n_elts, elem_t->size);
101+
size_t fill = n_elts * elem_t->size;
102102
size_t alloc = next_power_of_two(sizeof(rust_vec) + fill);
103-
void *mem = dom->malloc(alloc);
103+
void *mem = task->malloc(alloc, t->is_stateful ? t : NULL);
104104
if (!mem) {
105105
task->fail(3);
106106
return NULL;

src/rt/rust_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ struct type_desc {
274274
uintptr_t sever_glue_off; // For GC.
275275
uintptr_t mark_glue_off; // For GC.
276276
uintptr_t obj_drop_glue_off; // For custom destructors.
277+
uintptr_t is_stateful;
277278

278279
// Residual fields past here are known only to runtime.
279280
UT_hash_handle hh;

src/test/run-pass/vec-alloc-append.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std;
44

55
fn slice[T](vec[T] e) {
66
let vec[T] result = std._vec.alloc[T](uint(1));
7+
log "alloced";
78
result += e;
9+
log "appended";
810
}
911

1012
fn main() {

0 commit comments

Comments
 (0)