@@ -173,6 +173,39 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState)
173
173
return nothing
174
174
end
175
175
176
+ function finish! (interp:: AbstractInterpreter , mi:: MethodInstance , ci:: CodeInstance , src:: CodeInfo )
177
+ user_edges = src. edges
178
+ edges = user_edges isa SimpleVector ? user_edges : user_edges === nothing ? Core. svec () : Core. svec (user_edges... )
179
+ relocatability = 0x1
180
+ const_flag = false
181
+ di = src. debuginfo
182
+ rettype = Any
183
+ exctype = Any
184
+ rettype_const = nothing
185
+ const_flags = 0x0
186
+ ipo_effects = zero (UInt32)
187
+ min_world = src. min_world
188
+ max_world = src. max_world
189
+ if max_world >= get_world_counter ()
190
+ max_world = typemax (UInt)
191
+ end
192
+ if max_world == typemax (UInt)
193
+ # if we can record all of the backedges in the global reverse-cache,
194
+ # we can now widen our applicability in the global cache too
195
+ store_backedges (ci, edges)
196
+ end
197
+ ccall (:jl_fill_codeinst , Cvoid, (Any, Any, Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
198
+ ci, rettype, exctype, nothing , const_flags, min_world, max_world, ipo_effects, nothing , di, edges)
199
+ ccall (:jl_update_codeinst , Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, UInt8, Any, Any),
200
+ ci, nothing , const_flag, min_world, max_world, ipo_effects, nothing , relocatability, di, edges)
201
+ code_cache (interp)[mi] = ci
202
+ if isdefined (interp, :codegen )
203
+ interp. codegen[ci] = src
204
+ end
205
+ engine_reject (interp, ci)
206
+ return nothing
207
+ end
208
+
176
209
function finish_nocycle (:: AbstractInterpreter , frame:: InferenceState )
177
210
finishinfer! (frame, frame. interp)
178
211
opt = frame. result. src
@@ -826,7 +859,7 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
826
859
end
827
860
end
828
861
end
829
- if ccall (:jl_get_module_infer , Cint, (Any,), method. module) == 0 && ! generating_output ( #= incremental =# false )
862
+ if ccall (:jl_get_module_infer , Cint, (Any,), method. module) == 0
830
863
add_remark! (interp, caller, " [typeinf_edge] Inference is disabled for the target module" )
831
864
return Future (MethodCallResult (interp, caller, method, Any, Any, Effects (), nothing , edgecycle, edgelimited))
832
865
end
@@ -1096,15 +1129,6 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance, source_mod
1096
1129
end
1097
1130
end
1098
1131
def = mi. def
1099
- if isa (def, Method)
1100
- if ccall (:jl_get_module_infer , Cint, (Any,), def. module) == 0 && ! generating_output (#= incremental=# false )
1101
- src = retrieve_code_info (mi, get_inference_world (interp))
1102
- src isa CodeInfo || return nothing
1103
- return CodeInstance (mi, cache_owner (interp), Any, Any, nothing , src, Int32 (0 ),
1104
- get_inference_world (interp), get_inference_world (interp),
1105
- UInt32 (0 ), nothing , UInt8 (0 ), src. debuginfo, src. edges)
1106
- end
1107
- end
1108
1132
ci = engine_reserve (interp, mi)
1109
1133
# check cache again if it is still new after reserving in the engine
1110
1134
let code = get (code_cache (interp), mi, nothing )
@@ -1117,11 +1141,22 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance, source_mod
1117
1141
end
1118
1142
end
1119
1143
end
1144
+ if isa (def, Method) && ccall (:jl_get_module_infer , Cint, (Any,), def. module) == 0
1145
+ src = retrieve_code_info (mi, get_inference_world (interp))
1146
+ if src isa CodeInfo
1147
+ finish! (interp, mi, ci, src)
1148
+ else
1149
+ engine_reject (interp, ci)
1150
+ end
1151
+ ccall (:jl_typeinf_timing_end , Cvoid, (UInt64,), start_time)
1152
+ return ci
1153
+ end
1120
1154
result = InferenceResult (mi, typeinf_lattice (interp))
1121
1155
result. ci = ci
1122
1156
frame = InferenceState (result, #= cache_mode=# :global , interp)
1123
1157
if frame === nothing
1124
1158
engine_reject (interp, ci)
1159
+ ccall (:jl_typeinf_timing_end , Cvoid, (UInt64,), start_time)
1125
1160
return nothing
1126
1161
end
1127
1162
typeinf (interp, frame)
@@ -1263,18 +1298,29 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim::
1263
1298
callee in inspected && continue
1264
1299
push! (inspected, callee)
1265
1300
# now make sure everything has source code, if desired
1266
- # TODO : typeinf_code could return something with different edges/ages (needing an update to callee), which we don't handle here
1301
+ mi = get_ci_mi (callee)
1302
+ def = mi. def
1267
1303
if use_const_api (callee)
1268
- src = codeinfo_for_const (interp, callee . def , code. rettype_const)
1304
+ src = codeinfo_for_const (interp, mi , code. rettype_const)
1269
1305
elseif haskey (interp. codegen, callee)
1270
1306
src = interp. codegen[callee]
1307
+ elseif isa (def, Method) && ccall (:jl_get_module_infer , Cint, (Any,), def. module) == 0 && ! trim
1308
+ src = retrieve_code_info (mi, get_inference_world (interp))
1271
1309
else
1272
- src = typeinf_code (interp, callee. def, true )
1310
+ # TODO : typeinf_code could return something with different edges/ages/owner/abi (needing an update to callee), which we don't handle here
1311
+ src = typeinf_code (interp, mi, true )
1273
1312
end
1274
1313
if src isa CodeInfo
1275
1314
collectinvokes! (tocompile, src)
1315
+ # It is somewhat ambiguous if typeinf_ext might have callee in the caches,
1316
+ # but for the purpose of native compile, we always want them put there.
1317
+ if iszero (ccall (:jl_mi_cache_has_ci , Cint, (Any, Any), mi, callee))
1318
+ code_cache (interp)[mi] = callee
1319
+ end
1276
1320
push! (codeinfos, callee)
1277
1321
push! (codeinfos, src)
1322
+ elseif trim
1323
+ println (" warning: failed to get code for " , mi)
1278
1324
end
1279
1325
end
1280
1326
end
0 commit comments