Skip to content

Commit 41b02b7

Browse files
committed
Merge remote-tracking branch 'brson/self-describing-uniques'
Conflicts: src/snapshots.txt
2 parents 615f532 + 3a2c92b commit 41b02b7

21 files changed

+495
-298
lines changed

mk/host.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_STDLIB): \
7474
@$$(call E, cp: $$@)
7575
$$(Q)cp $$< $$@
7676
$$(Q)cp -R $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_GLOB) \
77-
$$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_DSYM_GLOB) \
77+
$$(wildcard $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_DSYM_GLOB)) \
7878
$$(HLIB$(2)_H_$(4))
7979

8080
$$(HLIB$(2)_H_$(4))/libcore.rlib: \

mk/target.mk

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
# (resp. corelib), set this flag to 1. It will cause stage1 to use
99
# the snapshot runtime (resp. corelib) rather than the runtime
1010
# (resp. corelib) from the working directory.
11-
USE_SNAPSHOT_RUNTIME=0
12-
USE_SNAPSHOT_CORELIB=0
11+
USE_SNAPSHOT_RUNTIME=1
12+
USE_SNAPSHOT_CORELIB=1
13+
USE_SNAPSHOT_STDLIB=1
1314

1415
define TARGET_STAGE_N
1516

@@ -18,13 +19,6 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a: \
1819
@$$(call E, cp: $$@)
1920
$$(Q)cp $$< $$@
2021

21-
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \
22-
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
23-
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
24-
$$(TSREQ$(1)_T_$(2)_H_$(3))
25-
@$$(call E, compile_and_link: $$@)
26-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
27-
2822
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM): \
2923
rustllvm/$(2)/$$(CFG_RUSTLLVM)
3024
@$$(call E, cp: $$@)
@@ -116,6 +110,30 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \
116110

117111
endef
118112

113+
define TARGET_STDLIB_FROM_SNAPSHOT
114+
115+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \
116+
$$(HLIB$(1)_H_$(3))/$$(CFG_STDLIB) \
117+
$$(STDLIB_INPUTS) \
118+
$$(TSREQ$(1)_T_$(2)_H_$(3))
119+
@$$(call E, cp: $$@)
120+
$$(Q)cp $$< $$@
121+
$$(Q)cp $$(HLIB$(1)_H_$(3))/$$(STDLIB_GLOB) \
122+
$$(TLIB$(1)_T_$(2)_H_$(3))
123+
124+
endef
125+
126+
define TARGET_STDLIB_FROM_WD
127+
128+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \
129+
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
130+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
131+
$$(TSREQ$(1)_T_$(2)_H_$(3))
132+
@$$(call E, compile_and_link: $$@)
133+
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
134+
135+
endef
136+
119137
# In principle, each host can build each target:
120138
$(foreach source,$(CFG_TARGET_TRIPLES), \
121139
$(foreach target,$(CFG_TARGET_TRIPLES), \
@@ -142,11 +160,20 @@ else
142160
$(eval $(call TARGET_CORELIB_FROM_WD,0,$(src),$(src))))
143161
endif
144162

163+
ifeq ($(USE_SNAPSHOT_STDLIB),1)
164+
$(foreach src,$(CFG_HOST_TRIPLE),\
165+
$(eval $(call TARGET_STDLIB_FROM_SNAPSHOT,0,$(src),$(src))))
166+
else
167+
$(foreach src,$(CFG_HOST_TRIPLE),\
168+
$(eval $(call TARGET_STDLIB_FROM_WD,0,$(src),$(src))))
169+
endif
170+
145171
# Non-host triples build the stage0 runtime from the working directory
146172
$(foreach source,$(CFG_TARGET_TRIPLES), \
147173
$(foreach target,$(NON_HOST_TRIPLES), \
148174
$(eval $(call TARGET_RT_FROM_WD,0,$(target),$(source))) \
149175
$(eval $(call TARGET_CORELIB_FROM_WD,0,$(target),$(source))) \
176+
$(eval $(call TARGET_STDLIB_FROM_WD,0,$(target),$(source))) \
150177
))
151178

152179
# After stage0, always build the stage0 runtime from the working directory
@@ -158,5 +185,8 @@ $(foreach source,$(CFG_TARGET_TRIPLES), \
158185
$(eval $(call TARGET_CORELIB_FROM_WD,1,$(target),$(source))) \
159186
$(eval $(call TARGET_CORELIB_FROM_WD,2,$(target),$(source))) \
160187
$(eval $(call TARGET_CORELIB_FROM_WD,3,$(target),$(source))) \
188+
$(eval $(call TARGET_STDLIB_FROM_WD,1,$(target),$(source))) \
189+
$(eval $(call TARGET_STDLIB_FROM_WD,2,$(target),$(source))) \
190+
$(eval $(call TARGET_STDLIB_FROM_WD,3,$(target),$(source))) \
161191
))
162192

src/libcore/vec.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,12 @@ impl extensions<T> for [T] {
11621162
mod unsafe {
11631163
// FIXME: This should have crate visibility (#1893 blocks that)
11641164
#[doc = "The internal representation of a vector"]
1165-
type vec_repr = {mut fill: uint, mut alloc: uint, data: u8};
1165+
type vec_repr = {
1166+
box_header: (uint, uint, uint, uint),
1167+
mut fill: uint,
1168+
mut alloc: uint,
1169+
data: u8
1170+
};
11661171

11671172
#[doc = "
11681173
Constructs a vector from an unsafe pointer to a buffer

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);

src/rt/rust_builtin.cpp

Lines changed: 32 additions & 31 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;
@@ -95,14 +95,14 @@ rust_env_pairs() {
9595
++envc;
9696
}
9797
c = ch;
98-
rust_vec *v = (rust_vec *)
99-
task->kernel->malloc(vec_size<rust_vec*>(envc),
98+
rust_vec_box *v = (rust_vec_box *)
99+
task->kernel->malloc(vec_size<rust_vec_box*>(envc),
100100
"str vec interior");
101-
v->fill = v->alloc = sizeof(rust_vec*) * envc;
101+
v->body.fill = v->body.alloc = sizeof(rust_vec*) * envc;
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);
@@ -157,25 +157,26 @@ str_reserve_shared(rust_vec** sp,
157157
* Copies elements in an unsafe buffer to the given interior vector. The
158158
* vector must have size zero.
159159
*/
160-
extern "C" CDECL rust_vec*
160+
extern "C" CDECL rust_vec_box*
161161
vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) {
162162
rust_task *task = rust_get_current_task();
163163
size_t fill = ty->size * count;
164-
rust_vec* v = (rust_vec*)task->kernel->malloc(fill + sizeof(rust_vec),
165-
"vec_from_buf");
166-
v->fill = v->alloc = fill;
167-
memmove(&v->data[0], ptr, fill);
164+
rust_vec_box* v = (rust_vec_box*)
165+
task->kernel->malloc(fill + sizeof(rust_vec_box),
166+
"vec_from_buf");
167+
v->body.fill = v->body.alloc = fill;
168+
memmove(&v->body.data[0], ptr, fill);
168169
return v;
169170
}
170171

171172
extern "C" CDECL void
172-
rust_str_push(rust_vec** sp, uint8_t byte) {
173+
rust_str_push(rust_vec_box** sp, uint8_t byte) {
173174
rust_task *task = rust_get_current_task();
174-
size_t fill = (*sp)->fill;
175+
size_t fill = (*sp)->body.fill;
175176
reserve_vec(task, sp, fill + 1);
176-
(*sp)->data[fill-1] = byte;
177-
(*sp)->data[fill] = 0;
178-
(*sp)->fill = fill + 1;
177+
(*sp)->body.data[fill-1] = byte;
178+
(*sp)->body.data[fill] = 0;
179+
(*sp)->body.fill = fill + 1;
179180
}
180181

181182
extern "C" CDECL rust_vec*
@@ -367,13 +368,13 @@ debug_get_stk_seg() {
367368
return task->stk;
368369
}
369370

370-
extern "C" CDECL rust_vec*
371+
extern "C" CDECL rust_vec_box*
371372
rust_list_files(rust_str *path) {
372373
rust_task *task = rust_get_current_task();
373374
array_list<rust_str*> strings;
374375
#if defined(__WIN32__)
375376
WIN32_FIND_DATA FindFileData;
376-
HANDLE hFind = FindFirstFile((char*)path->data, &FindFileData);
377+
HANDLE hFind = FindFirstFile((char*)path->body.data, &FindFileData);
377378
if (hFind != INVALID_HANDLE_VALUE) {
378379
do {
379380
rust_str *str = make_str(task->kernel, FindFileData.cFileName,
@@ -384,25 +385,25 @@ rust_list_files(rust_str *path) {
384385
FindClose(hFind);
385386
}
386387
#else
387-
DIR *dirp = opendir((char*)path->data);
388+
DIR *dirp = opendir((char*)path->body.data);
388389
if (dirp) {
389390
struct dirent *dp;
390391
while ((dp = readdir(dirp))) {
391-
rust_vec *str = make_str(task->kernel, dp->d_name,
392-
strlen(dp->d_name),
393-
"list_files_str");
392+
rust_vec_box *str = make_str(task->kernel, dp->d_name,
393+
strlen(dp->d_name),
394+
"list_files_str");
394395
strings.push(str);
395396
}
396397
closedir(dirp);
397398
}
398399
#endif
399400

400-
rust_vec *vec = (rust_vec *)
401-
task->kernel->malloc(vec_size<rust_vec*>(strings.size()),
401+
rust_vec_box *vec = (rust_vec_box *)
402+
task->kernel->malloc(vec_size<rust_vec_box*>(strings.size()),
402403
"list_files_vec");
403404
size_t alloc_sz = sizeof(rust_vec*) * strings.size();
404-
vec->fill = vec->alloc = alloc_sz;
405-
memcpy(&vec->data[0], strings.data(), alloc_sz);
405+
vec->body.fill = vec->body.alloc = alloc_sz;
406+
memcpy(&vec->body.data[0], strings.data(), alloc_sz);
406407
return vec;
407408
}
408409

@@ -520,9 +521,9 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
520521
if (zone != NULL) {
521522
size_t size = strlen(zone);
522523
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';
524+
memcpy(out_tm->tm_zone->body.data, zone, size);
525+
out_tm->tm_zone->body.fill = size + 1;
526+
out_tm->tm_zone->body.data[size] = '\0';
526527
}
527528
}
528529

src/rt/rust_cc.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ class irc : public shape::data<irc,shape::ptr> {
117117
}
118118

119119
void walk_uniq2() {
120-
shape::data<irc,shape::ptr>::walk_uniq_contents1();
120+
rust_opaque_box *box = *(rust_opaque_box**)dp;
121+
if (box)
122+
shape::data<irc,shape::ptr>::walk_uniq_contents1();
121123
}
122124

123125
void walk_rptr2() {
@@ -373,7 +375,9 @@ class mark : public shape::data<mark,shape::ptr> {
373375
}
374376

375377
void walk_uniq2() {
376-
shape::data<mark,shape::ptr>::walk_uniq_contents1();
378+
rust_opaque_box *box = *(rust_opaque_box**)dp;
379+
if (box)
380+
shape::data<mark,shape::ptr>::walk_uniq_contents1();
377381
}
378382

379383
void walk_rptr2() {

src/rt/rust_shape.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ class ptr {
783783
return box->td;
784784
}
785785

786+
inline const type_desc *uniq_body_td() const {
787+
rust_opaque_box *box = *reinterpret_cast<rust_opaque_box**>(p);
788+
return box->td;
789+
}
790+
786791
inline ptr box_body() const {
787792
rust_opaque_box *box = *reinterpret_cast<rust_opaque_box**>(p);
788793
return make((uint8_t*)::box_body(box));
@@ -881,6 +886,11 @@ class ptr_pair {
881886
return box_fst->td;
882887
}
883888

889+
inline const type_desc *uniq_body_td() const {
890+
rust_opaque_box *box_fst = *reinterpret_cast<rust_opaque_box**>(fst);
891+
return box_fst->td;
892+
}
893+
884894
inline ptr_pair box_body() const {
885895
rust_opaque_box *box_fst = *reinterpret_cast<rust_opaque_box**>(fst);
886896
rust_opaque_box *box_snd = *reinterpret_cast<rust_opaque_box**>(snd);
@@ -1067,10 +1077,16 @@ data<T,U>::walk_box_contents1() {
10671077
template<typename T,typename U>
10681078
void
10691079
data<T,U>::walk_uniq_contents1() {
1070-
typename U::template data<uint8_t *>::t box_ptr = bump_dp<uint8_t *>(dp);
1071-
U data_ptr(box_ptr);
1072-
T sub(*static_cast<T *>(this), data_ptr);
1073-
static_cast<T *>(this)->walk_uniq_contents2(sub);
1080+
const type_desc *body_td = dp.uniq_body_td();
1081+
if (body_td) {
1082+
U body_dp(dp.box_body());
1083+
arena arena;
1084+
type_param *params = type_param::from_tydesc(body_td, arena);
1085+
T sub(*static_cast<T *>(this), body_td->shape, params,
1086+
body_td->shape_tables, body_dp);
1087+
sub.align = true;
1088+
static_cast<T *>(this)->walk_uniq_contents2(sub);
1089+
}
10741090
}
10751091

10761092
template<typename T,typename U>
@@ -1094,9 +1110,9 @@ data<T,U>::walk_variant1(tag_info &tinfo, tag_variant_t variant_id) {
10941110
template<typename T,typename U>
10951111
std::pair<uint8_t *,uint8_t *>
10961112
data<T,U>::get_vec_data_range(ptr dp) {
1097-
rust_vec* ptr = bump_dp<rust_vec*>(dp);
1098-
uint8_t* data = &ptr->data[0];
1099-
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);
11001116
}
11011117

11021118
template<typename T,typename U>

src/rt/rust_task.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include "rust_task.h"
99
#include "rust_cc.h"
10-
#include "rust_upcall.h"
1110
#include "rust_env.h"
1211
#include "rust_port.h"
1312

@@ -130,6 +129,8 @@ cleanup_task(cleanup_args *args) {
130129
}
131130
}
132131

132+
extern "C" CDECL void upcall_exchange_free(void *ptr);
133+
133134
// This runs on the Rust stack
134135
void task_start_wrapper(spawn_args *a)
135136
{
@@ -161,7 +162,7 @@ void task_start_wrapper(spawn_args *a)
161162
// free the environment (which should be a unique closure).
162163
const type_desc *td = env->td;
163164
td->drop_glue(NULL, NULL, td->first_param, box_body(env));
164-
upcall_shared_free(env);
165+
upcall_exchange_free(env);
165166
}
166167

167168
// The cleanup work needs lots of stack

0 commit comments

Comments
 (0)