Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GC corruption during NamedTuple instantiation #36650

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1179,7 +1179,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 @@ -1915,7 +1911,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 @@ -1934,7 +1929,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 @@ -1954,7 +1948,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 @@ -1967,7 +1960,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 @@ -1981,7 +1973,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