1
1
module RuntimeGeneratedFunctions
2
2
3
3
using ExprTools, Serialization, SHA
4
+ import Base. Experimental: @opaque
4
5
5
6
export RuntimeGeneratedFunction, @RuntimeGeneratedFunction , drop_expr
6
7
@@ -34,9 +35,7 @@ If `opaque_closures` is `true`, all closures in `function_expression` are
34
35
converted to
35
36
[opaque closures](https://github.com/JuliaLang/julia/pull/37849#issue-496641229).
36
37
This allows for the use of closures and generators inside the generated function,
37
- but may not work in all cases due to slightly different semantics. This feature
38
- requires Julia 1.7.
39
-
38
+ but may not work in all cases due to slightly different semantics.
40
39
# Examples
41
40
```
42
41
RuntimeGeneratedFunctions.init(@__MODULE__) # Required at module top-level
@@ -56,10 +55,7 @@ struct RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id, B} <: Func
56
55
def = splitdef (ex)
57
56
args = normalize_args (get (def, :args , Symbol[]))
58
57
body = def[:body ]
59
- if opaque_closures && isdefined (Base, :Experimental ) &&
60
- isdefined (Base. Experimental, Symbol (" @opaque" ))
61
- body = closures_to_opaque (body)
62
- end
58
+ body = closures_to_opaque (body)
63
59
id = expr_to_id (body)
64
60
cached_body = _cache_body (cache_tag, id, body)
65
61
new {Tuple(args), cache_tag, context_tag, id, typeof(cached_body)} (cached_body)
@@ -306,7 +302,8 @@ function closures_to_opaque(ex::Expr, return_type = nothing)
306
302
fdef[:body ] = body
307
303
name = get (fdef, :name , nothing )
308
304
name != = nothing && delete! (fdef, :name )
309
- _ex = Expr (:macrocall , Symbol (" @opaque" ), LineNumberNode (0 ), combinedef (fdef))
305
+ opaque = Expr (:., Expr (:., :Base , QuoteNode (:Experimental )), QuoteNode (Symbol (" @opaque" )))
306
+ _ex = Expr (:macrocall , opaque, LineNumberNode (0 ), combinedef (fdef))
310
307
# TODO : emit named opaque closure for better stacktraces
311
308
# (ref https://github.com/JuliaLang/julia/pull/40242)
312
309
if name != = nothing
0 commit comments