11module RuntimeGeneratedFunctions
22
33using ExprTools, Serialization, SHA
4+ import Base. Experimental: @opaque
45
56export RuntimeGeneratedFunction, @RuntimeGeneratedFunction , drop_expr
67
@@ -34,9 +35,7 @@ If `opaque_closures` is `true`, all closures in `function_expression` are
3435converted to
3536[opaque closures](https://github.com/JuliaLang/julia/pull/37849#issue-496641229).
3637This 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.
4039# Examples
4140```
4241RuntimeGeneratedFunctions.init(@__MODULE__) # Required at module top-level
@@ -56,8 +55,7 @@ struct RuntimeGeneratedFunction{argnames, cache_tag, context_tag, id, B} <: Func
5655 def = splitdef (ex)
5756 args = normalize_args (get (def, :args , Symbol[]))
5857 body = def[:body ]
59- if opaque_closures && isdefined (Base, :Experimental ) &&
60- isdefined (Base. Experimental, Symbol (" @opaque" ))
58+ if opaque_closures
6159 body = closures_to_opaque (body)
6260 end
6361 id = expr_to_id (body)
@@ -306,7 +304,8 @@ function closures_to_opaque(ex::Expr, return_type = nothing)
306304 fdef[:body ] = body
307305 name = get (fdef, :name , nothing )
308306 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))
310309 # TODO : emit named opaque closure for better stacktraces
311310 # (ref https://github.com/JuliaLang/julia/pull/40242)
312311 if name != = nothing
0 commit comments