From 2c6c0eabd5bfe57a97a0fa12ea06f8ffd477359d Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Thu, 26 Sep 2024 23:25:33 +0200 Subject: [PATCH] Clarify the scope of `@set` and `@local` This patch adds a clarification about the scope of the right hand sides of `@set` and `@local` right hand sides. --- src/macros.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/macros.jl b/src/macros.jl index 92d77a45..e47ecd76 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -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.") @@ -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.")