JuliaDebug / JuliaDebug/Cthulhu.jl

`@descend` gives different result from `@code_warntype` on 1.7.0 (and master?)

Open
#256 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
709
Forks
46
Avg merge
1d 13h
Merged PRs (30d)
2

Description

MWE:

struct A
       a::Vector{A}
end
_count(a::A) = sum(_count.(a.a);init = 0);
temp = A([A([A(A[])])]);
  1. @code_warntype
julia> @code_warntype Broadcast.combine_eltypes(_count,(temp.a,))
MethodInstance for Base.Broadcast.combine_eltypes(::typeof(_count), ::Tuple{Vector{A}})
  from combine_eltypes(f, args::Tuple) in Base.Broadcast at broadcast.jl:717
Arguments
  #self#::Core.Const(Base.Broadcast.combine_eltypes)
  f::Core.Const(_count)
  args::Tuple{Vector{A}}
Body::Type{Int64}
1 ─ %1 = Base._return_type::Core.Const(Core.Compiler.return_type)
│   %2 = Base.Broadcast.eltypes(args)::Core.Const(Tuple{A})
│   %3 = (%1)(f, %2)::Core.Const(Int64)
│   %4 = Base.Broadcast.promote_typejoin_union(%3)::Core.Const(Int64)
└──      return %4
  1. @code_typed
julia> @code_typed Broadcast.combine_eltypes(_count,(temp.a,))
CodeInfo(
1 ─     return Int64
) => Type{Int64}
  1. @descend_code_warntype
julia> @descend_code_warntype Broadcast.combine_eltypes(_count,(temp.a,))
combine_eltypes(f, args::Tuple) in Base.Broadcast at broadcast.jl:717
Body::Union{Type{Union{}}, Type{Int64}}
717 1 ─ %1  = Base._return_type::Core.Const(Core.Compiler.return_type)      │
    │   %2  = (%1)(f, Tuple{A})::Union{Type{Int64}, Type{Union{}}}          │
    │   %3  = (isa)(%2, Type{Int64})::Bool                                  │
    └──       goto #3 if not %3                                             │
    2 ─       goto #6                                                       │
    3 ─ %6  = (isa)(%2, Type{Union{}})::Bool                                │
    └──       goto #5 if not %6                                             │
    4 ─       goto #6                                                       │
    5 ─       Core.throw(ErrorException("fatal error in type inference (type bound)"))
    └──       unreachable                                                   │
    6 ┄ %11 = φ (#2 => Int64, #4 => Union{})::Union{Type{Union{}}, Type{Int64}}
    └──       return %11                                                    │
Select a call to descend into or ↩ to ascend. [q]uit. [b]ookmark.
Toggles: [o]ptimize, [w]arn, [h]ide type-stable statements, [d]ebuginfo, [r]emarks, [i]nlining costs, [t]ype annotations, [s]yntax highlight for Source/LLVM/Native.
Show: [S]ource code, [A]ST, [T]yped code, [L]LVM IR, [N]ative code
Actions: [E]dit source code, [R]evise and redisplay
Advanced: dump [P]arams cache.
 • %2  = return_type < _count(::A)::Union{Type{Int64}, Type{Union{}}} >
   ↩

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Julia MWE and comparing @code_warntype, @code_typed, and @descend_code_warntype for Broadcast.combine_eltypes. Trace the @descend_code_warntype entry point and its handling of the return_type call, then determine why the displayed inferred union differs. Done means the discrepancy is explained and the corrected behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.