JuliaDebug / Debugger.jl

Julia debugger
MIT License
469 stars 43 forks source link

Debugger throws TypeError but function doesn't #316

Closed wheeheee closed 2 years ago

wheeheee commented 2 years ago

The hash function Base.hash(x::T, h::UInt) from InlineStrings.jl works fine when run normally but @enter hash(x, h) throws a TypeError.

julia> x = String3("a")
julia> h = UInt(0)
julia> @enter hash(x, h)
In hash(x, h) at C:\Users\whee\.julia\packages\InlineStrings\F5Dhz\src\InlineStrings.jl:289
 289  function Base.hash(x::T, h::UInt) where {T <: InlineString}
>290      h += Base.memhash_seed
 291      ref = Ref{T}(_bswap(x))
 292      return ccall(Base.memhash, UInt,
 293          (Ref{T}, Csize_t, UInt32),
 294          ref, sizeof(x), h % UInt32) + h
 295  end

About to run: (+)(0x0000000000000000, 0x71e729fd56419c81)
1|debug> n
In hash(x, h) at C:\Users\whee\.julia\packages\InlineStrings\F5Dhz\src\InlineStrings.jl:289
 289  function Base.hash(x::T, h::UInt) where {T <: InlineString}
 290      h += Base.memhash_seed
>291      ref = Ref{T}(_bswap(x))
 292      return ccall(Base.memhash, UInt,
 293          (Ref{T}, Csize_t, UInt32),
 294          ref, sizeof(x), h % UInt32) + h
 295  end

About to run: (Core.apply_type)(Ref, String3)
1|debug> n
In hash(x, h) at C:\Users\whee\.julia\packages\InlineStrings\F5Dhz\src\InlineStrings.jl:289
 289  function Base.hash(x::T, h::UInt) where {T <: InlineString}
 290      h += Base.memhash_seed
 291      ref = Ref{T}(_bswap(x))
>292      return ccall(Base.memhash, UInt,
 293          (Ref{T}, Csize_t, UInt32),
 294          ref, sizeof(x), h % UInt32) + h
 295  end

About to run: (Core.apply_type)(Ref, String3)
1|debug> n
ERROR: TypeError: in typeassert, expected Core.SimpleVector, got a value of type Int64
Stacktrace:
 [1] hash(x::String3, h::UInt64)
   @ InlineStrings C:\Users\whee\.julia\packages\InlineStrings\F5Dhz\src\InlineStrings.jl:292

Stepping through, I get this

1|debug>
In hash(x, h) at C:\Users\whee\.julia\packages\InlineStrings\F5Dhz\src\InlineStrings.jl:289
 289  function Base.hash(x::T, h::UInt) where {T <: InlineString}
 290      h += Base.memhash_seed
 291      ref = Ref{T}(_bswap(x))
>292      return ccall(Base.memhash, UInt,
 293          (Ref{T}, Csize_t, UInt32),
 294          ref, sizeof(x), h % UInt32) + h
 295  end

About to run: (Base.unsafe_convert)(UInt32, 0x56419c81)
1|debug>
In unsafe_convert(#unused#, x) at essentials.jl:419
>419  unsafe_convert(::Type{T}, x::T) where {T} = x # unsafe_convert (like convert) defaults to assuming the convert occurred

About to run: return 0x56419c81
1|debug>
ERROR: TypeError: in typeassert, expected Core.SimpleVector, got a value of type Int64
Stacktrace:
 [1] unsafe_convert(#unused#::Type{UInt32}, x::UInt32)
   @ Base essentials.jl:419
 [2] hash(x::String3, h::UInt64)
   @ InlineStrings C:\Users\whee\.julia\packages\InlineStrings\F5Dhz\src\InlineStrings.jl:292

Also, without @enter, this ccall doesn't error

julia> ccall(Base.memhash, UInt, (Ref{String3}, UInt, UInt32), Ref{String3}(_bswap(x)), sizeof(x), h % UInt32)
0xe6b53a48510e895a

but with @enter

julia> @enter ccall(Base.memhash, UInt, (Ref{String3}, UInt, UInt32), Ref{String3}(_bswap(x)), sizeof(x), h % UInt32)
ERROR: UndefVarError: ccall not defined
Stacktrace:
 [1] top-level scope
   @ C:\Users\whee\.julia\packages\Debugger\APRPi\src\Debugger.jl:89

but when I wrap it with a function it's ok.

julia> f(x, h) = ccall(Base.memhash, UInt, (Ref{String3}, UInt, UInt32), Ref{String3}(_bswap(x)), sizeof(x), h % UInt32)
f (generic function with 1 method)

julia> @enter f(x,h)
In f(x, h) at REPL[209]:1
>1  f(x, h) = ccall(Base.memhash, UInt, (Ref{String3}, UInt, UInt32), Ref{String3}(_bswap(x)), sizeof(x), h % UInt32)

About to run: (Core.apply_type)(Ref, String3)
1|debug> n
In f(x, h) at REPL[209]:1
>1  f(x, h) = ccall(Base.memhash, UInt, (Ref{String3}, UInt, UInt32), Ref{String3}(_bswap(x)), sizeof(x), h % UInt32)

About to run: return 0xe6b53a48510e895a
1|debug> n
0xe6b53a48510e895a

but f(x::T, h::UInt) where T <: InlineString = ccall(Base.memhash, UInt, (Ref{T}, UInt, UInt32), Ref{T}(_bswap(x)), sizeof(x), h % UInt32) throws the same TypeError as above regardless.

KristofferC commented 2 years ago

I can't reproduce this now:


julia> @enter hash(x, h)
In hash(x, h) at /home/kc/.julia/packages/InlineStrings/VHH4L/src/InlineStrings.jl:289
 289  function Base.hash(x::T, h::UInt) where {T <: InlineString}
>290      h += Base.memhash_seed
 291      ref = Ref{T}(_bswap(x))
 292      return ccall(Base.memhash, UInt,
 293          (Ref{T}, Csize_t, UInt32),
 294          ref, sizeof(x), h % UInt32) + h
 295  end

About to run: (+)(0x0000000000000000, 0x71e729fd56419c81)
1|debug> c
0xfa232f94411b00cd

so I will guess this is fixed. Please comment if it is still bad for you.