Skip to content

Commit 8982506

Browse files
vtjnashKristofferC
authored andcommitted
prevent allocation of Memory (layout and object) when not concrete (#58064)
Fix #54969 (cherry picked from commit cca5ac7)
1 parent 750f8cb commit 8982506

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/datatype.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,13 @@ void jl_get_genericmemory_layout(jl_datatype_t *st)
500500
jl_value_t *kind = jl_tparam0(st);
501501
jl_value_t *eltype = jl_tparam1(st);
502502
jl_value_t *addrspace = jl_tparam2(st);
503-
if (!jl_is_typevar(eltype) && !jl_is_type(eltype)) {
503+
if (!st->isconcretetype) {
504+
// Since parent dt has an opaque layout, we may end up here being asked to copy that layout to subtypes,
505+
// but we don't actually want to do that unless this object is constructable (or at least has a layout).
506+
// The real layout is stored only on the wrapper.
507+
return;
508+
}
509+
if (!jl_is_type(eltype)) {
504510
// this is expected to have a layout, but since it is not constructable, we don't care too much what it is
505511
static const jl_datatype_layout_t opaque_ptr_layout = {0, 0, 1, -1, sizeof(void*), {0}};
506512
st->layout = &opaque_ptr_layout;

src/julia.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ JL_DLLEXPORT jl_value_t *jl_unwrap_unionall(jl_value_t *v JL_PROPAGATES_ROOT) JL
15051505
#define jl_inlinedatatype_layout(t) (((jl_datatype_t*)t)->layout)
15061506
STATIC_INLINE const jl_datatype_layout_t *jl_datatype_layout(jl_datatype_t *t) JL_NOTSAFEPOINT
15071507
{
1508-
if (jl_is_layout_opaque(t->layout)) // e.g. GenericMemory
1508+
if (t->layout == NULL || jl_is_layout_opaque(t->layout)) // e.g. GenericMemory
15091509
t = (jl_datatype_t*)jl_unwrap_unionall(t->name->wrapper);
15101510
return t->layout;
15111511
}

test/core.jl

+3
Original file line numberDiff line numberDiff line change
@@ -4951,6 +4951,9 @@ let ft = Base.datatype_fieldtypes
49514951
@test !isdefined(ft(B12238.body.body)[1], :instance) # has free type vars
49524952
end
49534953

4954+
# issue #54969
4955+
@test !isdefined(Memory.body, :instance)
4956+
49544957
# `where` syntax in constructor definitions
49554958
(A12238{T} where T<:Real)(x) = 0
49564959
@test A12238{<:Real}(0) == 0

0 commit comments

Comments
 (0)