Skip to content

Commit 2907f03

Browse files
committed
Document type assertion
1 parent ebe8f91 commit 2907f03

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: src/copyable_task.jl

+14-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@ operation must return a specific type, specific `T`. If you do not know what typ
99
return, pass `Any` -- this will typically yield type instabilities, but will run correctly.
1010
1111
See also [`set_taped_globals!`](@ref).
12+
13+
# Extended Help
14+
15+
1216
"""
13-
@noinline get_taped_globals(::Type{T}) where {T} =
14-
typeassert(task_local_storage(:task_variable), T)
17+
@noinline function get_taped_globals(::Type{T}) where {T}
18+
# This function is `@noinline`d to ensure that the type-unstable items in here do not
19+
# appear in a calling function, and cause allocations.
20+
#
21+
# The return type of `task_local_storage(:task_variable)` is `Any`. To ensure that this
22+
# type instability does not propagate through the rest of the code, we `typeassert` the
23+
# result to be `T`. By doing this, callers of this function will (hopefully) think
24+
# carefully about how they can figure out what type they have put in global storage.
25+
return typeassert(task_local_storage(:task_variable), T)
26+
end
1527

1628
__v::Int = 5
1729

0 commit comments

Comments
 (0)