Skip to content

Commit a301d00

Browse files
authored
Clarify the scope of @set and @local (#126)
This patch adds a clarification about the scope of the right hand sides of `@set` and `@local` right hand sides.
1 parent 4b91f66 commit a301d00

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/macros.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ keyword arguments. Among others, this includes
9090
9191
Settings like `ntasks`, `chunksize`, and `split` etc. can be used to tune the scheduling policy (if the selected scheduler supports it).
9292
93+
Note that the assignment is hoisted above the loop body which means that the scope is *not*
94+
the scope of the loop (even though it looks like it) but rather the scope *surrounding* the
95+
loop body. (`@macroexpand` is a useful tool to inspect the generated code of the `@tasks`
96+
block.)
9397
"""
9498
macro set(args...)
9599
error("The @set macro may only be used inside of a @tasks block.")
@@ -146,6 +150,12 @@ end
146150
# ...
147151
end
148152
```
153+
154+
The right hand side of the assignment is hoisted outside of the loop body and captured
155+
as a closure used to initialize the task local value. This means that the scope of the
156+
closure is *not* the scope of the loop (even though it looks like it) but rather the
157+
scope *surrounding* the loop body. (`@macroexpand` is a useful tool to inspect the
158+
generated code of the `@tasks` block.)
149159
"""
150160
macro $(Symbol("local"))(args...)
151161
error("The @local macro may only be used inside of a @tasks block.")

0 commit comments

Comments
 (0)