Skip to content

Commit 310f6f5

Browse files
committed
Fixes to opaque_closure
Copied over from chalk-lab/Mooncake.jl#714
1 parent 8d6ed7e commit 310f6f5

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/utils.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,8 @@ function opaque_closure(
189189
# This implementation is copied over directly from `Core.OpaqueClosure`.
190190
ir = CC.copy(ir)
191191
@static if VERSION >= v"1.12-"
192-
ir.debuginfo.def === nothing &&
193-
(ir.debuginfo.def = :var"generated IR for OpaqueClosure")
194192
# On v1.12 OpaqueClosure expects the first arg to be the environment.
195-
# ir.argtypes[1] = typeof(env)
196-
# TODO(mhauru) However, there was a bug in this new treatment of argtypes
197-
# (https://github.com/JuliaLang/julia/issues/59222) the fix for which did not make
198-
# it to v1.12.0, so for now we need to use the below workaround.
199-
ir.argtypes[1] = Tuple
193+
ir.argtypes[1] = typeof(env)
200194
end
201195
nargtypes = length(ir.argtypes)
202196
nargs = nargtypes - 1
@@ -206,15 +200,19 @@ function opaque_closure(
206200
sig = Base.Experimental.compute_oc_signature(ir, nargs, isva)
207201
end
208202
src = ccall(:jl_new_code_info_uninit, Ref{CC.CodeInfo}, ())
209-
src.slotnames = fill(:none, nargtypes)
203+
src.slotnames = [Symbol(:_, i) for i in 1:nargtypes]
210204
src.slotflags = fill(zero(UInt8), nargtypes)
211205
src.slottypes = copy(ir.argtypes)
212-
src.rettype = ret_type
213-
@static if VERSION >= v"1.12-"
206+
@static if VERSION > v"1.12-"
207+
ir.debuginfo.def === nothing &&
208+
(ir.debuginfo.def = :var"generated IR for OpaqueClosure")
209+
src.min_world = ir.valid_worlds.min_world
210+
src.max_world = ir.valid_worlds.max_world
214211
src.isva = isva
215-
src.nargs = UInt(nargs + 1)
212+
src.nargs = nargtypes
216213
end
217214
src = CC.ir_to_codeinf!(src, ir)
215+
src.rettype = ret_type
218216
return Base.Experimental.generate_opaque_closure(
219217
sig, Union{}, ret_type, src, nargs, isva, env...; do_compile
220218
)::Core.OpaqueClosure{sig,ret_type}

0 commit comments

Comments
 (0)