From f8c06764b13f54913f2f8bbdfafb4d5f64296860 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sat, 13 May 2023 15:38:15 +0900 Subject: [PATCH] prefetch JuliaLang/julia#49801 for 1.9 --- src/analyzers/jetanalyzer.jl | 18 ++++++++++++++++++ test/analyzers/test_jetanalyzer.jl | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/analyzers/jetanalyzer.jl b/src/analyzers/jetanalyzer.jl index 1b4c796cc..97786c052 100644 --- a/src/analyzers/jetanalyzer.jl +++ b/src/analyzers/jetanalyzer.jl @@ -151,6 +151,24 @@ a package, or improve the accuracy of base abstract interpretation analysis. # getting rid of the false positive error from `getindex((), i)`. @overlay JET_METHOD_TABLE Base.iterate(::Tuple{}, ::Int) = nothing +# take the effects of https://github.com/JuliaLang/julia/pull/49801 for release versions +@static if VERSION < v"1.10.0-DEV.1289" +@overlay JET_METHOD_TABLE Base.@assume_effects :foldable function Base.aligned_sizeof(@nospecialize T::Type) + if isa(T, Union) + if Base.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 = Base.uniontype_layout(T) + return Base.LLT_ALIGN(sz, al) + end + elseif Base.allocatedinline(T) + al = Base.datatype_alignment(T) + return Base.LLT_ALIGN(Core.sizeof(T), al) + end + return Core.sizeof(Ptr{Cvoid}) +end +end + # overloads # ========= diff --git a/test/analyzers/test_jetanalyzer.jl b/test/analyzers/test_jetanalyzer.jl index bf3034cc3..af61bb1e8 100644 --- a/test/analyzers/test_jetanalyzer.jl +++ b/test/analyzers/test_jetanalyzer.jl @@ -1070,4 +1070,7 @@ test_call(issue_404, (Bool,)) end end +# https://github.com/JuliaLang/julia/pull/49801 +test_call(Base.aligned_sizeof, (Union{DataType,Union},)) + end # module test_jetanalyzer