Skip to content

Commit

Permalink
fix a bug where jl_typeof(jl_emptytuple) was a singleton type missing…
Browse files Browse the repository at this point in the history
… from the serializer known objects list

this also serializes the datatype along with any singleton.
this simplifies the back-and-forth a bit,
but more importantly, during incremental compilation, it was possible to
encounter a singleton without ever encountering its datatype.
it is now trivially possible to remove the Singleton_tag
  • Loading branch information
vtjnash committed Jul 17, 2015
1 parent ef3ec3d commit fee6081
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,14 @@ static void jl_serialize_value_(ios_t *s, jl_value_t *v)
else {
if (v == t->instance) {
assert(mode != MODE_MODULE_POSTWORK);
if (mode == MODE_MODULE) {
// also flag this in the backref table as special
uptrint_t *bp = (uptrint_t*)ptrhash_bp(&backref_table, v);
assert(*bp != (uptrint_t)HT_NOTFOUND);
*bp |= 1;
}
writetag(s, (jl_value_t*)Singleton_tag);
jl_serialize_value(s, t);
return;
}
if (t->size <= 255) {
Expand Down Expand Up @@ -983,7 +990,6 @@ static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos, jl_value_t **loc)
if (has_instance) {
assert(mode != MODE_MODULE_POSTWORK); // there shouldn't be an instance on a type with uid = 0
dt->instance = jl_deserialize_value(s, &dt->instance);
jl_set_typeof(dt->instance, dt);
jl_gc_wb(dt, dt->instance);
}
if (tag == 5) {
Expand Down Expand Up @@ -1382,7 +1388,13 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, jl_value_t *vtag, jl_value_t
return v;
}
else if (vtag == (jl_value_t*)Singleton_tag) {
assert(mode != MODE_MODULE_POSTWORK);
if (mode == MODE_MODULE_POSTWORK) {
uptrint_t pos = backref_list.len;
arraylist_push(&backref_list, NULL);
jl_datatype_t *dt = (jl_datatype_t*)jl_deserialize_value(s, NULL);
backref_list.items[pos] = dt->instance;
return dt->instance;
}
jl_value_t *v = (jl_value_t*)jl_gc_alloc_0w();
if (usetable) {
uptrint_t pos = backref_list.len;
Expand All @@ -1393,6 +1405,8 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, jl_value_t *vtag, jl_value_t
arraylist_push(&flagref_list, (void*)pos);
}
}
jl_datatype_t *dt = (jl_datatype_t*)jl_deserialize_value(s, NULL); // no loc, since if dt is replaced, then dt->instance would be also
jl_set_typeof(v, dt);
return v;
}
assert(0);
Expand Down Expand Up @@ -1926,13 +1940,14 @@ static jl_array_t *_jl_restore_incremental(ios_t *f)
while (j < flagref_list.len) {
jl_value_t **loc = (jl_value_t**)flagref_list.items[j];
int offs = (int)(intptr_t)flagref_list.items[j+1];
if (*loc == (jl_value_t*)dt) {
jl_value_t *o = loc ? *loc : (jl_value_t*)backref_list.items[offs];
if ((jl_value_t*)dt == o) {
if (t != dt) {
if (loc) *loc = (jl_value_t*)t;
if (offs > 0) backref_list.items[offs] = t;
}
}
else if (*loc == v) {
else if (v == o) {
if (t->instance != v) {
*loc = t->instance;
if (offs > 0) backref_list.items[offs] = t->instance;
Expand Down Expand Up @@ -2037,6 +2052,7 @@ void jl_init_serializer(void)
(void*)Int32_tag, (void*)Array1d_tag, (void*)Singleton_tag,
jl_module_type, jl_tvar_type, jl_lambda_info_type,
(void*)CommonSym_tag, (void*)NearbyGlobal_tag, jl_globalref_type,
// everything above here represents a class of object rather only than a literal

jl_emptysvec, jl_emptytuple, jl_false, jl_true, jl_nothing, jl_any_type,
call_sym, goto_ifnot_sym, return_sym, body_sym, line_sym,
Expand Down Expand Up @@ -2093,7 +2109,7 @@ void jl_init_serializer(void)
jl_ANY_flag, jl_array_any_type, jl_intrinsic_type, jl_method_type,
jl_methtable_type, jl_voidpointer_type, jl_newvarnode_type,
jl_array_symbol_type, jl_anytuple_type, jl_tparam0(jl_anytuple_type),

jl_typeof(jl_emptytuple),
jl_symbol_type->name, jl_gensym_type->name, jl_tuple_typename,
jl_ref_type->name, jl_pointer_type->name, jl_simplevector_type->name,
jl_datatype_type->name, jl_uniontype_type->name, jl_array_type->name,
Expand Down

0 comments on commit fee6081

Please sign in to comment.