Skip to content

Commit 3662ced

Browse files
authored
Merge pull request #325 from probcomp/sml-top-level
Note in docs that definitions of `(static)` generative functions and calls to `@load_generated_functions()` are supported as top-level expressions only
2 parents f4a422b + 4a8bf11 commit 3662ced

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

docs/src/ref/modeling.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,10 @@ This will produce a file `test.pdf` in the current working directory containing
426426

427427
### Restrictions
428428

429-
In order to be able to construct the static graph, Gen restricts the permitted syntax that can be used in functions annotated with `static`.
429+
First, the definition of a `(static)` generative function is always expected to occur as a [top-level definition](https://docs.julialang.org/en/v1/manual/modules/) (aka global variable); usage in non–top-level scopes is unsupported and may result in incorrect behavior.
430+
Recall also that the macro [`@load_generated_functions`](@ref) is expected to be called as a top-level expression only.
431+
432+
Next, in order to be able to construct the static graph, Gen restricts the permitted syntax that can be used in functions annotated with `static`.
430433
In particular, each statement in the body must be one of the following:
431434

432435
- A `@param` statement specifying any [Trainable parameters](@ref), e.g.:

src/Gen.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ end
2121
2222
Permit use of generative functions written in the static modeling language up
2323
to this point. Functions are loaded into the calling module.
24+
25+
This macro is intended to be called as a
26+
[top-level expression](https://docs.julialang.org/en/v1/manual/modules/)
27+
only; use in non–top-level scopes may result in incorrect behavior.
2428
"""
2529
macro load_generated_functions()
2630
for function_defn in generated_functions

0 commit comments

Comments
 (0)