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

method seems to get dropped when precompilation is enabled #20200

Closed
jrevels opened this issue Jan 23, 2017 · 3 comments
Closed

method seems to get dropped when precompilation is enabled #20200

jrevels opened this issue Jan 23, 2017 · 3 comments
Labels
compiler:precompilation Precompilation of modules domain:types and dispatch Types, subtyping and method dispatch kind:bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@jrevels
Copy link
Member

jrevels commented Jan 23, 2017

For ease of reproducibility, I made an MRE package here: https://github.com/jrevels/DispatchError.jl. The bug can be "toggled" by turning precompilation on/off.

Here's the code:

__precompile__()

module DispatchError

immutable Foo{A,B}
    a::A
    b::B
    c::Int
    # disable default outer constructor
    Foo(a, b, c) = new(a, b, c)
end

Foo(args...) = error("boo!")

Foo{A<:AbstractArray,B<:AbstractArray}(a::A, b::B, c::Int) = info("yay!")

end # module

...and here's the test which exhibits the bug:

using DispatchError

# if you run this with precompilation enabled, 
# it errors out with "boo!" even though it should 
# just call the non-erroring constructor
#
# if precompilation is disabled, it calls the correct method
DispatchError.Foo(rand(3), rand(3), 1)

versioninfo:

julia> versioninfo()
Julia Version 0.6.0-dev.2478
Commit dbf41c0 (2017-01-30 18:58 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-4288U CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

EDIT: simplified the example further

@jrevels
Copy link
Member Author

jrevels commented Jan 30, 2017

Note that switching the order of the outer constructor definitions also circumvents the bug.

@jrevels
Copy link
Member Author

jrevels commented Feb 8, 2017

Checked this at the request of @vtjnash, and it seems like the more specific constructor gets totally dropped when precompilation is enabled (but the method table seems to have the right number of methods either way...?).

Precompilation on:

julia> n_methods = length(typeof(Type).name.mt)
1387

julia> using DispatchError

julia> methods(DispatchError.Foo)
# 1 method for generic function "(::Type)":
(::Type{DispatchError.Foo})(args...) in DispatchError at /Users/jarrettrevels/.julia/v0.6/DispatchError/src/DispatchError.jl:13

julia> length(typeof(Type).name.mt) - n_methods
3

Precompilation off:

julia> n_methods = length(typeof(Type).name.mt)
1387

julia> using DispatchError

julia> methods(DispatchError.Foo)
# 2 methods for generic function "(::Type)":
(::Type{DispatchError.Foo}){A<:AbstractArray, B<:AbstractArray}(a::A, b::B, c::Int64) in DispatchError at /Users/jarrettrevels/.julia/v0.6/DispatchError/src/DispatchError.jl:15
(::Type{DispatchError.Foo})(args...) in DispatchError at /Users/jarrettrevels/.julia/v0.6/DispatchError/src/DispatchError.jl:13

julia> length(typeof(Type).name.mt) - n_methods
3

@jrevels jrevels changed the title dispatch isn't choosing most specific method when precompilation is enabled method seems to get dropped when precompilation is enabled Feb 8, 2017
@jrevels jrevels added this to the 0.6.0 milestone Mar 6, 2017
@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 7, 2017

fixed by #20665

@vtjnash vtjnash closed this as completed Mar 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:precompilation Precompilation of modules domain:types and dispatch Types, subtyping and method dispatch kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants