Skip to content

Commit

Permalink
Clarify the scope of @set and @local
Browse files Browse the repository at this point in the history
This patch adds a clarification about the scope of the right hand sides
of `@set` and `@local` right hand sides.
  • Loading branch information
fredrikekre committed Sep 26, 2024
1 parent 491dac9 commit 2c6c0ea
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ keyword arguments. Among others, this includes
Settings like `ntasks`, `chunksize`, and `split` etc. can be used to tune the scheduling policy (if the selected scheduler supports it).
Note that the assignment is hoisted above the loop body which means that the scope is *not*
the scope of the loop (even though it looks like it) but rather the scope *surrounding* the
loop body. (`@macroexpand` is a useful tool to inspect the generated code of the `@tasks`
block.)
"""
macro set(args...)
error("The @set macro may only be used inside of a @tasks block.")
Expand Down Expand Up @@ -146,6 +150,12 @@ end
# ...
end
```
The right hand side of the assignment is hoisted outside of the loop body and captured
as a closure used to initialize the task local value. This means that the scope of the
closure is *not* the scope of the loop (even though it looks like it) but rather the
scope *surrounding* the loop body. (`@macroexpand` is a useful tool to inspect the
generated code of the `@tasks` block.)
"""
macro $(Symbol("local"))(args...)
error("The @local macro may only be used inside of a @tasks block.")
Expand Down

0 comments on commit 2c6c0ea

Please sign in to comment.