@@ -68,7 +68,7 @@ mutable struct TapedFunction{F, TapeType}
68
68
tape:: TapeType
69
69
counter:: Int
70
70
bindings:: Bindings
71
- slots :: Dict {Int, Int } # slot indices in bindings
71
+ arg_indices :: Vector {Int} # arg indices in bindings
72
72
retval:: Int # 0 indicates the function has not returned
73
73
74
74
function TapedFunction {F, T} (f:: F , args... ; cache= false ) where {F, T}
@@ -94,7 +94,7 @@ mutable struct TapedFunction{F, TapeType}
94
94
95
95
function TapedFunction {F, T0} (tf:: TapedFunction{F, T1} ) where {F, T0, T1}
96
96
new {F, T0} (tf. func, tf. arity, tf. ir, tf. tape,
97
- tf. counter, tf. bindings, tf. slots , 0 )
97
+ tf. counter, tf. bindings, tf. arg_indices , 0 )
98
98
end
99
99
100
100
TapedFunction (tf:: TapedFunction{F, T} ) where {F, T} = TapedFunction {F, T} (tf)
@@ -155,10 +155,10 @@ function (tf::TapedFunction)(args...; callback=nothing, continuation=false)
155
155
# set args
156
156
if tf. counter <= 1
157
157
# The first slot in `bindings` is assumed to be `tf.func`.
158
- haskey ( tf. slots, 1 ) && _update_var! (tf, tf. slots [1 ], tf. func)
159
- for i in 1 : length (args) # the subsequent slots are arguments
158
+ tf. arg_indices[ 1 ] > 0 && _update_var! (tf, tf. arg_indices [1 ], tf. func)
159
+ for i in 1 : length (args) # the subsequent arg_indices are arguments
160
160
slot = i + 1
161
- haskey ( tf. slots, slot) && _update_var! (tf, tf. slots [slot], args[i])
161
+ tf. arg_indices[ slot] > 0 && _update_var! (tf, tf. arg_indices [slot], args[i])
162
162
end
163
163
end
164
164
@@ -330,7 +330,11 @@ function translate!(tape::RawTape, ir::Core.CodeInfo)
330
330
for (k, v) in tbind. book
331
331
isa (k, Core. SlotNumber) && (slots[k. id] = v)
332
332
end
333
- return (bindings, slots, tape)
333
+ arg_indices = fill (0 , maximum (keys (slots)))
334
+ for (k, v) in slots
335
+ arg_indices[k] = v
336
+ end
337
+ return (bindings, arg_indices, tape)
334
338
end
335
339
336
340
function _const_instruction (var:: IRVar , v, tbind:: TempBindings , ir)
0 commit comments