Skip to content

Commit 2b140ba

Browse files
committed
Allow opting out of PartialOpaque support via Expr(:opaque_closure, ...)
1 parent ed987f2 commit 2b140ba

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

base/opaque_closure.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ the argument type may be fixed length even if the function is variadic.
1818
This interface is experimental and subject to change or removal without notice.
1919
"""
2020
macro opaque(ex)
21-
esc(Expr(:opaque_closure, nothing, nothing, nothing, ex))
21+
esc(Expr(:opaque_closure, nothing, nothing, nothing, #= allow_partial =# true, ex))
2222
end
2323

2424
macro opaque(ty, ex)
@@ -34,7 +34,7 @@ macro opaque(ty, ex)
3434
end
3535
AT = (AT !== :_) ? AT : nothing
3636
RT = (RT !== :_) ? RT : nothing
37-
return esc(Expr(:opaque_closure, AT, RT, RT, ex))
37+
return esc(Expr(:opaque_closure, AT, RT, RT, #= allow_partial =# true, ex))
3838
end
3939

4040
# OpaqueClosure construction from pre-inferred CodeInfo/IRCode

src/julia-syntax.scm

+6-4
Original file line numberDiff line numberDiff line change
@@ -2435,7 +2435,8 @@
24352435
(let* ((argt (something (list (expand-forms (cadr e)) #f)))
24362436
(rt_lb (something (list (expand-forms (caddr e)) #f)))
24372437
(rt_ub (something (list (expand-forms (cadddr e)) #f)))
2438-
(F (caddddr e))
2438+
(allow-partial (caddddr e))
2439+
(F (cadddddr e))
24392440
(isva (let* ((arglist (function-arglist F))
24402441
(lastarg (and (pair? arglist) (last arglist))))
24412442
(if (and argt (any (lambda (arg)
@@ -2460,7 +2461,7 @@
24602461
(let* ((argtype (foldl (lambda (var ex) `(call (core UnionAll) ,var ,ex))
24612462
(expand-forms `(curly (core Tuple) ,@argtypes))
24622463
(reverse tvars))))
2463-
`(_opaque_closure ,(or argt argtype) ,rt_lb ,rt_ub ,isva ,(length argtypes) ,functionloc ,lam))))
2464+
`(_opaque_closure ,(or argt argtype) ,rt_lb ,rt_ub ,isva ,(length argtypes) ,allow-partial ,functionloc ,lam))))
24642465

24652466
'block
24662467
(lambda (e)
@@ -4028,7 +4029,8 @@ f(x) = yt(x)
40284029
((_opaque_closure)
40294030
(let* ((isva (car (cddddr e)))
40304031
(nargs (cadr (cddddr e)))
4031-
(functionloc (caddr (cddddr e)))
4032+
(allow-partial (caddr (cddddr e)))
4033+
(functionloc (cadddr (cddddr e)))
40324034
(lam2 (last e))
40334035
(vis (lam:vinfo lam2))
40344036
(cvs (map car (cadr vis))))
@@ -4040,7 +4042,7 @@ f(x) = yt(x)
40404042
v)))
40414043
cvs)))
40424044
`(new_opaque_closure
4043-
,(cadr e) ,(or (caddr e) '(call (core apply_type) (core Union))) ,(or (cadddr e) '(core Any)) (true)
4045+
,(cadr e) ,(or (caddr e) '(call (core apply_type) (core Union))) ,(or (cadddr e) '(core Any)) ,allow-partial
40444046
(opaque_closure_method (null) ,nargs ,isva ,functionloc ,(convert-lambda lam2 (car (lam:args lam2)) #f '() (symbol-to-idx-map cvs)))
40454047
,@var-exprs))))
40464048
((method)

test/precompile.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,13 @@ precompile_test_harness("Generated Opaque") do load_path
19951995
Expr(:opaque_closure_method, nothing, 0, false, lno, ci))
19961996
end
19971997
@assert oc_re_generated_no_partial()() === 1
1998+
@generated function oc_re_generated_no_partial_macro()
1999+
AT = nothing
2000+
RT = nothing
2001+
allow_partial = false # makes this legal to generate during pre-compile
2002+
return Expr(:opaque_closure, AT, RT, RT, allow_partial, :(()->const_int_barrier()))
2003+
end
2004+
@assert oc_re_generated_no_partial_macro()() === 1
19982005
end
19992006
""")
20002007
Base.compilecache(Base.PkgId("GeneratedOpaque"))

0 commit comments

Comments
 (0)