Skip to content

Commit 65c5453

Browse files
Merge pull request #96 from SciML/os/fix-opaque-generation
try fixing opaque_closure generation on 1.12
2 parents 45e61a5 + 11763e5 commit 65c5453

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/RuntimeGeneratedFunctions.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module RuntimeGeneratedFunctions
22

33
using ExprTools, Serialization, SHA
4+
import Base.Experimental: @opaque
45

56
export RuntimeGeneratedFunction, @RuntimeGeneratedFunction, drop_expr
67

@@ -34,9 +35,7 @@ If `opaque_closures` is `true`, all closures in `function_expression` are
3435
converted to
3536
[opaque closures](https://github.com/JuliaLang/julia/pull/37849#issue-496641229).
3637
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.
4039
# Examples
4140
```
4241
RuntimeGeneratedFunctions.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

Comments
 (0)