JunoLab / Traceur.jl

Other
318 stars 15 forks source link

no unique matching method found for the specified argument types #23

Closed yakir12 closed 5 years ago

yakir12 commented 5 years ago

I have a fairly straightforward piece of code (calculates the shortest distance to a dome according to some criterion):

using StaticArrays, LinearAlgebra
const V3 = SVector{3, Float64}
isgoodz(oz, l, dz, positive::Bool) = oz > -l*dz ? positive : !positive
function distance(orig::V3, dir::V3, positive::Bool)
    b = -orig⋅dir
    disc = b^2 - orig⋅orig + 1
    if disc ≥ 0
        d = sqrt(disc)
        t2 = b + d
        if t2 ≥ 0
            t1 = b - d
            if t1 > 0 
                isgoodz(orig[3], t1, dir[3], positive) && return t1
                isgoodz(orig[3], t2, dir[3], positive) && return t2
            else                                                   
                isgoodz(orig[3], t2, dir[3], positive) && return t2
            end
        end
    end
    nothing
end
z = 0.5
orig = V3(0.,0,z + 1)
dir = V3(0.,0,-1)
pos = true
distance(orig, dir, pos) # works and return 0.5

I wanted to test it but I get this error:

julia> using Traceur

julia> @trace distance(orig, dir, pos)
ERROR: no unique matching method found for the specified argument types                                
Stacktrace:
 [1] which(::Any, ::Any) at ./reflection.jl:926
 [2] method at /home/yakir/.julia/packages/Traceur/6a4Uc/src/analysis.jl:21 [inlined]
 [3] posthook(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::Function, ::SArray{Tuple{3},Float64,1,3}, ::SArray{Tuple{3},Float64,1,3}) at /home/yakir/.julia/packages/Traceur/6a4Uc/src/trace.jl:19
 [4] same_size at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/traits.jl:193 [inlined]
 [5] map at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/mapreduce.jl:11 [inlined]
 [6] - at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/linalg.jl:6 [inlined]
 [7] distance at ./REPL[4]:2 [inlined]
 [8] overdub(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::typeof(distance), ::SArray{Tuple{3},Float64,1,3}, ::SArray{Tuple{3},Float64,1,3}, ::Bool) at /home/yakir/.julia/packages/Cassette/LvKdG/src/overdub.jl:0
 [9] #7 at /home/yakir/.julia/packages/Traceur/6a4Uc/src/trace.jl:37 [inlined]
 [10] overdub(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::getfield(Main, Symbol("##7#8"))) at /home/yakir/.julia/packages/Cassette/LvKdG/src/overdub.jl:0
 [11] trace(::Function, ::Function) at /home/yakir/.julia/packages/Traceur/6a4Uc/src/trace.jl:26
 [12] warntrace(::Function) at /home/yakir/.julia/packages/Traceur/6a4Uc/src/trace.jl:28
 [13] top-level scope at none:0
kurbkid commented 5 years ago

I have the same issue and it even happens for two of the examples in the readme.md.

julia> function naive_sum(xs)
                s = 0
                for x in xs
                  s += x
                end
                return s
              end
naive_sum (generic function with 1 method)
julia> @trace naive_sum([1.])
ERROR: no unique matching method found for the specified argument types

and

julia> y=1
1
julia> f(x) = x+y
f (generic function with 1 method)
julia> @trace f(1.0)
ERROR: no unique matching method found for the specified argument types

The stacktrace looks the same as yours. Interestingly the naive_relu example is working as expected.

pfitzseb commented 5 years ago

Can you try Traceur#master? I can't seem to repro this issue with either of the above examples and Julia 1.0.3. Will release a new version if you can confirm.

yakir12 commented 5 years ago

Both @kurbkid's examples from the readme worked for me (after switching to master), but my own example didn't:


julia> distance(orig, dir, pos)
0.5

julia> @trace distance(orig, dir, pos)
ERROR: ArgumentError: argument is not a generic function
Stacktrace:
 [1] which(::Any, ::Any) at ./reflection.jl:920
 [2] method(::Traceur.DynamicCall{typeof(tuple),Tuple{Int64}}) at /home/yakir/.julia/packages/Traceur/LWoeA/src/analysis.jl:21
 [3] posthook(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::Function, ::Tuple{Int64}, ::Int64) at /home/yakir/.julia/packages/Traceur/LWoeA/src/trace.jl:29
 [4] Type at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/traits.jl:67 [inlined]
 [5] overdub(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::Type{Size}, ::Type{Tuple{3}}) at /home/yakir/.julia/packages/Cassette/LvKdG/src/overdub.jl:0
 [6] Type at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/traits.jl:88 [inlined]
 [7] overdub(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::Type{Size}, ::Type{SArray{Tuple{3},Float64,1,3}}) at /home/yakir/.julia/packages/Cassette/LvKdG/src/overdub.jl:0
 [8] Type at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/traits.jl:86 [inlined]
 [9] overdub(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::Type{Size}, ::SArray{Tuple{3},Float64,1,3}) at /home/yakir/.julia/packages/Cassette/LvKdG/src/overdub.jl:0
 [10] same_size at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/traits.jl:193 [inlined]
 [11] map at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/mapreduce.jl:11 [inlined]
 [12] - at /home/yakir/.julia/packages/StaticArrays/mcf7t/src/linalg.jl:6 [inlined]
 [13] distance at ./REPL[4]:2 [inlined]
 [14] overdub(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::typeof(distance), ::SArray{Tuple{3},Float64,1,3}, ::SArray{Tuple{3},Float64,1,3}, ::Bool) at /home/yakir/.julia/packages/Cassette/LvKdG/src/overdub.jl:0
 [15] #7 at /home/yakir/.julia/packages/Traceur/LWoeA/src/trace.jl:49 [inlined]
 [16] recurse(::Cassette.Context{nametype(TraceurCtx),Traceur.Trace,Nothing,getfield(Cassette, Symbol("##PassType#363")),Nothing,Nothing}, ::getfield(Main, Symbol("##7#8"))) at /home/yakir/.julia/packages/Cassette/LvKdG/src/overdub.jl:0
 [17] trace(::Function, ::Function) at /home/yakir/.julia/packages/Traceur/LWoeA/src/trace.jl:38
 [18] warntrace(::Function) at /home/yakir/.julia/packages/Traceur/LWoeA/src/trace.jl:40
 [19] top-level scope at none:0
kurbkid commented 5 years ago

The examples work for me on master too. Btw, is it normal that it takes a minute?

pfitzseb commented 5 years ago

Hm, @yakir12's example works fine for me as well:


julia> distance(orig, dir, pos)
0.5

julia> @trace distance(orig, dir, pos)
0.5

Btw, is it normal that it takes a minute?

The naive_sum example takes about 10s for me, but yeah, the current approach will be quite slow due to lots of recompilation happening. Once https://github.com/JuliaDebug/ASTInterpreter2.jl/pull/37 is ironed out and a new release is tagged I'll probably port Traceur back to that instead of using Cassette, which should improve performance drastically.

yakir12 commented 5 years ago

@yakir12's example works fine for me as well:

Whaaat... So what should I try..?

pfitzseb commented 5 years ago

Ah, I did have an unrelated change deved that caused the error to not appear. This seems like an upstream bug to me (see https://github.com/jrevels/Cassette.jl/issues/101), but I've pushed a commit that should fix it anyways. So yeah, please try latest master and if it works for you I'll tag a new release.

yakir12 commented 5 years ago

It worked (with warnings)!

julia> @trace distance(orig, dir, pos)
┌ Warning: dynamic dispatch to ((Core.apply_type)(StaticArrays.Size, (Core._apply)(StaticArrays.tuple, (Base.getfield)(s, parameters))))()
└ @ ~/.julia/packages/StaticArrays/mcf7t/src/traits.jl:67
┌ Warning: dynamic dispatch to ((Core.apply_type)(StaticArrays.Size, s))()
└ @ ~/.julia/packages/StaticArrays/mcf7t/src/traits.jl:65
0.5
pfitzseb commented 5 years ago

Alright, cool. I think those warnings are false positives, but that's kinda expected. Will release a new version for now.