@@ -12,6 +12,16 @@ 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+ else
21+ return false
22+ end
23+ end
24+
1525_CodeInfo_need_ver = v " 1.12.0-DEV.512"
1626if VERSION < _CodeInfo_need_ver
1727 function _CodeInfo (args... )
@@ -20,19 +30,29 @@ if VERSION < _CodeInfo_need_ver
2030else
2131 # debuginfo changed completely as of https://github.com/JuliaLang/julia/pull/52415
2232 # nargs / isva was added as of https://github.com/JuliaLang/julia/pull/54341
33+ # field rettype added in https://github.com/JuliaLang/julia/pull/54655
34+ # field has_image_globalref added in https://github.com/JuliaLang/julia/pull/57433
2335 # CodeInfo constructor. TODO : Should be in Core
2436 let
2537 fns = fieldnames (Core. CodeInfo)
2638 fts = fieldtypes (Core. CodeInfo)
2739 conversions = [:(convert ($ t, $ n)) for (t,n) in zip (fts, fns)]
2840
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)
41+ 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 )
42+ 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)
3143
32- code = if fns != expected_fns || fts != expected_fts
44+ code = if fns != expected_fns
45+ unexpected_fns = collect (setdiff (Set (fns), Set (expected_fns)))
46+ missing_fns = collect (setdiff (Set (expected_fns), Set (fns)))
3347 :(function _CodeInfo (args... )
34- error (" Unrecognized CodeInfo layout: Maybe version $VERSION is to new for this version of JuliaLowering?" )
35- end )
48+ error (" Unrecognized CodeInfo fields: Maybe version $VERSION is too new for this version of JuliaLowering?"
49+ * isempty (unexpected_fns) ? " " : " \n Unexpected fields found: $($ unexpected_fns) "
50+ * isempty (missing_fns) ? " " : " \n Missing fields: $($ missing_fns) " )
51+ end )
52+ elseif fts != expected_fts
53+ :(function _CodeInfo (args... )
54+ error (" Unrecognized CodeInfo field types: Maybe version $VERSION is too new for this version of JuliaLowering?" )
55+ end )
3656 else
3757 :(function _CodeInfo ($ (fns... ))
3858 $ (Expr (:new , :(Core. CodeInfo), conversions... ))
@@ -142,6 +162,8 @@ function to_code_info(ex, mod, funcname, slots)
142162
143163 debuginfo = finish_ir_debug_info! (current_codelocs_stack)
144164
165+ has_image_globalref = any (codeinfo_has_image_globalref, stmts)
166+
145167 # TODO : Set ssaflags based on call site annotations:
146168 # - @inbounds annotations
147169 # - call site @inline / @noinline
@@ -172,6 +194,7 @@ function to_code_info(ex, mod, funcname, slots)
172194 max_world = typemax (Csize_t)
173195 isva = false
174196 inlining_cost = 0xffff
197+ rettype = Any
175198
176199 _CodeInfo (
177200 stmts,
@@ -181,14 +204,16 @@ function to_code_info(ex, mod, funcname, slots)
181204 slotnames,
182205 slotflags,
183206 slottypes,
207+ rettype,
184208 parent,
185- method_for_inference_limit_heuristics,
186209 edges,
187210 min_world,
188211 max_world,
212+ method_for_inference_limit_heuristics,
189213 nargs,
190214 propagate_inbounds,
191215 has_fcall,
216+ has_image_globalref,
192217 nospecializeinfer,
193218 isva,
194219 inlining,
0 commit comments