Skip to content

prevent allocation of Memory (layout and object) when not concrete #58064

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

Merged
merged 1 commit into from
Apr 15, 2025
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
8 changes: 7 additions & 1 deletion src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,13 @@ void jl_get_genericmemory_layout(jl_datatype_t *st)
jl_value_t *kind = jl_tparam0(st);
jl_value_t *eltype = jl_tparam1(st);
jl_value_t *addrspace = jl_tparam2(st);
if (!jl_is_typevar(eltype) && !jl_is_type(eltype)) {
if (!st->isconcretetype) {
// Since parent dt has an opaque layout, we may end up here being asked to copy that layout to subtypes,
// but we don't actually want to do that unless this object is constructable (or at least has a layout).
// The real layout is stored only on the wrapper.
return;
}
if (!jl_is_type(eltype)) {
// this is expected to have a layout, but since it is not constructable, we don't care too much what it is
static const jl_datatype_layout_t opaque_ptr_layout = {0, 0, 1, -1, sizeof(void*), {0}};
st->layout = &opaque_ptr_layout;
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ JL_DLLEXPORT jl_value_t *jl_unwrap_unionall(jl_value_t *v JL_PROPAGATES_ROOT) JL
#define jl_inlinedatatype_layout(t) (((jl_datatype_t*)t)->layout)
STATIC_INLINE const jl_datatype_layout_t *jl_datatype_layout(jl_datatype_t *t) JL_NOTSAFEPOINT
{
if (jl_is_layout_opaque(t->layout)) // e.g. GenericMemory
if (t->layout == NULL || jl_is_layout_opaque(t->layout)) // e.g. GenericMemory
t = (jl_datatype_t*)jl_unwrap_unionall(t->name->wrapper);
return t->layout;
}
Expand Down
3 changes: 3 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4951,6 +4951,9 @@ let ft = Base.datatype_fieldtypes
@test !isdefined(ft(B12238.body.body)[1], :instance) # has free type vars
end

# issue #54969
@test !isdefined(Memory.body, :instance)

# `where` syntax in constructor definitions
(A12238{T} where T<:Real)(x) = 0
@test A12238{<:Real}(0) == 0
Expand Down