Skip to content

Commit d60f9b3

Browse files
Kenoaviatesk
andauthored
Refactor and pass correct interpreter to typeinf finish loop (#50469)
When we have an inference loop with different interpreters, the current code was trying to cache everything with the top level interpreter of the loop, yielding some unexpected behavior. I don't think that it's necessarily super well defined what should happen here, as it depends on the interpreters, in question, but I think it's better to try to cache each frame with the interpreter that created it, since they may have different lattices, etc. Doing this fixes an error I saw downstream that had just such a situation. --------- Co-authored-by: Shuhei Kadowaki <[email protected]>
1 parent e20274f commit d60f9b3

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

base/compiler/typeinfer.jl

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,33 +257,28 @@ function _typeinf(interp::AbstractInterpreter, frame::InferenceState)
257257
end
258258
for caller in frames
259259
caller.valid_worlds = valid_worlds
260-
finish(caller, interp)
260+
finish(caller, caller.interp)
261261
end
262-
# collect results for the new expanded frame
263-
results = Tuple{InferenceResult, Vector{Any}, Bool}[
264-
( frames[i].result,
265-
frames[i].stmt_edges[1]::Vector{Any},
266-
frames[i].cached )
267-
for i in 1:length(frames) ]
268-
empty!(frames)
269-
for (caller, _, _) in results
270-
opt = caller.src
271-
if opt isa OptimizationState{typeof(interp)} # implies `may_optimize(interp) === true`
272-
optimize(interp, opt, caller)
262+
for caller in frames
263+
opt = caller.result.src
264+
if opt isa OptimizationState # implies `may_optimize(caller.interp) === true`
265+
optimize(caller.interp, opt, caller.result)
273266
end
274267
end
275-
for (caller, edges, cached) in results
276-
valid_worlds = caller.valid_worlds
268+
for caller in frames
269+
(; result ) = caller
270+
valid_worlds = result.valid_worlds
277271
if last(valid_worlds) >= get_world_counter()
278272
# if we aren't cached, we don't need this edge
279273
# but our caller might, so let's just make it anyways
280-
store_backedges(caller, edges)
274+
store_backedges(result, caller.stmt_edges[1])
281275
end
282-
if cached
283-
cache_result!(interp, caller)
276+
if caller.cached
277+
cache_result!(caller.interp, result)
284278
end
285-
finish!(interp, caller)
279+
finish!(caller.interp, result)
286280
end
281+
empty!(frames)
287282
return true
288283
end
289284

0 commit comments

Comments
 (0)