Skip to content

Commit 8c02adc

Browse files
committed
rustc: Port the fn and obj traversal logic over from the GC branch. Doesn't actually do anything yet due to lack of support in trans.
1 parent ad3b9c4 commit 8c02adc

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

src/rt/rust_cc.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,20 @@ irc::walk_variant(shape::tag_info &tinfo, uint32_t variant_id,
164164

165165
void
166166
irc::compute_ircs(rust_task *task, irc_map &ircs) {
167-
std::map<void *,type_desc *>::iterator begin(task->local_allocs.begin()),
168-
end(task->local_allocs.end());
167+
std::map<void *,const type_desc *>::iterator
168+
begin(task->local_allocs.begin()), end(task->local_allocs.end());
169169
while (begin != end) {
170170
uint8_t *p = reinterpret_cast<uint8_t *>(begin->first);
171171
p += sizeof(uintptr_t); // Skip over the reference count.
172172

173-
type_desc *tydesc = begin->second;
173+
const type_desc *tydesc = begin->second;
174174

175175
//DPRINT("determining internal ref counts: %p, tydesc=%p\n", p,
176176
//tydesc);
177177

178178
shape::arena arena;
179179
shape::type_param *params =
180-
shape::type_param::from_tydesc(tydesc, arena);
180+
shape::type_param::from_tydesc(&tydesc, arena);
181181
irc irc(task, true, tydesc->shape, params, tydesc->shape_tables, p,
182182
ircs);
183183
irc.walk();
@@ -197,8 +197,8 @@ irc::compute_ircs(rust_task *task, irc_map &ircs) {
197197

198198
void
199199
find_roots(rust_task *task, irc_map &ircs, std::vector<void *> &roots) {
200-
std::map<void *,type_desc *>::iterator begin(task->local_allocs.begin()),
201-
end(task->local_allocs.end());
200+
std::map<void *,const type_desc *>::iterator
201+
begin(task->local_allocs.begin()), end(task->local_allocs.end());
202202
while (begin != end) {
203203
void *alloc = begin->first;
204204
uintptr_t *ref_count_ptr = reinterpret_cast<uintptr_t *>(alloc);
@@ -376,13 +376,13 @@ mark::do_mark(rust_task *task, const std::vector<void *> &roots,
376376
uint8_t *p = reinterpret_cast<uint8_t *>(alloc);
377377
p += sizeof(uintptr_t); // Skip over the reference count.
378378

379-
type_desc *tydesc = task->local_allocs[*begin];
379+
const type_desc *tydesc = task->local_allocs[*begin];
380380

381381
//DPRINT("marking: %p, tydesc=%p\n", p, tydesc);
382382

383383
shape::arena arena;
384384
shape::type_param *params =
385-
shape::type_param::from_tydesc(tydesc, arena);
385+
shape::type_param::from_tydesc(&tydesc, arena);
386386

387387
#if 0
388388
shape::log log(task, true, tydesc->shape, params,
@@ -403,8 +403,8 @@ mark::do_mark(rust_task *task, const std::vector<void *> &roots,
403403

404404
void
405405
sweep(rust_task *task, const std::set<void *> &marked) {
406-
std::map<void *,type_desc *>::iterator begin(task->local_allocs.begin()),
407-
end(task->local_allocs.end());
406+
std::map<void *,const type_desc *>::iterator
407+
begin(task->local_allocs.begin()), end(task->local_allocs.end());
408408
while (begin != end) {
409409
void *alloc = begin->first;
410410
if (marked.find(alloc) == marked.end()) {

src/rt/rust_gc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ struct frame {
3838
struct root_info {
3939
intptr_t frame_offset;
4040
uintptr_t dynamic; // 0 = static, 1 = dynamic
41-
type_desc *tydesc;
41+
const type_desc *tydesc;
4242
};
4343

4444
struct root {
45-
type_desc *tydesc;
45+
const type_desc *tydesc;
4646
uint8_t *data;
4747

4848
root(const root_info &info, const frame &frame)
@@ -117,8 +117,8 @@ gc::mark(std::vector<root> &roots) {
117117
DPRINT("root: %p\n", ri->data);
118118

119119
shape::arena arena;
120-
shape::type_param *params = shape::type_param::from_tydesc(ri->tydesc,
121-
arena);
120+
shape::type_param *params =
121+
shape::type_param::from_tydesc(&ri->tydesc, arena);
122122
shape::log log(task, true, ri->tydesc->shape, params,
123123
ri->tydesc->shape_tables, ri->data, std::cerr);
124124
log.walk();

src/rt/rust_obstack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ rust_obstack::dump() const {
161161
while (b != e) {
162162
std::pair<const type_desc *,void *> data = *b;
163163
shape::arena arena;
164-
shape::type_param *params = shape::type_param::from_tydesc(data.first,
165-
arena);
164+
shape::type_param *params =
165+
shape::type_param::from_tydesc(&data.first, arena);
166166
shape::log log(task, true, data.first->shape, params,
167167
data.first->shape_tables,
168168
reinterpret_cast<uint8_t *>(data.second), std::cerr);

src/rt/rust_shape.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type_param::make(const type_desc **tydescs, unsigned n_tydescs,
3737
const type_desc *subtydesc = tydescs[i];
3838
ptrs[i].shape = subtydesc->shape;
3939
ptrs[i].tables = subtydesc->shape_tables;
40-
ptrs[i].params = from_tydesc(subtydesc, arena);
40+
ptrs[i].params = from_tydesc(&subtydesc, arena);
4141
}
4242
return ptrs;
4343
}
@@ -527,11 +527,12 @@ log::walk_res(const rust_fn *dtor, unsigned n_params,
527527
} // end namespace shape
528528

529529
extern "C" void
530-
upcall_cmp_type(int8_t *result, rust_task *task, type_desc *tydesc,
530+
upcall_cmp_type(int8_t *result, rust_task *task, const type_desc *tydesc,
531531
const type_desc **subtydescs, uint8_t *data_0,
532532
uint8_t *data_1, uint8_t cmp_type) {
533533
shape::arena arena;
534-
shape::type_param *params = shape::type_param::from_tydesc(tydesc, arena);
534+
shape::type_param *params =
535+
shape::type_param::from_tydesc(&tydesc, arena);
535536
shape::cmp cmp(task, true, tydesc->shape, params, tydesc->shape_tables,
536537
data_0, data_1);
537538
cmp.walk();
@@ -544,13 +545,14 @@ upcall_cmp_type(int8_t *result, rust_task *task, type_desc *tydesc,
544545
}
545546

546547
extern "C" void
547-
upcall_log_type(rust_task *task, type_desc *tydesc, uint8_t *data,
548+
upcall_log_type(rust_task *task, const type_desc *tydesc, uint8_t *data,
548549
uint32_t level) {
549550
if (task->sched->log_lvl < level)
550551
return; // TODO: Don't evaluate at all?
551552

552553
shape::arena arena;
553-
shape::type_param *params = shape::type_param::from_tydesc(tydesc, arena);
554+
shape::type_param *params =
555+
shape::type_param::from_tydesc(&tydesc, arena);
554556

555557
std::stringstream ss;
556558
shape::log log(task, true, tydesc->shape, params, tydesc->shape_tables,

src/rt/rust_shape.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,27 @@ class type_param {
310310
}
311311

312312
// Creates type parameters from a type descriptor.
313-
static inline type_param *from_tydesc(const type_desc *tydesc,
313+
static inline type_param *from_tydesc(const type_desc **tydesc,
314314
arena &arena) {
315-
if (tydesc->n_obj_params) {
316-
// TODO
315+
if ((*tydesc)->n_obj_params) {
316+
uintptr_t n_obj_params = (*tydesc)->n_obj_params;
317+
const type_desc **first_param;
318+
if (n_obj_params & 0x80000000) {
319+
// Function closure.
320+
DPRINT("n_obj_params FN %lu, tydesc %p, starting at %p\n",
321+
n_obj_params, tydesc, tydesc + 4);
322+
n_obj_params &= 0x7fffffff;
323+
first_param = (const type_desc **)
324+
((uint8_t *)(tydesc + 4) + (*tydesc)->size);
325+
} else {
326+
// Object closure.
327+
DPRINT("n_obj_params OBJ %lu, tydesc %p, starting at %p\n",
328+
n_obj_params, tydesc, tydesc + 4);
329+
first_param = tydesc + 4;
330+
}
317331
}
318-
return make(tydesc->first_param, tydesc->n_params, arena);
332+
333+
return make((*tydesc)->first_param, (*tydesc)->n_params, arena);
319334
}
320335
};
321336

src/rt/rust_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
115115

116116
rust_obstack dynastack;
117117

118-
std::map<void *,type_desc *> local_allocs;
118+
std::map<void *,const type_desc *> local_allocs;
119119

120120
// Only a pointer to 'name' is kept, so it must live as long as this task.
121121
rust_task(rust_scheduler *sched,

0 commit comments

Comments
 (0)