@@ -4,7 +4,7 @@ using ExprTools, Serialization, SHA
44
55export RuntimeGeneratedFunction, @RuntimeGeneratedFunction
66
7- """
7+ const _rgf_docs = """
88 @RuntimeGeneratedFunction(function_expression)
99 @RuntimeGeneratedFunction(context_module, function_expression, opaque_closures=true)
1010
@@ -48,6 +48,8 @@ function foo()
4848end
4949```
5050"""
51+
52+ " $_rgf_docs "
5153struct RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id} <: Function
5254 body:: Expr
5355 function RuntimeGeneratedFunction (cache_tag, context_tag, ex; opaque_closures = true )
@@ -91,50 +93,7 @@ function RuntimeGeneratedFunction(cache_module::Module, context_module::Module,
9193 opaque_closures = opaque_closures)
9294end
9395
94- """
95- @RuntimeGeneratedFunction(function_expression)
96- @RuntimeGeneratedFunction(context_module, function_expression, opaque_closures=true)
97-
98- RuntimeGeneratedFunction(cache_module, context_module, function_expression; opaque_closures=true)
99-
100- Construct a function from `function_expression` which can be called immediately
101- without world age problems. Somewhat like using `eval(function_expression)` and
102- then calling the resulting function. The differences are:
103-
104- * The result can be called immediately (immune to world age errors)
105- * The result is not a named generic function, and doesn't participate in
106- generic function dispatch; it's more like a callable method.
107-
108- You need to use `RuntimeGeneratedFunctions.init(your_module)` a single time at
109- the top level of `your_module` before any other uses of the macro.
110-
111- If provided, `context_module` is module in which symbols within
112- `function_expression` will be looked up. By default this is module in which
113- `@RuntimeGeneratedFunction` is expanded.
114-
115- `cache_module` is the module where the expression `code` will be cached. If
116- `RuntimeGeneratedFunction` is used during precompilation, this must be a module
117- which is currently being precompiled. Normally this would be set to
118- `@__MODULE__` using one of the macro constructors.
119-
120- If `opaque_closures` is `true`, all closures in `function_expression` are
121- converted to
122- [opaque closures](https://github.com/JuliaLang/julia/pull/37849#issue-496641229).
123- This allows for the use of closures and generators inside the generated function,
124- but may not work in all cases due to slightly different semantics. This feature
125- requires Julia 1.7.
126-
127- # Examples
128- ```
129- RuntimeGeneratedFunctions.init(@__MODULE__) # Required at module top-level
130-
131- function foo()
132- expression = :((x,y)->x+y+1) # May be generated dynamically
133- f = @RuntimeGeneratedFunction(expression)
134- f(1,2) # May be called immediately
135- end
136- ```
137- """
96+ " $_rgf_docs "
13897macro RuntimeGeneratedFunction (code)
13998 quote
14099 RuntimeGeneratedFunction (@__MODULE__ , @__MODULE__ , $ (esc (code)))
0 commit comments