11"""
2- get_dynamic_scope (T::Type)
2+ get_taped_globals (T::Type)
33
44Returns 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
77The type `T` is required for optimal performance. If you know that the result of this
88operation must return a specific type, specific `T`. If you do not know what type it will
99return, 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
5454end
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}
6868const 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
151151ways. For example, in the context of Sequential Monte Carlo, you might want the only
152152difference 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
156156to a given [`Libtask.TapedTask`](@ref). The former can be called inside a function:
157157```jldoctest sv
158158julia> 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
163163f (generic function with 1 method)
164164```
165165
166166The 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
169169julia> t = TapedTask(1, f);
170170
@@ -174,20 +174,20 @@ julia> consume(t)
174174
175175The 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
179179julia> consume(t)
1801802
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)
191191end
192192
193193function fresh_copy (mc:: T ) where {T<: MistyClosure }
@@ -206,16 +206,14 @@ function fresh_copy(mc::T) where {T<:MistyClosure}
206206end
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
220218end
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
242240end
0 commit comments