Skip to content

Commit a9c4eeb

Browse files
committed
propagate results of _hasmethod/applicable using MethodResultPure
To avoid calling `add_edges!` directly. In fact, it might be better to define something like `VirtualizedCallInfo` rather than using `MethodResultPure`.
1 parent f081d25 commit a9c4eeb

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

base/Base.jl

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ function Core._hasmethod(@nospecialize(f), @nospecialize(t)) # this function has
198198
return Core._hasmethod(tt)
199199
end
200200

201-
202201
# core operations & types
203202
include("promotion.jl")
204203
include("tuple.jl")

base/compiler/stmtinfo.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ add_uncovered_edges_impl(edges::Vector{Any}, info::ConstCallInfo, @nospecialize(
178178
"""
179179
info::MethodResultPure <: CallInfo
180180
181-
This struct represents a method result constant was proven to be
182-
effect-free, including being no-throw (typically because the value was computed
183-
by calling an `@pure` function).
181+
This struct represents a method result constant was proven to be effect-free.
184182
"""
185183
struct MethodResultPure <: CallInfo
186184
info::CallInfo

base/compiler/tfuncs.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -2969,13 +2969,14 @@ end
29692969
# a simplified model of abstract_call_gf_by_type for applicable
29702970
function abstract_applicable(interp::AbstractInterpreter, argtypes::Vector{Any},
29712971
sv::AbsIntState, max_methods::Int)
2972-
length(argtypes) < 2 && return CallMeta(Bottom, Any, EFFECTS_THROWS, NoCallInfo())
2973-
isvarargtype(argtypes[2]) && return CallMeta(Bool, Any, EFFECTS_THROWS, NoCallInfo())
2972+
length(argtypes) < 2 && return CallMeta(Bottom, ArgumentError, EFFECTS_THROWS, NoCallInfo())
2973+
isvarargtype(argtypes[2]) && return CallMeta(Bool, ArgumentError, EFFECTS_THROWS, NoCallInfo())
29742974
argtypes = argtypes[2:end]
29752975
atype = argtypes_to_type(argtypes)
29762976
matches = find_method_matches(interp, argtypes, atype; max_methods)
29772977
if isa(matches, FailedMethodMatch)
29782978
rt = Bool # too many matches to analyze
2979+
info = NoCallInfo()
29792980
else
29802981
(; valid_worlds, applicable) = matches
29812982
update_valid_age!(sv, valid_worlds)
@@ -2988,9 +2989,9 @@ function abstract_applicable(interp::AbstractInterpreter, argtypes::Vector{Any},
29882989
else
29892990
rt = Const(true) # has applicable matches
29902991
end
2991-
add_edges!(sv.edges, matches.info)
2992+
info = MethodResultPure(matches.info) # XXX this should probably be something like `VirtualizedCallInfo`
29922993
end
2993-
return CallMeta(rt, Union{}, EFFECTS_TOTAL, NoCallInfo())
2994+
return CallMeta(rt, Union{}, EFFECTS_TOTAL, info)
29942995
end
29952996
add_tfunc(applicable, 1, INT_INF, @nospecs((𝕃::AbstractLattice, f, args...)->Bool), 40)
29962997

@@ -3024,15 +3025,14 @@ function _hasmethod_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, sv
30243025
update_valid_age!(sv, valid_worlds)
30253026
if match === nothing
30263027
rt = Const(false)
3027-
let vresults = MethodLookupResult(Any[], valid_worlds, true)
3028-
vinfo = MethodMatchInfo(vresults, mt, types, false)
3029-
add_edges!(sv.edges, vinfo) # XXX: this should actually be an invoke-type backedge
3030-
end
3028+
vresults = MethodLookupResult(Any[], valid_worlds, true)
3029+
vinfo = MethodMatchInfo(vresults, mt, types, false) # XXX: this should actually be an info with invoke-type edge
30313030
else
30323031
rt = Const(true)
3033-
add_edges!(sv.edges, InvokeCallInfo(match, nothing, types))
3032+
vinfo = InvokeCallInfo(match, nothing, types)
30343033
end
3035-
return CallMeta(rt, Any, EFFECTS_TOTAL, NoCallInfo())
3034+
info = MethodResultPure(vinfo) # XXX this should probably be something like `VirtualizedCallInfo`
3035+
return CallMeta(rt, Union{}, EFFECTS_TOTAL, info)
30363036
end
30373037

30383038
# N.B.: typename maps type equivalence classes to a single value

0 commit comments

Comments
 (0)