@@ -16,8 +16,25 @@ const _REF_NAME = Ref.body.name
16
16
call_result_unused (frame:: InferenceState , pc:: LineNum = frame. currpc) =
17
17
isexpr (frame. src. code[frame. currpc], :call ) && isempty (frame. ssavalue_uses[pc])
18
18
19
+ function matching_methods (@nospecialize (atype), cache:: IdDict{Any, Tuple{Any, UInt, UInt}} , max_methods:: Int , world:: UInt )
20
+ box = Core. Box (atype)
21
+ return get! (cache, atype) do
22
+ _min_val = UInt[typemin (UInt)]
23
+ _max_val = UInt[typemax (UInt)]
24
+ ms = _methods_by_ftype (box. contents, max_methods, world, _min_val, _max_val)
25
+ return ms, _min_val[1 ], _max_val[1 ]
26
+ end
27
+ end
28
+
29
+ function matching_methods (@nospecialize (atype), cache:: IdDict{Any, Tuple{Any, UInt, UInt}} , max_methods:: Int , world:: UInt , min_valid:: Vector{UInt} , max_valid:: Vector{UInt} )
30
+ ms, minvalid, maxvalid = matching_methods (atype, cache, max_methods, world)
31
+ min_valid[1 ] = max (min_valid[1 ], minvalid)
32
+ max_valid[1 ] = min (max_valid[1 ], maxvalid)
33
+ return ms
34
+ end
35
+
19
36
function abstract_call_gf_by_type (interp:: AbstractInterpreter , @nospecialize (f), argtypes:: Vector{Any} , @nospecialize (atype), sv:: InferenceState ,
20
- max_methods = InferenceParams (interp). MAX_METHODS)
37
+ max_methods:: Int = InferenceParams (interp). MAX_METHODS)
21
38
atype_params = unwrap_unionall (atype). parameters
22
39
ft = unwrap_unionall (atype_params[1 ]) # TODO : ccall jl_method_table_for here
23
40
isa (ft, DataType) || return Any # the function being called is unknown. can't properly handle this backedge right now
@@ -42,22 +59,14 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
42
59
splitsigs = switchtupleunion (atype)
43
60
applicable = Any[]
44
61
for sig_n in splitsigs
45
- (xapplicable, min_valid[1 ], max_valid[1 ]) =
46
- get! (sv. matching_methods_cache, sig_n) do
47
- ms = _methods_by_ftype (sig_n, max_methods,
48
- get_world_counter (interp), min_valid, max_valid)
49
- return (ms, min_valid[1 ], max_valid[1 ])
50
- end
62
+ xapplicable = matching_methods (sig_n, sv. matching_methods_cache, max_methods,
63
+ get_world_counter (interp), min_valid, max_valid)
51
64
xapplicable === false && return Any
52
65
append! (applicable, xapplicable)
53
66
end
54
67
else
55
- (applicable, min_valid[1 ], max_valid[1 ]) =
56
- get! (sv. matching_methods_cache, atype) do
57
- ms = _methods_by_ftype (atype, max_methods,
58
- get_world_counter (interp), min_valid, max_valid)
59
- return (ms, min_valid[1 ], max_valid[1 ])
60
- end
68
+ applicable = matching_methods (atype, sv. matching_methods_cache, max_methods,
69
+ get_world_counter (interp), min_valid, max_valid)
61
70
if applicable === false
62
71
# this means too many methods matched
63
72
# (assume this will always be true, so we don't compute / update valid age in this case)
595
604
596
605
# do apply(af, fargs...), where af is a function value
597
606
function abstract_apply (interp:: AbstractInterpreter , @nospecialize (itft), @nospecialize (aft), aargtypes:: Vector{Any} , vtypes:: VarTable , sv:: InferenceState ,
598
- max_methods = InferenceParams (interp). MAX_METHODS)
607
+ max_methods:: Int = InferenceParams (interp). MAX_METHODS)
599
608
aftw = widenconst (aft)
600
609
if ! isa (aft, Const) && (! isType (aftw) || has_free_typevars (aftw))
601
610
if ! isconcretetype (aftw) || (aftw <: Builtin )
@@ -694,7 +703,7 @@ function argtype_tail(argtypes::Vector{Any}, i::Int)
694
703
end
695
704
696
705
# call where the function is known exactly
697
- function abstract_call_known (interp:: AbstractInterpreter , @nospecialize (f), fargs:: Union{Nothing,Vector{Any}} , argtypes:: Vector{Any} , vtypes:: VarTable , sv:: InferenceState , max_methods = InferenceParams (interp). MAX_METHODS)
706
+ function abstract_call_known (interp:: AbstractInterpreter , @nospecialize (f), fargs:: Union{Nothing,Vector{Any}} , argtypes:: Vector{Any} , vtypes:: VarTable , sv:: InferenceState , max_methods:: Int = InferenceParams (interp). MAX_METHODS)
698
707
la = length (argtypes)
699
708
700
709
if isa (f, Builtin)
911
920
912
921
# call where the function is any lattice element
913
922
function abstract_call (interp:: AbstractInterpreter , fargs:: Union{Nothing,Vector{Any}} , argtypes:: Vector{Any} ,
914
- vtypes:: VarTable , sv:: InferenceState , max_methods = InferenceParams (interp). MAX_METHODS)
923
+ vtypes:: VarTable , sv:: InferenceState , max_methods:: Int = InferenceParams (interp). MAX_METHODS)
915
924
# print("call ", e.args[1], argtypes, "\n\n")
916
925
ft = argtypes[1 ]
917
926
if isa (ft, Const)
0 commit comments