Skip to content

Commit 20f49ef

Browse files
committed
rename fields in TF
1 parent 9bafecf commit 20f49ef

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/tapedfunction.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ in a non-strict SSA form. Then we convert each IR instruction to a
1111
Julia representation (an object of a subtype of
1212
AbstractInstruction). All the operands (i.e., the varibales) these
1313
instructions use are stored in a data structure called
14-
`bindings`. This conversion/binding process is performed at
14+
`Bindings`. This conversion/binding process is performed at
1515
compile-time / tape-recording time.
1616
1717
There are mainly three kinds of instructions on a tape:
@@ -23,7 +23,7 @@ There are mainly three kinds of instructions on a tape:
2323
2424
Once the tape is recorded, we can run the tape to gain the same effect
2525
as calling the original function. We first fill the arguments into
26-
the bindings, then go through each instruction on the tape, stop after
26+
the Bindings, then go through each instruction on the tape, stop after
2727
we encounter a ReturnInstruction.
2828
2929
We provide a mechanism to add a callback after each instruction, with
@@ -67,9 +67,9 @@ mutable struct TapedFunction{F, TapeType}
6767
ir::Core.CodeInfo
6868
tape::TapeType
6969
counter::Int
70-
bindings::Bindings
71-
arg_indices::Vector{Int} # arg indices in bindings
72-
retval::Int # 0 indicates the function has not returned
70+
binding_values::Bindings
71+
arg_binding_slots::Vector{Int} # arg indices in binding_values
72+
retval_binding_slot::Int # 0 indicates the function has not returned
7373

7474
function TapedFunction{F, T}(f::F, args...; cache=false) where {F, T}
7575
args_type = _accurate_typeof.(args)
@@ -82,9 +82,9 @@ mutable struct TapedFunction{F, TapeType}
8282
return tf
8383
end
8484
ir = _infer(f, args_type)
85-
bindings, slots, tape = translate!(RawTape(), ir)
85+
binding_values, slots, tape = translate!(RawTape(), ir)
8686

87-
tf = new{F, T}(f, length(args), ir, tape, 1, bindings, slots, 0)
87+
tf = new{F, T}(f, length(args), ir, tape, 1, binding_values, slots, 0)
8888
TRCache[cache_key] = tf # set cache
8989
return tf
9090
end
@@ -94,7 +94,7 @@ mutable struct TapedFunction{F, TapeType}
9494

9595
function TapedFunction{F, T0}(tf::TapedFunction{F, T1}) where {F, T0, T1}
9696
new{F, T0}(tf.func, tf.arity, tf.ir, tf.tape,
97-
tf.counter, tf.bindings, tf.arg_indices, 0)
97+
tf.counter, tf.binding_values, tf.arg_binding_slots, 0)
9898
end
9999

100100
TapedFunction(tf::TapedFunction{F, T}) where {F, T} = TapedFunction{F, T}(tf)
@@ -113,8 +113,8 @@ end
113113

114114
compile(tf::TapedFunction{F, RawTape}) where {F} = TapedFunction{F, CompiledTape}(tf)
115115

116-
@inline _lookup(tf::TapedFunction, v::Int) = @inbounds tf.bindings[v]
117-
@inline _update_var!(tf::TapedFunction, v::Int, c) = @inbounds tf.bindings[v] = c
116+
@inline _lookup(tf::TapedFunction, v::Int) = @inbounds tf.binding_values[v]
117+
@inline _update_var!(tf::TapedFunction, v::Int, c) = @inbounds tf.binding_values[v] = c
118118

119119
"""
120120
Instruction
@@ -144,21 +144,21 @@ end
144144

145145
struct NOOPInstruction <: AbstractInstruction end
146146

147-
@inline result(t::TapedFunction) = t.bindings[t.retval]
147+
@inline result(t::TapedFunction) = t.binding_values[t.retval_binding_slot]
148148

149149
function (tf::TapedFunction)(args...; callback=nothing, continuation=false)
150-
if !continuation # reset counter and retval to run from the start
150+
if !continuation # reset counter and retval_binding_slot to run from the start
151151
tf.counter = 1
152-
tf.retval = 0
152+
tf.retval_binding_slot = 0
153153
end
154154

155155
# set args
156156
if tf.counter <= 1
157-
# The first slot in `bindings` is assumed to be `tf.func`.
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
157+
# The first slot in `binding_values` is assumed to be `tf.func`.
158+
tf.arg_binding_slots[1] > 0 && _update_var!(tf, tf.arg_binding_slots[1], tf.func)
159+
for i in 1:length(args) # the subsequent arg_binding_slots are arguments
160160
slot = i + 1
161-
tf.arg_indices[slot] > 0 && _update_var!(tf, tf.arg_indices[slot], args[i])
161+
tf.arg_binding_slots[slot] > 0 && _update_var!(tf, tf.arg_binding_slots[slot], args[i])
162162
end
163163
end
164164

@@ -167,7 +167,7 @@ function (tf::TapedFunction)(args...; callback=nothing, continuation=false)
167167
ins = tf.tape[tf.counter]
168168
ins(tf)
169169
callback !== nothing && callback()
170-
tf.retval != 0 && break
170+
tf.retval_binding_slot != 0 && break
171171
end
172172
return result(tf)
173173
end
@@ -244,7 +244,7 @@ function (instr::CondGotoInstruction)(tf::TapedFunction)
244244
end
245245

246246
function (instr::ReturnInstruction)(tf::TapedFunction)
247-
tf.retval = instr.arg
247+
tf.retval_binding_slot = instr.arg
248248
end
249249

250250
function (instr::NOOPInstruction)(tf::TapedFunction)
@@ -315,10 +315,10 @@ function allocate_binding!(var, tbind::TempBindings, ::Type{T}) where T
315315
end
316316

317317
function translate!(tape::RawTape, ir::Core.CodeInfo)
318-
bindings = Bindings()
319-
sizehint!(bindings, 128)
318+
binding_values = Bindings()
319+
sizehint!(binding_values, 128)
320320
bcache = Dict{IRVar, Int}()
321-
tbind = TempBindings(bindings, bcache)
321+
tbind = TempBindings(binding_values, bcache)
322322
slots = Dict{Int, Int}()
323323

324324
for (idx, line) in enumerate(ir.code)
@@ -330,11 +330,11 @@ function translate!(tape::RawTape, ir::Core.CodeInfo)
330330
for (k, v) in tbind.book
331331
isa(k, Core.SlotNumber) && (slots[k.id] = v)
332332
end
333-
arg_indices = fill(0, maximum(keys(slots)))
333+
arg_binding_slots = fill(0, maximum(keys(slots)))
334334
for (k, v) in slots
335-
arg_indices[k] = v
335+
arg_binding_slots[k] = v
336336
end
337-
return (bindings, arg_indices, tape)
337+
return (binding_values, arg_binding_slots, tape)
338338
end
339339

340340
function _const_instruction(var::IRVar, v, tbind::TempBindings, ir)
@@ -475,6 +475,6 @@ end
475475

476476
function Base.copy(tf::TapedFunction)
477477
new_tf = TapedFunction(tf)
478-
new_tf.bindings = copy_bindings(tf.bindings)
478+
new_tf.binding_values = copy_bindings(tf.binding_values)
479479
return new_tf
480480
end

src/tapedtask.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ function Base.copy(t::TapedTask; args=())
171171
args
172172
else
173173
if t.tf.counter > 1
174-
# the task is running, we find the real args from the copied bindings
174+
# the task is running, we find the real args from the copied binding_values
175175
map(1:length(t.args)) do i
176176
s = i + 1
177-
tf.arg_indices[s] > 0 ? tf.bindings[tf.arg_indices[s]] : t.args[i]
177+
tf.arg_binding_slots[s] > 0 ? tf.binding_values[tf.arg_binding_slots[s]] : t.args[i]
178178
end
179179
else
180180
# the task is not started yet, but no args is given

0 commit comments

Comments
 (0)