Skip to content

Commit 730d046

Browse files
committed
mock out early generator expansion in inference [ci skip]
1 parent f1b90b2 commit 730d046

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

base/inference.jl

+19-8
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,12 @@ function InferenceState(linfo::MethodInstance,
305305
end
306306

307307
function get_staged(li::MethodInstance)
308-
return ccall(:jl_code_for_staged, Any, (Any,), li)::CodeInfo
308+
try
309+
# user code might throw errors – ignore them
310+
return ccall(:jl_code_for_staged, Any, (Any,), li)::CodeInfo
311+
catch
312+
return nothing
313+
end
309314
end
310315

311316

@@ -405,12 +410,7 @@ end
405410
function retrieve_code_info(linfo::MethodInstance)
406411
m = linfo.def::Method
407412
if isdefined(m, :generator)
408-
try
409-
# user code might throw errors – ignore them
410-
c = get_staged(linfo)
411-
catch
412-
return nothing
413-
end
413+
return get_staged(linfo)
414414
else
415415
# TODO: post-inference see if we can swap back to the original arrays?
416416
if isa(m.source, Array{UInt8,1})
@@ -1922,6 +1922,17 @@ function abstract_call_method(method::Method, @nospecialize(f), @nospecialize(si
19221922
# Returns the topmost occurrence of that repeated edge.
19231923
cyclei = 0
19241924
infstate = sv
1925+
if isdefined(method, :generator) && method.generator.expand_early
1926+
method_instance = code_for_method(method, sig, sparams, sv.params.world, false)
1927+
if isa(method_instance, MethodInstance)
1928+
cinfo = get_staged(method_instance)
1929+
if isa(cinfo, CodeInfo) && isa(cinfo.method_for_inference_heuristics, Method)
1930+
checked_method = cinfo.method_for_inference_heuristics
1931+
end
1932+
end
1933+
else
1934+
checked_method = method
1935+
end
19251936
while !(infstate === nothing)
19261937
infstate = infstate::InferenceState
19271938
if method === infstate.linfo.def && infstate.linfo.specTypes == sig
@@ -1931,7 +1942,7 @@ function abstract_call_method(method::Method, @nospecialize(f), @nospecialize(si
19311942
break
19321943
end
19331944
working_method = method_for_inference_heuristics(infstate)
1934-
if method === working_method
1945+
if checked_method === working_method
19351946
if topmost === nothing
19361947
# inspect the parent of this edge,
19371948
# to see if they are the same Method as sv

0 commit comments

Comments
 (0)