Skip to content

Commit c457660

Browse files
committed
---
yaml --- r: 13133 b: refs/heads/master c: 09a1b94 h: refs/heads/master i: 13131: 894542d v: v3
1 parent f905bf5 commit c457660

File tree

10 files changed

+202
-108
lines changed

10 files changed

+202
-108
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 846dfbc922b5b8c2c7de8da0cbb912bb89ff046e
2+
refs/heads/master: 09a1b949071cd573cd171362e9c3b894105556c1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rt/rust.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ command_line_args : public kernel_owned<command_line_args>
1313
char **argv;
1414

1515
// [str] passed to rust_task::start.
16-
rust_vec *args;
16+
rust_vec_box *args;
1717

1818
command_line_args(rust_task *task,
1919
int sys_argc,
@@ -47,7 +47,7 @@ command_line_args : public kernel_owned<command_line_args>
4747

4848
~command_line_args() {
4949
for (int i = 0; i < argc; ++i) {
50-
rust_vec *s = ((rust_vec**)&args->data)[i];
50+
rust_vec *s = ((rust_vec**)&args->body.data)[i];
5151
kernel->free(s);
5252
}
5353
kernel->free(args);

trunk/src/rt/rust_builtin.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ rust_getcwd() {
8585
}
8686

8787
#if defined(__WIN32__)
88-
extern "C" CDECL rust_vec *
88+
extern "C" CDECL rust_vec_box *
8989
rust_env_pairs() {
9090
rust_task *task = rust_get_current_task();
9191
size_t envc = 0;
@@ -102,7 +102,7 @@ rust_env_pairs() {
102102
for (size_t i = 0; i < envc; ++i) {
103103
size_t n = strlen(c);
104104
rust_str *str = make_str(task->kernel, c, n, "str");
105-
((rust_str**)&v->data)[i] = str;
105+
((rust_str**)&v->body.data)[i] = str;
106106
c += n + 1;
107107
}
108108
if (ch) {
@@ -111,7 +111,7 @@ rust_env_pairs() {
111111
return v;
112112
}
113113
#else
114-
extern "C" CDECL rust_vec *
114+
extern "C" CDECL rust_vec_box *
115115
rust_env_pairs() {
116116
rust_task *task = rust_get_current_task();
117117
#ifdef __APPLE__
@@ -140,14 +140,14 @@ unsupervise() {
140140
}
141141

142142
extern "C" CDECL void
143-
vec_reserve_shared(type_desc* ty, rust_vec** vp,
143+
vec_reserve_shared(type_desc* ty, rust_vec_box** vp,
144144
size_t n_elts) {
145145
rust_task *task = rust_get_current_task();
146146
reserve_vec_exact(task, vp, n_elts * ty->size);
147147
}
148148

149149
extern "C" CDECL void
150-
str_reserve_shared(rust_vec** sp,
150+
str_reserve_shared(rust_vec_box** sp,
151151
size_t n_elts) {
152152
rust_task *task = rust_get_current_task();
153153
reserve_vec_exact(task, sp, n_elts + 1);
@@ -169,13 +169,13 @@ vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) {
169169
}
170170

171171
extern "C" CDECL void
172-
rust_str_push(rust_vec** sp, uint8_t byte) {
172+
rust_str_push(rust_vec_box** sp, uint8_t byte) {
173173
rust_task *task = rust_get_current_task();
174-
size_t fill = (*sp)->fill;
174+
size_t fill = (*sp)->body.fill;
175175
reserve_vec(task, sp, fill + 1);
176-
(*sp)->data[fill-1] = byte;
177-
(*sp)->data[fill] = 0;
178-
(*sp)->fill = fill + 1;
176+
(*sp)->body.data[fill-1] = byte;
177+
(*sp)->body.data[fill] = 0;
178+
(*sp)->body.fill = fill + 1;
179179
}
180180

181181
extern "C" CDECL rust_vec*
@@ -373,7 +373,7 @@ rust_list_files(rust_str *path) {
373373
array_list<rust_str*> strings;
374374
#if defined(__WIN32__)
375375
WIN32_FIND_DATA FindFileData;
376-
HANDLE hFind = FindFirstFile((char*)path->data, &FindFileData);
376+
HANDLE hFind = FindFirstFile((char*)path->body.data, &FindFileData);
377377
if (hFind != INVALID_HANDLE_VALUE) {
378378
do {
379379
rust_str *str = make_str(task->kernel, FindFileData.cFileName,
@@ -384,13 +384,13 @@ rust_list_files(rust_str *path) {
384384
FindClose(hFind);
385385
}
386386
#else
387-
DIR *dirp = opendir((char*)path->data);
387+
DIR *dirp = opendir((char*)path->body.data);
388388
if (dirp) {
389389
struct dirent *dp;
390390
while ((dp = readdir(dirp))) {
391-
rust_vec *str = make_str(task->kernel, dp->d_name,
392-
strlen(dp->d_name),
393-
"list_files_str");
391+
rust_vec_box *str = make_str(task->kernel, dp->d_name,
392+
strlen(dp->d_name),
393+
"list_files_str");
394394
strings.push(str);
395395
}
396396
closedir(dirp);
@@ -520,9 +520,9 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
520520
if (zone != NULL) {
521521
size_t size = strlen(zone);
522522
str_reserve_shared(&out_tm->tm_zone, size);
523-
memcpy(out_tm->tm_zone->data, zone, size);
524-
out_tm->tm_zone->fill = size + 1;
525-
out_tm->tm_zone->data[size] = '\0';
523+
memcpy(out_tm->tm_zone->body.data, zone, size);
524+
out_tm->tm_zone->body.fill = size + 1;
525+
out_tm->tm_zone->body.data[size] = '\0';
526526
}
527527
}
528528

trunk/src/rt/rust_shape.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,9 @@ data<T,U>::walk_variant1(tag_info &tinfo, tag_variant_t variant_id) {
11101110
template<typename T,typename U>
11111111
std::pair<uint8_t *,uint8_t *>
11121112
data<T,U>::get_vec_data_range(ptr dp) {
1113-
rust_vec* ptr = bump_dp<rust_vec*>(dp);
1114-
uint8_t* data = &ptr->data[0];
1115-
return std::make_pair(data, data + ptr->fill);
1113+
rust_vec_box* ptr = bump_dp<rust_vec_box*>(dp);
1114+
uint8_t* data = &ptr->body.data[0];
1115+
return std::make_pair(data, data + ptr->body.fill);
11161116
}
11171117

11181118
template<typename T,typename U>

trunk/src/rt/rust_upcall.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,10 @@ upcall_s_str_new_shared(s_str_new_shared_args *args) {
445445
vec_size<char>(str_fill),
446446
"str_new_shared");
447447
rust_str *str = (rust_str *)box_body(args->retval);
448-
str->fill = str_fill;
449-
str->alloc = str_alloc;
450-
memcpy(&str->data, args->cstr, args->len);
451-
str->data[args->len] = '\0';
448+
str->body.fill = str_fill;
449+
str->body.alloc = str_alloc;
450+
memcpy(&str->body.data, args->cstr, args->len);
451+
str->body.data[args->len] = '\0';
452452
}
453453

454454
extern "C" CDECL rust_opaque_box*
@@ -460,7 +460,7 @@ upcall_str_new_shared(const char *cstr, size_t len) {
460460

461461

462462
struct s_vec_grow_args {
463-
rust_vec** vp;
463+
rust_vec_box** vp;
464464
size_t new_sz;
465465
};
466466

@@ -469,37 +469,38 @@ upcall_s_vec_grow(s_vec_grow_args *args) {
469469
rust_task *task = rust_get_current_task();
470470
LOG_UPCALL_ENTRY(task);
471471
reserve_vec(task, args->vp, args->new_sz);
472-
(*args->vp)->fill = args->new_sz;
472+
(*args->vp)->body.fill = args->new_sz;
473473
}
474474

475475
extern "C" CDECL void
476-
upcall_vec_grow(rust_vec** vp, size_t new_sz) {
476+
upcall_vec_grow(rust_vec_box** vp, size_t new_sz) {
477477
s_vec_grow_args args = {vp, new_sz};
478478
UPCALL_SWITCH_STACK(&args, upcall_s_vec_grow);
479479
}
480480

481481
struct s_str_concat_args {
482-
rust_vec* lhs;
483-
rust_vec* rhs;
484-
rust_vec* retval;
482+
rust_vec_box* lhs;
483+
rust_vec_box* rhs;
484+
rust_vec_box* retval;
485485
};
486486

487487
extern "C" CDECL void
488488
upcall_s_str_concat(s_str_concat_args *args) {
489-
rust_vec *lhs = args->lhs;
490-
rust_vec *rhs = args->rhs;
489+
rust_vec *lhs = &args->lhs->body;
490+
rust_vec *rhs = &args->rhs->body;
491491
rust_task *task = rust_get_current_task();
492492
size_t fill = lhs->fill + rhs->fill - 1;
493-
rust_vec* v = (rust_vec*)task->kernel->malloc(fill + sizeof(rust_vec),
494-
"str_concat");
495-
v->fill = v->alloc = fill;
496-
memmove(&v->data[0], &lhs->data[0], lhs->fill - 1);
497-
memmove(&v->data[lhs->fill - 1], &rhs->data[0], rhs->fill);
493+
rust_vec_box* v = (rust_vec_box*)
494+
task->kernel->malloc(fill + sizeof(rust_vec_box),
495+
"str_concat");
496+
v->body.fill = v->body.alloc = fill;
497+
memmove(&v->body.data[0], &lhs->data[0], lhs->fill - 1);
498+
memmove(&v->body.data[lhs->fill - 1], &rhs->data[0], rhs->fill);
498499
args->retval = v;
499500
}
500501

501-
extern "C" CDECL rust_vec*
502-
upcall_str_concat(rust_vec* lhs, rust_vec* rhs) {
502+
extern "C" CDECL rust_vec_box*
503+
upcall_str_concat(rust_vec_box* lhs, rust_vec_box* rhs) {
503504
s_str_concat_args args = {lhs, rhs, 0};
504505
UPCALL_SWITCH_STACK(&args, upcall_s_str_concat);
505506
return args.retval;

trunk/src/rt/rust_util.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,16 @@ rust_vec
4242
uint8_t data[0];
4343
};
4444

45+
struct
46+
rust_vec_box
47+
{
48+
rust_opaque_box header;
49+
rust_vec body;
50+
};
51+
4552
template <typename T>
4653
inline size_t vec_size(size_t elems) {
47-
return sizeof(rust_vec) + sizeof(T) * elems;
54+
return sizeof(rust_vec_box) + sizeof(T) * elems;
4855
}
4956

5057
template <typename T>
@@ -53,19 +60,20 @@ vec_data(rust_vec *v) {
5360
return reinterpret_cast<T*>(v->data);
5461
}
5562

56-
inline void reserve_vec_exact(rust_task* task, rust_vec** vpp, size_t size) {
57-
if (size > (*vpp)->alloc) {
58-
*vpp = (rust_vec*)task->kernel
59-
->realloc(*vpp, size + sizeof(rust_vec));
60-
(*vpp)->alloc = size;
63+
inline void reserve_vec_exact(rust_task* task, rust_vec_box** vpp,
64+
size_t size) {
65+
if (size > (*vpp)->body.alloc) {
66+
*vpp = (rust_vec_box*)task->kernel
67+
->realloc(*vpp, size + sizeof(rust_vec_box));
68+
(*vpp)->body.alloc = size;
6169
}
6270
}
6371

64-
inline void reserve_vec(rust_task* task, rust_vec** vpp, size_t size) {
72+
inline void reserve_vec(rust_task* task, rust_vec_box** vpp, size_t size) {
6573
reserve_vec_exact(task, vpp, next_power_of_two(size));
6674
}
6775

68-
typedef rust_vec rust_str;
76+
typedef rust_vec_box rust_str;
6977

7078
inline rust_str *
7179
make_str(rust_kernel* kernel, const char* c, size_t strlen,
@@ -74,24 +82,24 @@ make_str(rust_kernel* kernel, const char* c, size_t strlen,
7482
size_t str_alloc = str_fill;
7583
rust_str *str = (rust_str *)
7684
kernel->malloc(vec_size<char>(str_fill), name);
77-
str->fill = str_fill;
78-
str->alloc = str_alloc;
79-
memcpy(&str->data, c, strlen);
80-
str->data[strlen] = '\0';
85+
str->body.fill = str_fill;
86+
str->body.alloc = str_alloc;
87+
memcpy(&str->body.data, c, strlen);
88+
str->body.data[strlen] = '\0';
8189
return str;
8290
}
8391

84-
inline rust_vec *
92+
inline rust_vec_box *
8593
make_str_vec(rust_kernel* kernel, size_t nstrs, char **strs) {
86-
rust_vec *v = (rust_vec *)
87-
kernel->malloc(vec_size<rust_vec*>(nstrs),
94+
rust_vec_box *v = (rust_vec_box *)
95+
kernel->malloc(vec_size<rust_vec_box*>(nstrs),
8896
"str vec interior");
89-
v->fill = v->alloc = sizeof(rust_vec*) * nstrs;
97+
v->body.fill = v->body.alloc = sizeof(rust_vec_box*) * nstrs;
9098
for (size_t i = 0; i < nstrs; ++i) {
9199
rust_str *str = make_str(kernel, strs[i],
92100
strlen(strs[i]),
93101
"str");
94-
((rust_str**)&v->data)[i] = str;
102+
((rust_str**)&v->body.data)[i] = str;
95103
}
96104
return v;
97105
}

trunk/src/rustc/back/upcall.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import driver::session;
33
import middle::trans::base;
44
import middle::trans::common::{T_fn, T_i1, T_i8, T_i32,
55
T_int, T_nil,
6-
T_opaque_vec, T_ptr,
7-
T_size_t, T_void};
6+
T_opaque_vec, T_ptr, T_unique_ptr,
7+
T_size_t, T_void, T_vec2};
88
import lib::llvm::{type_names, ModuleRef, ValueRef, TypeRef};
99

1010
type upcalls =
@@ -13,6 +13,7 @@ type upcalls =
1313
malloc: ValueRef,
1414
free: ValueRef,
1515
exchange_malloc: ValueRef,
16+
exchange_malloc_dyn: ValueRef,
1617
exchange_free: ValueRef,
1718
validate_box: ValueRef,
1819
shared_malloc: ValueRef,
@@ -51,7 +52,6 @@ fn declare_upcalls(targ_cfg: @session::config,
5152

5253
let int_t = T_int(targ_cfg);
5354
let size_t = T_size_t(targ_cfg);
54-
let opaque_vec_t = T_opaque_vec(targ_cfg);
5555

5656
ret @{_fail: dv("fail", [T_ptr(T_i8()),
5757
T_ptr(T_i8()),
@@ -67,6 +67,10 @@ fn declare_upcalls(targ_cfg: @session::config,
6767
exchange_malloc:
6868
nothrow(d("exchange_malloc", [T_ptr(tydesc_type)],
6969
T_ptr(T_i8()))),
70+
exchange_malloc_dyn:
71+
nothrow(d("exchange_malloc_dyn",
72+
[T_ptr(tydesc_type), int_t],
73+
T_ptr(T_i8()))),
7074
exchange_free:
7175
nothrow(dv("exchange_free", [T_ptr(T_i8())])),
7276
validate_box:
@@ -81,17 +85,17 @@ fn declare_upcalls(targ_cfg: @session::config,
8185
mark:
8286
d("mark", [T_ptr(T_i8())], int_t),
8387
vec_grow:
84-
nothrow(dv("vec_grow", [T_ptr(T_ptr(opaque_vec_t)), int_t])),
88+
nothrow(dv("vec_grow", [T_ptr(T_ptr(T_i8())), int_t])),
8589
str_new_uniq:
8690
nothrow(d("str_new_uniq", [T_ptr(T_i8()), int_t],
87-
T_ptr(opaque_vec_t))),
91+
T_ptr(T_i8()))),
8892
str_new_shared:
8993
nothrow(d("str_new_shared", [T_ptr(T_i8()), int_t],
9094
T_ptr(T_i8()))),
9195
str_concat:
92-
nothrow(d("str_concat", [T_ptr(opaque_vec_t),
93-
T_ptr(opaque_vec_t)],
94-
T_ptr(opaque_vec_t))),
96+
nothrow(d("str_concat", [T_ptr(T_i8()),
97+
T_ptr(T_i8())],
98+
T_ptr(T_i8()))),
9599
cmp_type:
96100
dv("cmp_type",
97101
[T_ptr(T_i1()), T_ptr(tydesc_type),

0 commit comments

Comments
 (0)