From dc064683087d017927381e64c38bd162aea47b4e Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Thu, 27 Jul 2023 08:09:58 -0300 Subject: [PATCH] Make reinterpret specialize fully. (#50670) Fixes https://github.com/JuliaLang/julia/issues/50612 The issue here was the reinterpret change made a bunch of operations like `Core.bitcast(UInt64,24)` not fold, even though they are fully known at compile time. That made `UInt32(Char)` not inline which then caused the regression. --- base/essentials.jl | 4 ++-- test/compiler/inline.jl | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/base/essentials.jl b/base/essentials.jl index 68dd0c06d646f..ad6e02cab145c 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -571,8 +571,8 @@ julia> reinterpret(Tuple{UInt16, UInt8}, (0x01, 0x0203)) otherwise be prevented by the type's constructors and methods. Unexpected behavior may result without additional validation. """ -function reinterpret(Out::Type, x::In) where {In} - if isprimitivetype(Out) && isprimitivetype(In) +function reinterpret(::Type{Out}, x) where {Out} + if isprimitivetype(Out) && isprimitivetype(typeof(x)) return bitcast(Out, x) end # only available when Base is fully loaded. diff --git a/test/compiler/inline.jl b/test/compiler/inline.jl index be821a88f00cc..3bc7ab5ccbc82 100644 --- a/test/compiler/inline.jl +++ b/test/compiler/inline.jl @@ -2061,3 +2061,7 @@ let src = code_typed1((Union{DataType,UnionAll},); interp=NoCompileSigInvokes()) (x.args[1]::MethodInstance).specTypes == Tuple{typeof(no_compile_sig_invokes),UnionAll} end == 1 end + +# https://github.com/JuliaLang/julia/issues/50612 +f50612(x) = UInt32(x) +@test all(!isinvoke(:UInt32),get_code(f50612,Tuple{Char}))