Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
N5N3 opened this issue Dec 25, 2021 · 3 comments
Open

Comments

@N5N3
Copy link

N5N3 commented Dec 25, 2021

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(
1return 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{}}} >
   
@simeonschaub
Copy link
Collaborator

This is expected. @code_warntype gives the IR before optimization, if you want to get the equivalent in Cthulhu you need to pass optimize=false (or just press o). Perhaps @descend_code_warntype should set that by default to be more consistent with @code_warntype though?

@N5N3
Copy link
Author

N5N3 commented Dec 26, 2021

The problem is they give different inference results.
@code_typed and @code_warntype shows Type{Int64}.
IIUC, @descend_code_warntype shows Union{Type{Int64}, Type{Union{}}}.

@simeonschaub
Copy link
Collaborator

Ah, sorry, I missed that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants