@@ -68,7 +68,11 @@ function optimise_ir!(ir::IRCode; show_ir=false, do_inline=true)
6868
6969 ir = CC. compact! (ir)
7070 # CC.verify_ir(ir, true, false, CC.optimizer_lattice(local_interp))
71- CC. verify_linetable (ir. linetable, true )
71+ @static if VERSION >= v " 1.12-"
72+ CC. verify_linetable (ir. debuginfo, div (length (ir. debuginfo. codelocs), 3 ), true )
73+ else
74+ CC. verify_linetable (ir. linetable, true )
75+ end
7276 if show_ir
7377 println (" Post-optimization" )
7478 display (ir)
96100# Run type inference and constant propagation on the ir. Credit to @oxinabox:
97101# https://gist.github.com/oxinabox/cdcffc1392f91a2f6d80b2524726d802#file-example-jl-L54
98102function __infer_ir! (ir, interp:: CC.AbstractInterpreter , mi:: CC.MethodInstance )
99- method_info = CC. MethodInfo (true , nothing ) #= propagate_inbounds=#
100- min_world = world = get_inference_world (interp)
101- max_world = Base. get_world_counter ()
102- irsv = CC. IRInterpretationState (
103- interp, method_info, ir, mi, ir. argtypes, world, min_world, max_world
104- )
105- rt = CC. _ir_abstract_constant_propagation (interp, irsv)
103+ # TODO (mhauru) Why is this line here? This function is no longer defined in 1.12
104+ @static if VERSION >= v " 1.12-"
105+ nargs = length (ir. argtypes) - 1
106+ # TODO (mhauru) How do we figure out isva? I don't think it's in ir or mi, see above
107+ # prints.
108+ isva = false
109+ propagate_inbounds = true
110+ spec_info = CC. SpecInfo (nargs, isva, propagate_inbounds, nothing )
111+ min_world = world = get_inference_world (interp)
112+ max_world = Base. get_world_counter ()
113+ irsv = CC. IRInterpretationState (
114+ interp, spec_info, ir, mi, ir. argtypes, world, min_world, max_world
115+ )
116+ rt = CC. ir_abstract_constant_propagation (interp, irsv)
117+ else
118+ method_info = CC. MethodInfo (true , nothing ) #= propagate_inbounds=#
119+ min_world = world = get_inference_world (interp)
120+ max_world = Base. get_world_counter ()
121+ irsv = CC. IRInterpretationState (
122+ interp, method_info, ir, mi, ir. argtypes, world, min_world, max_world
123+ )
124+ rt = CC. _ir_abstract_constant_propagation (interp, irsv)
125+ end
106126 return ir
107127end
108128
@@ -168,13 +188,24 @@ function opaque_closure(
168188)
169189 # This implementation is copied over directly from `Core.OpaqueClosure`.
170190 ir = CC. copy (ir)
191+ @static if VERSION >= v " 1.12-"
192+ # On v1.12 OpaqueClosure expects the first arg to be the environment.
193+ ir. argtypes[1 ] = typeof (env)
194+ end
171195 nargs = length (ir. argtypes) - 1
172- sig = Base. Experimental. compute_oc_signature (ir, nargs, isva)
196+ @static if VERSION >= v " 1.12-"
197+ sig = CC. compute_oc_signature (ir, nargs, isva)
198+ else
199+ sig = Base. Experimental. compute_oc_signature (ir, nargs, isva)
200+ end
173201 src = ccall (:jl_new_code_info_uninit , Ref{CC. CodeInfo}, ())
174202 src. slotnames = fill (:none , nargs + 1 )
175203 src. slotflags = fill (zero (UInt8), length (ir. argtypes))
176204 src. slottypes = copy (ir. argtypes)
177205 src. rettype = ret_type
206+ @static if VERSION >= v " 1.12-"
207+ src. nargs = UInt (nargs + 1 )
208+ end
178209 src = CC. ir_to_codeinf! (src, ir)
179210 return Base. Experimental. generate_opaque_closure (
180211 sig, Union{}, ret_type, src, nargs, isva, env... ; do_compile
0 commit comments