Skip to content

Nicer error for ambiguous methods #199

@penelopeysm

Description

@penelopeysm

function build_callable(sig::Type{<:Tuple})
if sig <: Tuple{typeof(produce),Any}
msg = """
Can not construct a TapedTask for a 'naked' call to `produce`.
Please wrap the call to `produce` in a function, and construct a
TapedTask from that function."""
throw(ArgumentError(msg))
end
key = CacheKey(Base.get_world_counter(), sig)
if haskey(mc_cache, key)
return fresh_copy(mc_cache[key])
else
ir = Base.code_ircode_by_type(sig)[1][1]
# Check whether this is a varargs call.
isva = which(sig).isva

If Libtask attempts to construct IR for an ambiguous method, line 86 here will error with something like this. It's at least not impossible to guess where is going wrong (based on the signature in [4]), but the error message could definitely be improved here too.

ERROR: BoundsError: attempt to access 0-element Vector{Any} at index [1]
Stacktrace:
  [1] throw_boundserror(A::Vector{Any}, I::Tuple{Int64})
    @ Base ./essentials.jl:14
  [2] getindex
    @ ./essentials.jl:916 [inlined]
  [3] build_callable(sig::Type{Tuple{…}})
    @ Libtask ~/.julia/packages/Libtask/Sf4tJ/src/copyable_task.jl:86
  [4] (::Libtask.DynamicCallable{…})(::Function, ::Turing.Inference.ParticleMCMCContext{…}, ::Cauchy{…}, ::Float64, ::AbstractPPL.VarName{…}, ::DynamicPPL.VarInfo{…})
    @ Libtask ~/.julia/packages/Libtask/Sf4tJ/src/copyable_task.jl:1163
  [5] f
    @ ./REPL[6]:1 [inlined]
  [6] (::Tuple{…})(none::typeof(f), none::DynamicPPL.Model{…}, none::DynamicPPL.VarInfo{…}, none::Float64)
    @ Base.Experimental ./<missing>:0
  [7] consume
    @ ~/.julia/packages/Libtask/Sf4tJ/src/copyable_task.jl:347 [inlined]
  [8] advance!(trace::AdvancedPS.Trace{AdvancedPS.LibtaskModel{…}, AdvancedPS.TracedRNG{…}}, isref::Bool)
    @ Turing.Inference ~/ppl/lib/src/mcmc/particle_mcmc.jl:68
  [9] reweight!(pc::AdvancedPS.ParticleContainer{AdvancedPS.Trace{…}, AdvancedPS.TracedRNG{…}}, ref::Noth

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions