Skip to content

Report bitcast: target type not a leaf primitive type in code using isprimitivetype, perhaps isprimitivetype should be handled special? #792

@fingolfin

Description

@fingolfin

I am seeing this in a JET report for AbstractAlgebra:

││││┌ convert(::Type{OrdinalRange{Int64, Int64}}, r::OrdinalRange{<:Integer, <:Integer}) @ Base ./range.jl:276
│││││┌ OrdinalRange{Int64, Int64}(r::OrdinalRange{<:Integer, <:Integer}) @ Base ./range.jl:1315
││││││┌ StepRange{Int64, Int64}(r::OrdinalRange{<:Integer, <:Integer}) @ Base ./range.jl:1327
│││││││┌ StepRange{Int64, Int64}(start::Any, step::Any, stop::Any) @ Base ./range.jl:336
││││││││┌ steprange_last(start::Any, step::Any, stop::Any) @ Base ./range.jl:365
│││││││││┌ (::Base.var"#overflow_case#steprange_last##0")(absdiff::Signed, absstep::Any) @ Base ./range.jl:364
││││││││││┌ unsigned(x::Union{Int128, Int16, Int32, Int64, Int8}) @ Base ./int.jl:216
│││││││││││┌ reinterpret(::Union{Type{…}, Type{…}, Type{…}, Type{…}, Type{…}}, x::Union{Int128, Int16, Int32, Int64, Int8}) @ Base ./essentials.jl:733
││││││││││││ bitcast: target type not a leaf primitive type: Base.bitcast(Out::Union{Type{UInt128}, Type{UInt16}, Type{UInt32}, Type{UInt64}, Type{UInt8}}, x::Union{Int128, Int16, Int32, Int64, Int8})
│││││││││││└────────────────────

Alas the code in essentials.jl:733 that JET complains about, the type Out in question is guarded by an isprimitivetype(Out) check.

function reinterpret(::Type{Out}, x) where {Out}
    @inline
    if isprimitivetype(Out) && isprimitivetype(typeof(x))
        return bitcast(Out, x)   # <-- this is the line 733 it complains about
    end
    # only available when Base is fully loaded.
    return _reinterpret(Out, x)
end

Perhaps JET could / should catch that pattern?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions