Skip to content

Commit c856e26

Browse files
committed
---
yaml --- r: 4925 b: refs/heads/master c: 72d78e6 h: refs/heads/master i: 4923: 15101eb v: v3
1 parent 18f337b commit c856e26

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0dc1d7ee57bed7f0bd54e0369633fc09e200bbd6
2+
refs/heads/master: 72d78e6a93829703f64bd59f502410bebe64ae91

trunk/src/rt/rust_gc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ gc::mark(std::vector<root> &roots) {
119119
DPRINT("root: %p\n", ri->data);
120120

121121
shape::arena arena;
122-
shape::type_param *params = shape::type_param::make(ri->tydesc,
123-
arena);
122+
shape::type_param *params = shape::type_param::from_tydesc(ri->tydesc,
123+
arena);
124124
shape::log log(task, ri->tydesc->shape, params,
125125
ri->tydesc->shape_tables, ri->data, std::cerr);
126126
log.walk(true);

trunk/src/rt/rust_shape.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,37 @@ namespace shape {
1717

1818
using namespace shape;
1919

20-
// Forward declarations
21-
22-
struct rust_obj;
23-
struct size_align;
24-
struct type_param;
25-
26-
2720
// Constants
2821

2922
const uint8_t CMP_EQ = 0u;
3023
const uint8_t CMP_LT = 1u;
3124
const uint8_t CMP_LE = 2u;
3225

33-
} // end namespace shape
3426

27+
// Type parameters
28+
29+
type_param *
30+
type_param::make(const type_desc **tydescs, unsigned n_tydescs,
31+
arena &arena) {
32+
if (!n_tydescs)
33+
return NULL;
34+
35+
type_param *ptrs = arena.alloc<type_param>(n_tydescs);
36+
for (uint32_t i = 0; i < n_tydescs; i++) {
37+
const type_desc *subtydesc = tydescs[i];
38+
ptrs[i].shape = subtydesc->shape;
39+
ptrs[i].tables = subtydesc->shape_tables;
40+
ptrs[i].params = from_tydesc(subtydesc, arena);
41+
}
42+
return ptrs;
43+
}
44+
45+
type_param *
46+
type_param::from_obj_shape(const uint8_t *sp, arena &arena) {
47+
// TODO
48+
abort();
49+
}
3550

36-
namespace shape {
3751

3852
// A shape printer, useful for debugging
3953

@@ -469,7 +483,7 @@ upcall_cmp_type(int8_t *result, rust_task *task, type_desc *tydesc,
469483
const type_desc **subtydescs, uint8_t *data_0,
470484
uint8_t *data_1, uint8_t cmp_type) {
471485
shape::arena arena;
472-
shape::type_param *params = shape::type_param::make(tydesc, arena);
486+
shape::type_param *params = shape::type_param::from_tydesc(tydesc, arena);
473487
shape::cmp cmp(task, tydesc->shape, params, tydesc->shape_tables, data_0,
474488
data_1);
475489
cmp.walk(true);
@@ -488,7 +502,7 @@ upcall_log_type(rust_task *task, type_desc *tydesc, uint8_t *data,
488502
return; // TODO: Don't evaluate at all?
489503

490504
shape::arena arena;
491-
shape::type_param *params = shape::type_param::make(tydesc, arena);
505+
shape::type_param *params = shape::type_param::from_tydesc(tydesc, arena);
492506

493507
std::stringstream ss;
494508
shape::log log(task, tydesc->shape, params, tydesc->shape_tables, data,

trunk/src/rt/rust_shape.h

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const uint8_t SHAPE_VAR = 21u;
5151

5252
struct rust_obj;
5353
struct size_align;
54-
struct type_param;
54+
class type_param;
5555

5656

5757
// Arenas; these functions must execute very quickly, so we use an arena
@@ -215,10 +215,18 @@ struct rust_obj {
215215

216216
// Type parameters
217217

218-
struct type_param {
218+
class type_param {
219+
private:
220+
static type_param *make(const type_desc **tydescs, unsigned n_tydescs,
221+
arena &arena);
222+
223+
public:
219224
const uint8_t *shape;
220225
const rust_shape_tables *tables;
221-
const struct type_param *params; // subparameters
226+
const type_param *params; // subparameters
227+
228+
// Creates type parameters from an object shape description.
229+
static type_param *from_obj_shape(const uint8_t *sp, arena &arena);
222230

223231
template<typename T>
224232
inline void set(ctxt<T> *cx) {
@@ -227,19 +235,10 @@ struct type_param {
227235
params = cx->params;
228236
}
229237

230-
static type_param *make(const type_desc *tydesc, arena &arena) {
231-
uint32_t n_params = tydesc->n_params;
232-
if (!n_params)
233-
return NULL;
234-
235-
type_param *ptrs = arena.alloc<type_param>(n_params);
236-
for (uint32_t i = 0; i < n_params; i++) {
237-
const type_desc *subtydesc = tydesc->first_param[i];
238-
ptrs[i].shape = subtydesc->shape;
239-
ptrs[i].tables = subtydesc->shape_tables;
240-
ptrs[i].params = make(subtydesc, arena);
241-
}
242-
return ptrs;
238+
// Creates type parameters from a type descriptor.
239+
static inline type_param *from_tydesc(const type_desc *tydesc,
240+
arena &arena) {
241+
return make(tydesc->first_param, tydesc->n_params, arena);
243242
}
244243
};
245244

@@ -483,6 +482,7 @@ class print : public ctxt<print> {
483482
}
484483
};
485484

485+
486486
//
487487
// Size-of (which also computes alignment). Be warned: this is an expensive
488488
// operation.
@@ -892,12 +892,17 @@ data<T,U>::walk_obj_contents(bool align, ptr &dp) {
892892
uint8_t *box_ptr = bump_dp<uint8_t *>(dp);
893893
type_desc *subtydesc =
894894
*reinterpret_cast<type_desc **>(box_ptr + sizeof(void *));
895-
ptr obj_closure_dp(box_ptr + sizeof(void *));
895+
ptr obj_closure_dp(*box_ptr + sizeof(void *));
896896

897+
// FIXME: Should be type_param::from_obj_shape() below.
897898
arena arena;
898-
type_param *params = type_param::make(subtydesc, arena);
899+
type_param *params = type_param::from_tydesc(subtydesc, arena);
899900
T sub(*static_cast<T *>(this), subtydesc->shape, params,
900901
subtydesc->shape_tables, obj_closure_dp);
902+
903+
print print(sub);
904+
print.walk(false);
905+
901906
sub.walk(true);
902907
}
903908

0 commit comments

Comments
 (0)