Skip to content

Commit

Permalink
Reorder self-referential types checking to prevent inline allocation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Liozou authored and vtjnash committed Oct 30, 2019
1 parent d35134c commit b92a35d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ void jl_compute_field_offsets(jl_datatype_t *st)
// based on whether its definition is self-referential
if (w->types != NULL) {
st->isbitstype = st->isinlinealloc = st->isconcretetype && !st->mutabl;
if (st->isinlinealloc) {
size_t i, nf = jl_svec_len(w->types);
for (i = 0; i < nf; i++) {
jl_value_t *fld = jl_svecref(w->types, i);
if (references_name(fld, w->name)) {
st->isinlinealloc = 0;
st->isbitstype = 0;
st->zeroinit = 1;
break;
}
}
}
size_t i, nf = jl_svec_len(st->types);
for (i = 0; i < nf; i++) {
jl_value_t *fld = jl_svecref(st->types, i);
Expand All @@ -327,18 +339,6 @@ void jl_compute_field_offsets(jl_datatype_t *st)
st->has_concrete_subtype &= !jl_is_datatype(fld) || ((jl_datatype_t *)fld)->has_concrete_subtype;
}
}
if (st->isinlinealloc) {
size_t i, nf = jl_svec_len(w->types);
for (i = 0; i < nf; i++) {
jl_value_t *fld = jl_svecref(w->types, i);
if (references_name(fld, w->name)) {
st->isinlinealloc = 0;
st->isbitstype = 0;
st->zeroinit = 1;
break;
}
}
}
}
// If layout doesn't depend on type parameters, it's stored in st->name->wrapper
// and reused by all subtypes.
Expand Down
8 changes: 8 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5924,6 +5924,14 @@ let x = UnionFieldInlineStruct(1, 3.14)
@test CInlineUnion[end] == x
end

# issue 33709
struct A33709
a::Union{Nothing,A33709}
end
let a33709 = A33709(A33709(nothing))
@test isnothing(a33709.a.a)
end

# issue 31583
a31583 = "a"
f31583() = a31583 === "a"
Expand Down

0 comments on commit b92a35d

Please sign in to comment.