TuringLang / IRTracker.jl

Dynamically track IR as a graph, using source transformations
31 stars 5 forks source link

Snapshotting UnionAll fails #44

Closed phipsgabler closed 4 years ago

phipsgabler commented 4 years ago
julia> f(x) = x isa AbstractVector{<:Some}
f (generic function with 1 method)

julia> track(f, 1)
(value, head, arguments) = (AbstractArray{#s18,1} where #s18<:Some, :foreigncall, (⟨:jl_type_unionall⟩, ⟨Any⟩, ⟨svec(Any, Any)⟩, ⟨0⟩, ⟨:ccall⟩, @2, @3))
ERROR: TypeError: in new, expected DataType, got Type{AbstractArray{#s18,1} where #s18<:Some}
Stacktrace:
 [1] Snapshot at /home/philipp/.julia/dev/IRTracker/src/tapeexpr.jl:8 [inlined] (repeats 2 times)
 [2] IRTracker.Snapshot(::Type) at /home/philipp/.julia/dev/IRTracker/src/tapeexpr.jl:31
 [3] TapeSpecialForm(::Type, ::Symbol, ::Tuple{TapeConstant{Symbol},TapeConstant{DataType},TapeConstant{Core.SimpleVector},TapeConstant{Int64},TapeConstant{Symbol},TapeReference{TypeVar,ArgumentNode{TypeVar}},TapeReference{DataType,ArgumentNode{DataType}}}) at /home/philipp/.julia/dev/IRTracker/src/tapeexpr.jl:167
 [4] UnionAll at ./boot.jl:355 [inlined]
 [5] _recordnestedcall!(::IRTracker.GraphRecorder{DefaultTrackingContext}, ::Type{UnionAll}, ::TypeVar, ::Type{AbstractArray{#s18<:Some,1}}) at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:0
 [6] recordnestedcall at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:53 [inlined]
 [7] trackednested at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:194 [inlined]
 [8] trackedcall(::DefaultTrackingContext, ::TapeConstant{DataType}, ::Tuple{TapeReference{TypeVar,NestedCallNode{TypeVar,DataType,Tuple{Symbol,UnionAll},TapeCall{TypeVar,DataType,Tuple{Symbol,UnionAll},TapeConstant{DataType},Tuple{TapeConstant{Symbol},TapeConstant{UnionAll}},Tuple{}}}},TapeReference{DataType,PrimitiveCallNode{DataType,typeof(Core.apply_type),Tuple{UnionAll,TypeVar},TapeCall{DataType,typeof(Core.apply_type),Tuple{UnionAll,TypeVar},TapeConstant{typeof(Core.apply_type)},Tuple{TapeConstant{UnionAll},TapeReference{TypeVar,NestedCallNode{TypeVar,DataType,Tuple{Symbol,UnionAll},TapeCall{TypeVar,DataType,Tuple{Symbol,UnionAll},TapeConstant{DataType},Tuple{TapeConstant{Symbol},TapeConstant{UnionAll}},Tuple{}}}}},Nothing}}}}, ::NodeInfo) at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:214
 [9] trackedcall at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:221 [inlined]
 [10] f at ./REPL[19]:1 [inlined]
 [11] _recordnestedcall!(::IRTracker.GraphRecorder{DefaultTrackingContext}, ::typeof(f), ::Int64) at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:0
 [12] recordnestedcall at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:53 [inlined]
 [13] trackednested at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:194 [inlined]
 [14] trackedcall(::DefaultTrackingContext, ::TapeConstant{typeof(f)}, ::Tuple{TapeConstant{Int64}}, ::NodeInfo) at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:214
 [15] trackedcall at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:221 [inlined]
 [16] track(::DefaultTrackingContext, ::Function, ::Int64) at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:72
 [17] track(::Function, ::Int64) at /home/philipp/.julia/dev/IRTracker/src/tracker.jl:67
 [18] top-level scope at REPL[20]:1
 [19] eval(::Module, ::Any) at ./boot.jl:330
 [20] eval_user_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:86
 [21] run_backend(::REPL.REPLBackend) at /home/philipp/.julia/packages/Revise/AMRie/src/Revise.jl:1023
 [22] top-level scope at REPL[2]:0

Narrowed down to

julia> IRTracker.Snapshot(AbstractArray{<:Some, 1}, AbstractArray{<:Some, 1})
ERROR: TypeError: in new, expected DataType, got Type{AbstractArray{#s18,1} where #s18<:Some}
Stacktrace:
 [1] Snapshot at /home/philipp/.julia/dev/IRTracker/src/tapeexpr.jl:8 [inlined] (repeats 2 times)
 [2] top-level scope at REPL[25]:1
 [3] eval(::Module, ::Any) at ./boot.jl:330
 [4] eval_user_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/REPL/src/REPL.jl:86
 [5] run_backend(::REPL.REPLBackend) at /home/philipp/.julia/packages/Revise/AMRie/src/Revise.jl:1023
 [6] top-level scope at REPL[2]:0