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,8 +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" ))
58
+ if opaque_closures
61
59
body = closures_to_opaque (body)
62
60
end
63
61
id = expr_to_id (body)
@@ -306,7 +304,8 @@ function closures_to_opaque(ex::Expr, return_type = nothing)
306
304
fdef[:body ] = body
307
305
name = get (fdef, :name , nothing )
308
306
name != = nothing && delete! (fdef, :name )
309
- _ex = Expr (:opaque_closure , combinedef (fdef))
307
+ opaque = Expr (:., Expr (:., :Base , QuoteNode (:Experimental )), QuoteNode (Symbol (" @opaque" )))
308
+ _ex = Expr (:macrocall , opaque, LineNumberNode (0 ), combinedef (fdef))
310
309
# TODO : emit named opaque closure for better stacktraces
311
310
# (ref https://github.com/JuliaLang/julia/pull/40242)
312
311
if name != = nothing
0 commit comments