133133struct NOOPInstruction <: AbstractInstruction end
134134
135135@inline result (t:: TapedFunction ) = t. binding_values[t. retval_binding_slot]
136+ @inline function _arg (tf:: TapedFunction , i:: Int ; default= nothing )
137+ length (tf. arg_binding_slots) < i && return default
138+ tf. arg_binding_slots[i] > 0 && return tf. binding_values[tf. arg_binding_slots[i]]
139+ return default
140+ end
141+ @inline function _arg! (tf:: TapedFunction , i:: Int , v)
142+ length (tf. arg_binding_slots) >= i &&
143+ tf. arg_binding_slots[i] > 0 && _update_var! (tf, tf. arg_binding_slots[i], v)
144+ end
136145
137146function (tf:: TapedFunction )(args... ; callback= nothing , continuation= false )
138147 if ! continuation # reset counter and retval_binding_slot to run from the start
@@ -143,10 +152,10 @@ function (tf::TapedFunction)(args...; callback=nothing, continuation=false)
143152 # set args
144153 if tf. counter <= 1
145154 # The first slot in `binding_values` is assumed to be `tf.func`.
146- tf . arg_binding_slots[ 1 ] > 0 && _update_var ! (tf, tf . arg_binding_slots[ 1 ] , tf. func)
155+ _arg ! (tf, 1 , tf. func)
147156 for i in 1 : length (args) # the subsequent arg_binding_slots are arguments
148157 slot = i + 1
149- tf . arg_binding_slots[slot] > 0 && _update_var ! (tf, tf . arg_binding_slots[ slot] , args[i])
158+ _arg ! (tf, slot, args[i])
150159 end
151160 end
152161
@@ -314,7 +323,7 @@ function translate!(tape::RawTape, ir::Core.CodeInfo)
314323 for (k, v) in bcache
315324 isa (k, Core. SlotNumber) && (slots[k. id] = v)
316325 end
317- arg_binding_slots = fill (0 , maximum (keys (slots)))
326+ arg_binding_slots = fill (0 , maximum (keys (slots); init = 0 ))
318327 for (k, v) in slots
319328 arg_binding_slots[k] = v
320329 end
0 commit comments