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

improve type inference of Base.aligned_sizeof #49801

Merged
merged 1 commit into from
May 13, 2023
Merged
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
13 changes: 8 additions & 5 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,18 @@ LLT_ALIGN(x, sz) = (x + sz - 1) & -sz
# amount of total space taken by T when stored in a container
function aligned_sizeof(@nospecialize T::Type)
@_foldable_meta
if isbitsunion(T)
_, sz, al = uniontype_layout(T)
return LLT_ALIGN(sz, al)
if isa(T, Union)
if allocatedinline(T)
# NOTE this check is equivalent to `isbitsunion(T)`, we can improve type
# inference in the second branch with the outer `isa(T, Union)` check
_, sz, al = uniontype_layout(T)
return LLT_ALIGN(sz, al)
end
elseif allocatedinline(T)
al = datatype_alignment(T)
return LLT_ALIGN(Core.sizeof(T), al)
else
return Core.sizeof(Ptr{Cvoid})
end
return Core.sizeof(Ptr{Cvoid})
end

gc_alignment(sz::Integer) = Int(ccall(:jl_alignment, Cint, (Csize_t,), sz))
Expand Down