Skip to content

Commit

Permalink
Make reinterpret specialize fully. (#50670)
Browse files Browse the repository at this point in the history
Fixes #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.
  • Loading branch information
gbaraldi authored Jul 27, 2023
1 parent 4fd68e8 commit dc06468
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}))

0 comments on commit dc06468

Please sign in to comment.