Skip to content

Commit aa86594

Browse files
committed
Docs and tidy up
1 parent b42227e commit aa86594

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ First, manipulation of [`TapedTask`](@ref)s:
1414
```@docs; canonical=true
1515
Libtask.consume
1616
Base.copy(::Libtask.TapedTask)
17-
Libtask.set_dynamic_scope!
17+
Libtask.set_taped_globals!
1818
```
1919

2020
Functions for use inside a [`TapedTask`](@ref)s are:
2121
```@docs; canonical=true
2222
Libtask.produce
23-
Libtask.get_dynamic_scope
23+
Libtask.get_taped_globals
2424
```

src/Libtask.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ using Core.Compiler: Argument, IRCode, ReturnNode
1616
include("copyable_task.jl")
1717
include("test_utils.jl")
1818

19-
export TapedTask, consume, produce, get_dynamic_scope, set_dynamic_scope!
19+
export TapedTask, consume, produce, get_taped_globals, set_taped_globals!
2020

2121
end

src/copyable_task.jl

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""
2-
get_dynamic_scope(T::Type)
2+
get_taped_globals(T::Type)
33
44
Returns the dynamic scope associated to `Libtask`. If called from inside a `TapedTask`, this
5-
will return whatever is contained in its `dynamic_scope` field.
5+
will return whatever is contained in its `taped_globals` field.
66
77
The type `T` is required for optimal performance. If you know that the result of this
88
operation must return a specific type, specific `T`. If you do not know what type it will
99
return, pass `Any` -- this will typically yield type instabilities, but will run correctly.
1010
11-
See also [`set_dynamic_scope!`](@ref).
11+
See also [`set_taped_globals!`](@ref).
1212
"""
13-
get_dynamic_scope(::Type{T}) where {T} = typeassert(task_local_storage(:task_variable), T)
13+
get_taped_globals(::Type{T}) where {T} = typeassert(task_local_storage(:task_variable), T)
1414

1515
__v::Int = 5
1616

@@ -53,8 +53,8 @@ function build_callable(sig::Type{<:Tuple})
5353
end
5454
end
5555

56-
mutable struct TapedTask{Tdynamic_scope,Tfargs,Tmc<:MistyClosure}
57-
dynamic_scope::Tdynamic_scope
56+
mutable struct TapedTask{Ttaped_globals,Tfargs,Tmc<:MistyClosure}
57+
taped_globals::Ttaped_globals
5858
const fargs::Tfargs
5959
const mc::Tmc
6060
const position::Base.RefValue{Int32}
@@ -68,10 +68,10 @@ end
6868
const mc_cache = Dict{CacheKey,MistyClosure}()
6969

7070
"""
71-
TapedTask(dynamic_scope::Any, f, args...; kwargs...)
71+
TapedTask(taped_globals::Any, f, args...; kwargs...)
7272
73-
Construct a `TapedTask` with the specified `dynamic_scope`, for function `f` and positional
74-
arguments `args`.
73+
Construct a `TapedTask` with the specified `taped_globals`, for function `f`, positional
74+
arguments `args`, and keyword argument `kwargs`.
7575
7676
# Extended Help
7777
@@ -151,20 +151,20 @@ It is often desirable to permit a copy of a task and the original to differ in v
151151
ways. For example, in the context of Sequential Monte Carlo, you might want the only
152152
difference between two copies to be their random number generator.
153153
154-
A generic mechanism is available to achieve this. [`Libtask.get_dynamic_scope`](@ref) and
155-
[`Libtask.set_dynamic_scope!`](@ref) let you set and retrieve a variable which is specific
154+
A generic mechanism is available to achieve this. [`Libtask.get_taped_globals`](@ref) and
155+
[`Libtask.set_taped_globals!`](@ref) let you set and retrieve a variable which is specific
156156
to a given [`Libtask.TapedTask`](@ref). The former can be called inside a function:
157157
```jldoctest sv
158158
julia> function f()
159-
produce(get_dynamic_scope(Int))
160-
produce(get_dynamic_scope(Int))
159+
produce(get_taped_globals(Int))
160+
produce(get_taped_globals(Int))
161161
return nothing
162162
end
163163
f (generic function with 1 method)
164164
```
165165
166166
The first argument to [`Libtask.TapedTask`](@ref) is the value that
167-
[`Libtask.get_dynamic_scope`](@ref) will return:
167+
[`Libtask.get_taped_globals`](@ref) will return:
168168
```jldoctest sv
169169
julia> t = TapedTask(1, f);
170170
@@ -174,20 +174,20 @@ julia> consume(t)
174174
175175
The value that it returns can be changed between [`Libtask.consume`](@ref) calls:
176176
```jldoctest sv
177-
julia> set_dynamic_scope!(t, 2)
177+
julia> set_taped_globals!(t, 2)
178178
179179
julia> consume(t)
180180
2
181181
```
182182
183183
`Int`s have been used here, but it is permissible to set the value returned by
184-
[`Libtask.get_dynamic_scope`](@ref) to anything you like.
184+
[`Libtask.get_taped_globals`](@ref) to anything you like.
185185
"""
186-
function TapedTask(dynamic_scope::Any, fargs...; kwargs...)
186+
function TapedTask(taped_globals::Any, fargs...; kwargs...)
187187
all_args = isempty(kwargs) ? fargs : (Core.kwcall, getfield(kwargs, :data), fargs...)
188188
seed_id!()
189189
mc, count_ref = build_callable(typeof(all_args))
190-
return TapedTask(dynamic_scope, all_args, mc, count_ref)
190+
return TapedTask(taped_globals, all_args, mc, count_ref)
191191
end
192192

193193
function fresh_copy(mc::T) where {T<:MistyClosure}
@@ -206,16 +206,14 @@ function fresh_copy(mc::T) where {T<:MistyClosure}
206206
end
207207

208208
"""
209-
set_dynamic_scope!(t::TapedTask, new_dynamic_scope)::Nothing
209+
set_taped_globals!(t::TapedTask, new_taped_globals)::Nothing
210210
211-
Set the `dynamic_scope` of `t` to `new_dynamic_scope`. Any references to
212-
`LibTask.dynamic_scope` in future calls to `consume(t)` (either directly, or implicitly via
213-
iteration) will see this new value.
214-
215-
See also: [`get_dynamic_scope`](@ref).
211+
Set the `taped_globals` of `t` to `new_taped_globals`. Any calls to
212+
[`get_taped_globals`](@ref) in future calls to `consume(t)` (either directly, or implicitly
213+
via iteration) will see this new value.
216214
"""
217-
function set_dynamic_scope!(t::TapedTask{T}, new_dynamic_scope::T)::Nothing where {T}
218-
t.dynamic_scope = new_dynamic_scope
215+
function set_taped_globals!(t::TapedTask{T}, new_taped_globals::T)::Nothing where {T}
216+
t.taped_globals = new_taped_globals
219217
return nothing
220218
end
221219

@@ -236,7 +234,7 @@ called, it start execution from the entry point. If `consume` has previously bee
236234
`nothing` will be returned.
237235
"""
238236
@inline function consume(t::TapedTask)
239-
task_local_storage(:task_variable, t.dynamic_scope)
237+
task_local_storage(:task_variable, t.taped_globals)
240238
v = t.mc.oc(t.fargs...)
241239
return v isa ProducedValue ? v[] : nothing
242240
end

src/test_utils.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313

1414
struct Testcase
1515
name::String
16-
dynamic_scope::Any
16+
taped_globals::Any
1717
fargs::Tuple
1818
kwargs::Union{NamedTuple,Nothing}
1919
expected_iteration_results::Vector
@@ -28,9 +28,9 @@ function (case::Testcase)()
2828

2929
# Construct the task.
3030
if case.kwargs === nothing
31-
t = TapedTask(case.dynamic_scope, case.fargs...)
31+
t = TapedTask(case.taped_globals, case.fargs...)
3232
else
33-
t = TapedTask(case.dynamic_scope, case.fargs...; case.kwargs...)
33+
t = TapedTask(case.taped_globals, case.fargs...; case.kwargs...)
3434
end
3535

3636
# Iterate through t. Record the results, and take a copy after each iteration.
@@ -54,9 +54,9 @@ function (case::Testcase)()
5454

5555
# Construct the task.
5656
if case.kwargs === nothing
57-
t = TapedTask(case.dynamic_scope, case.fargs...)
57+
t = TapedTask(case.taped_globals, case.fargs...)
5858
else
59-
t = TapedTask(case.dynamic_scope, case.fargs...; case.kwargs...)
59+
t = TapedTask(case.taped_globals, case.fargs...; case.kwargs...)
6060
end
6161

6262
for _ in iteration_results
@@ -139,8 +139,8 @@ function test_cases()
139139
[Ptr{UInt8}, Ptr{UInt8}],
140140
allocs,
141141
),
142-
Testcase("dynamic scope 1", 5, (dynamic_scope_tester_1,), nothing, [5], allocs),
143-
Testcase("dynamic scope 2", 6, (dynamic_scope_tester_1,), nothing, [6], none),
142+
Testcase("dynamic scope 1", 5, (taped_globals_tester_1,), nothing, [5], allocs),
143+
Testcase("dynamic scope 2", 6, (taped_globals_tester_1,), nothing, [6], none),
144144
Testcase(
145145
"nested (static)", nothing, (static_nested_outer,), nothing, [true, false], none
146146
),
@@ -286,8 +286,8 @@ function foreigncall_tester(s::String)
286286
return nothing
287287
end
288288

289-
function dynamic_scope_tester_1()
290-
produce(Libtask.get_dynamic_scope(Int))
289+
function taped_globals_tester_1()
290+
produce(Libtask.get_taped_globals(Int))
291291
return nothing
292292
end
293293

test/copyable_task.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
for case in Libtask.TestUtils.test_cases()
33
case()
44
end
5-
@testset "set_dynamic_scope" begin
5+
@testset "set_taped_globals!" begin
66
function f()
7-
produce(Libtask.get_dynamic_scope(Int))
8-
produce(Libtask.get_dynamic_scope(Int))
7+
produce(Libtask.get_taped_globals(Int))
8+
produce(Libtask.get_taped_globals(Int))
99
return nothing
1010
end
1111
t = TapedTask(5, f)
1212
@test consume(t) == 5
13-
Libtask.set_dynamic_scope!(t, 6)
13+
Libtask.set_taped_globals!(t, 6)
1414
@test consume(t) == 6
1515
@test consume(t) === nothing
1616
end

0 commit comments

Comments
 (0)