Open
Description
MWE:
julia> @report_call empty!(Dict{String,Union{String, UInt}}())
═════ 1 possible error found ═════
┌ empty!(h::Dict{String, Union{UInt64, String}}) @ Base ./dict.jl:225
│┌ _unsetindex!(A::Memory{Union{UInt64, String}}, i::Int64) @ Base ./genericmemory.jl:77
││┌ _unsetindex!(A::MemoryRef{Union{UInt64, String}}) @ Base ./genericmemory.jl:88
│││ invalid builtin function call: typeassert(T::Type{Union{UInt64, String}}, DataType)
││└────────────────────
This happens due to this code in Base (slightly modified):
arrayelem = datatype_arrayelem(MemT)
isbits = 0; isboxed = 1; isunion = 2
arrayelem == isbits && datatype_pointerfree(T::DataType) && return A
where
- The function
datatype_arrayelem
is a C function that returns 0, 1, or 2 depending on how a givenMemory{T}
subtype stores its elements. - In the error case, the memory being passed in is the
Memory{String, UInt}
in the dict. Therefore, the C function will return 2 - The line
arrayelem == isbits && datatype_pointerfree(T::DataType) && return A
will never execute. However, the compiler does not know this. - The issue occurs because JET, at compile time, knows that
T::DataType
will fail, sinceT === Union{String, UInt}
.
The core problem is that JET will flag typeasserts it knows at compile time will fail. However, we typically use typeasserts precisely when we have type information which the compiler doesn't.
In this case, we know a priori that arrayelem == isunion
.
Possible solutions:
- Make JET less eager to report typeasserts as errors, unless the compiler can prove that the typeassert is going to be executed with the wrong type
- Add a mechanism in Base to disable type checking (that's probably not a good idea)
Metadata
Metadata
Assignees
Labels
No labels