@@ -12,6 +12,18 @@ function macroexpand(mod::Module, ex)
1212 ex1
1313end
1414
15+ function codeinfo_has_image_globalref (@nospecialize (e))
16+ if e isa GlobalRef
17+ return 0x00 != = @ccall jl_object_in_image (e. mod:: Any ):: UInt8
18+ elseif e isa Core. CodeInfo
19+ return any (codeinfo_has_image_globalref, e. code)
20+ elseif e isa Expr
21+ return any (codeinfo_has_image_globalref, e. args)
22+ else
23+ return false
24+ end
25+ end
26+
1527_CodeInfo_need_ver = v " 1.12.0-DEV.512"
1628if VERSION < _CodeInfo_need_ver
1729 function _CodeInfo (args... )
@@ -20,19 +32,29 @@ if VERSION < _CodeInfo_need_ver
2032else
2133 # debuginfo changed completely as of https://github.com/JuliaLang/julia/pull/52415
2234 # nargs / isva was added as of https://github.com/JuliaLang/julia/pull/54341
35+ # field rettype added in https://github.com/JuliaLang/julia/pull/54655
36+ # field has_image_globalref added in https://github.com/JuliaLang/julia/pull/57433
2337 # CodeInfo constructor. TODO : Should be in Core
2438 let
2539 fns = fieldnames (Core. CodeInfo)
2640 fts = fieldtypes (Core. CodeInfo)
2741 conversions = [:(convert ($ t, $ n)) for (t,n) in zip (fts, fns)]
2842
29- expected_fns = (:code , :debuginfo , :ssavaluetypes , :ssaflags , :slotnames , :slotflags , :slottypes , :parent , :method_for_inference_limit_heuristics , :edges , :min_world , :max_world , :nargs , :propagate_inbounds , :has_fcall , :nospecializeinfer , :isva , :inlining , :constprop , :purity , :inlining_cost )
30- expected_fts = (Vector{Any}, Core. DebugInfo, Any, Vector{UInt32}, Vector{Symbol}, Vector{UInt8}, Any, Any, Any, Any, UInt64, UInt64, UInt64, Bool, Bool, Bool, Bool, UInt8, UInt8, UInt16, UInt16)
43+ expected_fns = (:code , :debuginfo , :ssavaluetypes , :ssaflags , :slotnames , :slotflags , :slottypes , :rettype , :parent , :edges , :min_world , :max_world , :method_for_inference_limit_heuristics , : nargs , :propagate_inbounds , :has_fcall , :has_image_globalref , :nospecializeinfer , :isva , :inlining , :constprop , :purity , :inlining_cost )
44+ expected_fts = (Vector{Any}, Core. DebugInfo, Any, Vector{UInt32}, Vector{Symbol}, Vector{UInt8}, Any, Any, Any, Any, UInt64, UInt64, Any, UInt64, Bool , Bool, Bool, Bool, Bool, UInt8, UInt8, UInt16, UInt16)
3145
32- code = if fns != expected_fns || fts != expected_fts
46+ code = if fns != expected_fns
47+ unexpected_fns = collect (setdiff (Set (fns), Set (expected_fns)))
48+ missing_fns = collect (setdiff (Set (expected_fns), Set (fns)))
3349 :(function _CodeInfo (args... )
34- error (" Unrecognized CodeInfo layout: Maybe version $VERSION is to new for this version of JuliaLowering?" )
35- end )
50+ error (" Unrecognized CodeInfo fields: Maybe version $VERSION is too new for this version of JuliaLowering?"
51+ * isempty (unexpected_fns) ? " " : " \n Unexpected fields found: $($ unexpected_fns) "
52+ * isempty (missing_fns) ? " " : " \n Missing fields: $($ missing_fns) " )
53+ end )
54+ elseif fts != expected_fts
55+ :(function _CodeInfo (args... )
56+ error (" Unrecognized CodeInfo field types: Maybe version $VERSION is too new for this version of JuliaLowering?" )
57+ end )
3658 else
3759 :(function _CodeInfo ($ (fns... ))
3860 $ (Expr (:new , :(Core. CodeInfo), conversions... ))
@@ -142,6 +164,8 @@ function to_code_info(ex, mod, funcname, slots)
142164
143165 debuginfo = finish_ir_debug_info! (current_codelocs_stack)
144166
167+ has_image_globalref = any (codeinfo_has_image_globalref, stmts)
168+
145169 # TODO : Set ssaflags based on call site annotations:
146170 # - @inbounds annotations
147171 # - call site @inline / @noinline
@@ -172,6 +196,7 @@ function to_code_info(ex, mod, funcname, slots)
172196 max_world = typemax (Csize_t)
173197 isva = false
174198 inlining_cost = 0xffff
199+ rettype = Any
175200
176201 _CodeInfo (
177202 stmts,
@@ -181,14 +206,16 @@ function to_code_info(ex, mod, funcname, slots)
181206 slotnames,
182207 slotflags,
183208 slottypes,
209+ rettype,
184210 parent,
185- method_for_inference_limit_heuristics,
186211 edges,
187212 min_world,
188213 max_world,
214+ method_for_inference_limit_heuristics,
189215 nargs,
190216 propagate_inbounds,
191217 has_fcall,
218+ has_image_globalref,
192219 nospecializeinfer,
193220 isva,
194221 inlining,
0 commit comments