Skip to content

Commit

Permalink
Merge pull request #36650 from JuliaLang/kf/typeinstgcfix
Browse files Browse the repository at this point in the history
Fix GC corruption during NamedTuple instantiation
  • Loading branch information
Keno authored Jul 14, 2020
2 parents dff83f2 + d778a3d commit 9676ec9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ jl_datatype_t *jl_new_uninitialized_datatype(void)
t->has_concrete_subtype = 1;
t->layout = NULL;
t->names = NULL;
t->types = NULL;
t->instance = NULL;
return t;
}

Expand Down Expand Up @@ -554,7 +556,6 @@ JL_DLLEXPORT jl_datatype_t *jl_new_datatype(
t->abstract = abstract;
t->mutabl = mutabl;
t->ninitialized = ninitialized;
t->instance = NULL;
t->size = 0;

t->name = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,6 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v
assert(pos == backref_list.len - 1 && "nothing should have been deserialized since assigning pos");
backref_list.items[pos] = dt;
dt->size = size;
dt->instance = NULL;
dt->abstract = flags & 1;
dt->mutabl = (flags >> 1) & 1;
int has_layout = (flags >> 2) & 1;
Expand Down
17 changes: 4 additions & 13 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ static void check_datatype_parameters(jl_typename_t *tn, jl_value_t **params, si
JL_GC_POP();
}

static jl_value_t *extract_wrapper(jl_value_t *t JL_PROPAGATES_ROOT)
static jl_value_t *extract_wrapper(jl_value_t *t JL_PROPAGATES_ROOT) JL_GLOBALLY_ROOTED
{
t = jl_unwrap_unionall(t);
if (jl_is_datatype(t))
Expand Down Expand Up @@ -1255,12 +1255,9 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
jl_value_t *tw = extract_wrapper(pi);
if (tw && tw != pi && (tn != jl_type_typename || jl_typeof(pi) == jl_typeof(tw)) &&
jl_types_equal(pi, tw)) {
if (jl_is_vararg_type(iparams[i])) {
tw = jl_wrap_vararg(tw, jl_tparam1(jl_unwrap_unionall(iparams[i])));
JL_GC_PUSH1(&tw);
tw = jl_rewrap_unionall(tw, iparams[i]);
JL_GC_POP();
}
// This would require some special handling, but is never used at
// the moment.
assert(!jl_is_vararg_type(iparams[i]));
iparams[i] = tw;
if (p) jl_gc_wb(p, tw);
}
Expand Down Expand Up @@ -1419,7 +1416,6 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
}
ndt->mutabl = dt->mutabl;
ndt->abstract = dt->abstract;
ndt->instance = NULL;
ndt->size = 0;
jl_precompute_memoized_dt(ndt, cacheable);
if (istuple)
Expand Down Expand Up @@ -1914,7 +1910,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_any_type, jl_any_type, jl_any_type, jl_any_type,
jl_any_type, jl_any_type, jl_any_type, jl_any_type,
jl_any_type);
jl_datatype_type->instance = NULL;
jl_datatype_type->abstract = 0;
// NOTE: types are not actually mutable, but we want to ensure they are heap-allocated with stable addresses
jl_datatype_type->mutabl = 1;
Expand All @@ -1933,7 +1928,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_typename_type->types = jl_svec(9, jl_symbol_type, jl_any_type, jl_simplevector_type,
jl_type_type, jl_simplevector_type, jl_simplevector_type,
jl_any_type, jl_any_type, jl_any_type);
jl_typename_type->instance = NULL;
jl_typename_type->abstract = 0;
jl_typename_type->mutabl = 1;
jl_typename_type->ninitialized = 2;
Expand All @@ -1953,7 +1947,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_any_type, jl_any_type/*module*/,
jl_any_type/*any vector*/, jl_any_type/*long*/, jl_any_type/*int32*/,
jl_any_type/*uint8*/, jl_any_type/*uint8*/);
jl_methtable_type->instance = NULL;
jl_methtable_type->abstract = 0;
jl_methtable_type->mutabl = 1;
jl_methtable_type->ninitialized = 5;
Expand All @@ -1966,7 +1959,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_symbol_type->parameters = jl_emptysvec;
jl_symbol_type->name->names = jl_emptysvec;
jl_symbol_type->types = jl_emptysvec;
jl_symbol_type->instance = NULL;
jl_symbol_type->size = 0;
jl_symbol_type->abstract = 0;
jl_symbol_type->mutabl = 1;
Expand All @@ -1980,7 +1972,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_simplevector_type->parameters = jl_emptysvec;
jl_simplevector_type->name->names = jl_emptysvec;
jl_simplevector_type->types = jl_emptysvec;
jl_simplevector_type->instance = NULL;
jl_simplevector_type->abstract = 0;
jl_simplevector_type->mutabl = 1;
jl_simplevector_type->ninitialized = 0;
Expand Down

0 comments on commit 9676ec9

Please sign in to comment.