diff --git a/src/dump.c b/src/dump.c index 84a84032f4aa4..1105e375b17bc 100644 --- a/src/dump.c +++ b/src/dump.c @@ -257,7 +257,7 @@ static int type_parameter_recursively_external(jl_value_t *p0) JL_NOTSAFEPOINT return 0; if (module_in_worklist(p->name->module)) return 0; - if (jl_unwrap_unionall(p->name->wrapper) != (jl_value_t*)p) { + if (p->name->wrapper != (jl_value_t*)p0) { if (!type_recursively_external(p)) return 0; } @@ -327,11 +327,8 @@ static void jl_serialize_datatype(jl_serializer_state *s, jl_datatype_t *dt) JL_ write_uint8(s->s, TAG_DATATYPE); write_uint8(s->s, tag); - if (tag == 6) { - jl_serialize_value(s, dt->name); - return; - } - if (tag == 7) { + if (tag == 6 || tag == 7) { + // for tag==6, copy its typevars in case there are references to them elsewhere jl_serialize_value(s, dt->name); jl_serialize_value(s, dt->parameters); return; @@ -745,7 +742,7 @@ static void jl_serialize_value_(jl_serializer_state *s, jl_value_t *v, int as_li else if (jl_is_unionall(v)) { write_uint8(s->s, TAG_UNIONALL); jl_datatype_t *d = (jl_datatype_t*)jl_unwrap_unionall(v); - if (jl_is_datatype(d) && jl_unwrap_unionall(d->name->wrapper) == (jl_value_t*)d && + if (jl_is_datatype(d) && d->name->wrapper == v && !module_in_worklist(d->name->module)) { write_uint8(s->s, 1); jl_serialize_value(s, d->name->module); @@ -1335,13 +1332,8 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v if (tag == 6 || tag == 7) { jl_typename_t *name = (jl_typename_t*)jl_deserialize_value(s, NULL); jl_value_t *dtv = name->wrapper; - if (tag == 7) { - jl_svec_t *parameters = (jl_svec_t*)jl_deserialize_value(s, NULL); - dtv = jl_apply_type(dtv, jl_svec_data(parameters), jl_svec_len(parameters)); - } - else { - dtv = jl_unwrap_unionall(dtv); - } + jl_svec_t *parameters = (jl_svec_t*)jl_deserialize_value(s, NULL); + dtv = jl_apply_type(dtv, jl_svec_data(parameters), jl_svec_len(parameters)); backref_list.items[pos] = dtv; return dtv; } diff --git a/test/precompile.jl b/test/precompile.jl index ed93b60bfdd4f..c8f502b8b58b5 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -135,6 +135,8 @@ try const x28297 = Result(missing) + const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body)) + const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body)) # issue #28998 const x28998 = [missing, 2, missing, 6, missing, @@ -187,6 +189,9 @@ try @test Foo.x28297.result === missing + @test Foo.d29936a === Dict + @test Foo.d29936b === Dict{K,V} where {V,K} + @test Foo.x28998[end] == 6 end