Skip to content

Commit f06f68d

Browse files
committed
auto merge of #4915 : luqmana/rust/rt-cleanup, r=pcwalton
Closes #1190. Also, got rid of `rust_ptr_eq` since it isn't used any as well the `RUST_REFCOUNTED` macros. Fixes #2667: alignment & wrong structure.
2 parents 6366e74 + 2c19856 commit f06f68d

File tree

4 files changed

+13
-40
lines changed

4 files changed

+13
-40
lines changed

src/rt/rust_builtin.cpp

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -241,32 +241,26 @@ debug_opaque(type_desc *t, uint8_t *front) {
241241
rust_task *task = rust_get_current_task();
242242
LOG(task, stdlib, "debug_opaque");
243243
debug_tydesc_helper(t);
244-
// FIXME (#2667) may want to actually account for alignment.
245-
// `front` may not indeed be the front byte of the passed-in
246-
// argument.
244+
// Account for alignment. `front` may not indeed be the
245+
// front byte of the passed-in argument
246+
if (((uintptr_t)front % t->align) != 0) {
247+
front = (uint8_t *)align_to((uintptr_t)front, (size_t)t->align);
248+
}
247249
for (uintptr_t i = 0; i < t->size; ++front, ++i) {
248250
LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, *front);
249251
}
250252
}
251253

252-
// FIXME (#2667) this no longer reflects the actual structure of boxes!
253-
struct rust_box {
254-
RUST_REFCOUNTED(rust_box)
255-
256-
// FIXME (#2667) `data` could be aligned differently from the actual
257-
// box body data
258-
uint8_t data[];
259-
};
260-
261254
extern "C" CDECL void
262-
debug_box(type_desc *t, rust_box *box) {
255+
debug_box(type_desc *t, rust_opaque_box *box) {
263256
rust_task *task = rust_get_current_task();
264257
LOG(task, stdlib, "debug_box(0x%" PRIxPTR ")", box);
265258
debug_tydesc_helper(t);
266259
LOG(task, stdlib, " refcount %" PRIdPTR,
267260
box->ref_count - 1); // -1 because we ref'ed for this call
261+
uint8_t *data = (uint8_t *)box_body(box);
268262
for (uintptr_t i = 0; i < t->size; ++i) {
269-
LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, box->data[i]);
263+
LOG(task, stdlib, " byte %" PRIdPTR ": 0x%" PRIx8, i, data[i]);
270264
}
271265
}
272266

@@ -288,20 +282,15 @@ debug_tag(type_desc *t, rust_tag *tag) {
288282
tag->variant[i]);
289283
}
290284

291-
struct rust_fn {
292-
uintptr_t *thunk;
293-
rust_box *closure;
294-
};
295-
296285
extern "C" CDECL void
297-
debug_fn(type_desc *t, rust_fn *fn) {
286+
debug_fn(type_desc *t, fn_env_pair *fn) {
298287
rust_task *task = rust_get_current_task();
299288
LOG(task, stdlib, "debug_fn");
300289
debug_tydesc_helper(t);
301-
LOG(task, stdlib, " thunk at 0x%" PRIxPTR, fn->thunk);
302-
LOG(task, stdlib, " closure at 0x%" PRIxPTR, fn->closure);
303-
if (fn->closure) {
304-
LOG(task, stdlib, " refcount %" PRIdPTR, fn->closure->ref_count);
290+
LOG(task, stdlib, " fn at 0x%" PRIxPTR, fn->f);
291+
LOG(task, stdlib, " env at 0x%" PRIxPTR, fn->env);
292+
if (fn->env) {
293+
LOG(task, stdlib, " refcount %" PRIdPTR, fn->env->ref_count);
305294
}
306295
}
307296

@@ -389,11 +378,6 @@ extern "C" CDECL FILE* rust_get_stdin() {return stdin;}
389378
extern "C" CDECL FILE* rust_get_stdout() {return stdout;}
390379
extern "C" CDECL FILE* rust_get_stderr() {return stderr;}
391380

392-
extern "C" CDECL int
393-
rust_ptr_eq(type_desc *t, rust_box *a, rust_box *b) {
394-
return a == b;
395-
}
396-
397381
#if defined(__WIN32__)
398382
extern "C" CDECL void
399383
get_time(int64_t *sec, int32_t *nsec) {

src/rt/rust_refcount.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@
1717
// Refcounting defines
1818
typedef unsigned long ref_cnt_t;
1919

20-
#define RUST_REFCOUNTED(T) \
21-
RUST_REFCOUNTED_WITH_DTOR(T, delete (T*)this)
22-
23-
#define RUST_REFCOUNTED_WITH_DTOR(T, dtor) \
24-
intptr_t ref_count; \
25-
void ref() { ++ref_count; } \
26-
void deref() { if (--ref_count == 0) { dtor; } }
27-
2820
#define RUST_ATOMIC_REFCOUNT() \
2921
private: \
3022
intptr_t ref_count; \

src/rt/rust_task.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@
168168
#define RED_ZONE_SIZE RZ_MAC_32
169169
#endif
170170

171-
struct rust_box;
172-
173171
struct frame_glue_fns {
174172
uintptr_t mark_glue_off;
175173
uintptr_t drop_glue_off;

src/rt/rustrt.def.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ rust_list_files2
3939
rust_log_console_on
4040
rust_log_console_off
4141
rust_process_wait
42-
rust_ptr_eq
4342
rust_run_program
4443
rust_sched_current_nonlazy_threads
4544
rust_sched_threads

0 commit comments

Comments
 (0)