@@ -369,7 +369,11 @@ function rewrite_inst(inst, ir, interp, RT, guaranteed_error)
369369 end
370370 end
371371 if Meta. isexpr (inst, :invoke )
372- omi = inst. args[1 ]:: Core.MethodInstance
372+ omi = if inst. args[1 ] isa Core. MethodInstance
373+ inst. args[1 ]
374+ else
375+ (inst. args[1 ]:: Core.CodeInstance ). def
376+ end
373377 sig = omi. specTypes
374378 ft = sig. parameters[1 ]
375379 argsig = sig. parameters[2 : end ]
@@ -518,22 +522,42 @@ function make_oc_ref(
518522 if Base. isassigned (oc_captures)
519523 return oc_captures[]
520524 else
521- ores = ccall (
522- :jl_new_opaque_closure_from_code_info ,
523- Any,
524- (Any, Any, Any, Any, Any, Cint, Any, Cint, Cint, Any, Cint),
525- sig,
526- rt,
527- rt,
528- @__MODULE__ ,
529- src,
530- 0 ,
531- nothing ,
532- nargs,
533- isva,
534- f,
535- true ,
536- ):: Core.OpaqueClosure
525+ ores = @static if VERSION < v " 1.11"
526+ ccall (
527+ :jl_new_opaque_closure_from_code_info ,
528+ Any,
529+ (Any, Any, Any, Any, Any, Cint, Any, Cint, Cint, Any, Cint),
530+ sig,
531+ rt,
532+ rt,
533+ @__MODULE__ ,
534+ src,
535+ 0 ,
536+ nothing ,
537+ nargs,
538+ isva,
539+ f,
540+ true ,
541+ ):: Core.OpaqueClosure
542+ else
543+ ccall (
544+ :jl_new_opaque_closure_from_code_info ,
545+ Any,
546+ (Any, Any, Any, Any, Any, Cint, Any, Cint, Cint, Any, Cint, Cint),
547+ sig, # jl_tupletype_t *argt
548+ rt, # jl_value_t *rt_lb
549+ rt, # jl_value_t *rt_ub
550+ @__MODULE__ , # jl_module_t *mod
551+ src, # jl_code_info_t *ci
552+ 0 , # int lineno
553+ nothing , # jl_value_t *file
554+ nargs, # int nargs
555+ isva, # int isva
556+ f, # jl_value_t *env
557+ true , # int do_compile
558+ true , # int isinferred
559+ ):: Core.OpaqueClosure
560+ end
537561 oc_captures[] = ores
538562 return ores
539563 end
@@ -725,7 +749,9 @@ function call_with_reactant_generator(
725749 src. slotnames = fill (:none , length (ir. argtypes) + 1 )
726750 src. slotflags = fill (zero (UInt8), length (ir. argtypes))
727751 src. slottypes = copy (ir. argtypes)
728- src. rettype = rt
752+ @static if VERSION < v " 1.12.0-"
753+ src. rettype = rt
754+ end
729755 src = CC. ir_to_codeinf! (src, ir)
730756
731757 if DEBUG_INTERP[]
@@ -747,17 +773,31 @@ function call_with_reactant_generator(
747773 # and the REDUB_ARGUMENTS_NAME tuple of input arguments
748774 code_info. slotnames = Any[:call_with_reactant , REDUB_ARGUMENTS_NAME]
749775 code_info. slotflags = UInt8[0x00 , 0x00 ]
776+
777+ if VERSION >= v " 1.12-"
778+ code_info. nargs = length (code_info. slotnames)
779+ code_info. isva = true
780+ end
781+
750782 n_prepended_slots = 2
751783 overdub_args_slot = Core. SlotNumber (n_prepended_slots)
752784
753785 # For the sake of convenience, the rest of this pass will translate `code_info`'s fields
754786 # into these overdubbed equivalents instead of updating `code_info` in-place. Then, at
755787 # the end of the pass, we'll reset `code_info` fields accordingly.
756788 overdubbed_code = Any[]
757- overdubbed_codelocs = Int32[]
789+
790+ overdubbed_codelocs = @static if isdefined (Core, :DebugInfo )
791+ nothing
792+ else
793+ Int32[]
794+ end
795+
758796 function push_inst! (inst)
759797 push! (overdubbed_code, inst)
760- push! (overdubbed_codelocs, code_info. codelocs[1 ])
798+ @static if ! isdefined (Core, :DebugInfo )
799+ push! (overdubbed_codelocs, code_info. codelocs[1 ])
800+ end
761801 return Core. SSAValue (length (overdubbed_code))
762802 end
763803 # Rewire the arguments from our tuple input of fn and args, to the corresponding calling convention
@@ -781,6 +821,11 @@ function call_with_reactant_generator(
781821 iter_args = min (n_actual_args, n_method_args - 1 )
782822 end
783823
824+ if VERSION >= v " 1.12-"
825+ src. nargs = length (src. slottypes)
826+ src. isva = false
827+ end
828+
784829 for i in 1 : iter_args
785830 actual_argument = Expr (
786831 :call , Core. GlobalRef (Core, :getfield ), overdub_args_slot, offset
@@ -862,12 +907,9 @@ function call_with_reactant_generator(
862907 farg = nothing
863908 rep = Expr (:call , make_oc, dict, octup, rt, src, ocnargs, ocva, farg)
864909 push_inst! (rep)
865- Core. SSAValue (length (overdubbed_code))
866910 end
867911
868- push_inst! (Expr (:call , oc, fn_args[1 : end ]. .. ))
869-
870- ocres = Core. SSAValue (length (overdubbed_code))
912+ ocres = push_inst! (Expr (:call , oc, fn_args[1 : end ]. .. ))
871913
872914 if DEBUG_INTERP[]
873915 push_inst! (Expr (:call , safe_print, " ocres" , ocres))
@@ -882,7 +924,13 @@ function call_with_reactant_generator(
882924 end
883925
884926 code_info. code = overdubbed_code
885- code_info. codelocs = overdubbed_codelocs
927+
928+ @static if isdefined (Core, :DebugInfo )
929+ code_info. debuginfo = Core. DebugInfo (:none ) # Core.DebugInfoStream(overdubbed_codelocs), length(overdubbed_codelocs))
930+ else
931+ code_info. codelocs = overdubbed_codelocs
932+ end
933+
886934 code_info. ssavaluetypes = length (overdubbed_code)
887935 code_info. ssaflags = [0x00 for _ in 1 : length (overdubbed_code)] # XXX we need to copy flags that are set for the original code
888936
0 commit comments