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

@code_native fails on broadcast calls #31695

Closed
staticfloat opened this issue Apr 11, 2019 · 3 comments
Closed

@code_native fails on broadcast calls #31695

staticfloat opened this issue Apr 11, 2019 · 3 comments

Comments

@staticfloat
Copy link
Sponsor Member

Using Julia v1.1:

julia> X = randn(100); @code_native log.(X)
ERROR: no unique matching method found for the specified argument types
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] which(::Any, ::Any) at ./reflection.jl:1002
 [3] _dump_function(::Any, ::Any, ::Bool, ::Bool, ::Bool, ::Bool, ::Symbol, ::Bool, ::Symbol, ::Base.CodegenParams) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/InteractiveUtils/src/codeview.jl:65
 [4] _dump_function at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/InteractiveUtils/src/codeview.jl:59 [inlined]
 [5] #code_native#9 at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/InteractiveUtils/src/codeview.jl:136 [inlined]
 [6] (::getfield(InteractiveUtils, Symbol("#kw##code_native")))(::NamedTuple{(:syntax, :debuginfo),Tuple{Symbol,Symbol}}, ::typeof(code_native), ::Base.TTY, ::Function, ::Type) at ./none:0
 [7] #code_native#10(::Symbol, ::Symbol, ::Function, ::Any, ::Any) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/InteractiveUtils/src/codeview.jl:138
 [8] code_native(::Any, ::Any) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/InteractiveUtils/src/codeview.jl:138
 [9] top-level scope at none:0
@staticfloat
Copy link
Sponsor Member Author

Notably; wrapping the broadcast call in another call works:

julia> X = randn(100)
       foo(X) = log.(X)
       @code_native foo(X)
# works...

@staticfloat staticfloat changed the title @code_native fails with error on log.(X) @code_native fails on broadcast calls Apr 11, 2019
@mbauman
Copy link
Sponsor Member

mbauman commented Apr 11, 2019

I could've sworn we had an issue for this, but I'm not finding it. It's similar to #20620 and affects all of the code_typed / code_warntype / code_llvm / code_native / edit / which / etc functionality. And it results in an UndefVarError in cases like:

julia> @code_llvm [1] .+ [2]
ERROR: UndefVarError: .+ not defined

In short, the lowering for broadcast is non-trivial and isn't a single function call:

julia> Meta.@lower log.(x)
:($(Expr(:thunk, CodeInfo(
1 ─ %1 = (Base.broadcasted)(log, x)
│   %2 = (Base.materialize)(%1)
└──      return %2
))))

I'm regularly building those broadcasted objects and introspecting materialize directly:

julia> bc = (Base.broadcasted)(log, x)
Base.Broadcast.Broadcasted(log, (1:5,))

julia> @code_typed (Base.materialize)(bc)
CodeInfo(
...
)

@maleadt
Copy link
Member

maleadt commented Apr 12, 2019

I could've sworn we had an issue for this, but I'm not finding it.

#28615?

@mbauman mbauman closed this as completed Apr 12, 2019
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

3 participants