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

stagedfunction called with Any #8508

Closed
mlubin opened this issue Sep 28, 2014 · 4 comments
Closed

stagedfunction called with Any #8508

mlubin opened this issue Sep 28, 2014 · 4 comments

Comments

@mlubin
Copy link
Member

mlubin commented Sep 28, 2014

I thought it was guaranteed that staged functions would be called with concrete types, but the following code seems to trick Julia into calling a stagedfunction with Any:

stagedfunction foo(t)
    @show t
    return
end

x = Array(Float64, 5)

let
    x = Array(Int,3)
    for i in 1:3
        x[i] = i
    end
    foo(x[1])

end

prints

t = Any
t = Any

This behavior is highly sensitive to the structure, if you remove let or the assignment to x[i], then the function is called correctly with Int.

CC @Keno @timholy

julia> versioninfo()
Julia Version 0.4.0-dev+812
Commit a28d619 (2014-09-27 07:46 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
@Keno
Copy link
Member

Keno commented Sep 28, 2014

You can throw an error in the staged function if the type is too general for you which will have it fall back to runtime dispatch.

@mlubin
Copy link
Member Author

mlubin commented Sep 28, 2014

Ah, useful to document :)

@timholy
Copy link
Member

timholy commented Sep 28, 2014

Related: #8504.

@timholy
Copy link
Member

timholy commented Sep 28, 2014

@Keno, actually, if this works, why does #8504 happen?

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

4 participants