Skip to content

Commit

Permalink
propagate results of _hasmethod/applicable using MethodResultPure
Browse files Browse the repository at this point in the history
To avoid calling `add_edges!` directly.
In fact, it might be better to define something like
`VirtualizedCallInfo` rather than using `MethodResultPure`.
  • Loading branch information
aviatesk committed Oct 4, 2024
1 parent acfe6a1 commit a674c1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
1 change: 0 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ function Core._hasmethod(@nospecialize(f), @nospecialize(t)) # this function has
return Core._hasmethod(tt)
end


# core operations & types
include("promotion.jl")
include("tuple.jl")
Expand Down
4 changes: 1 addition & 3 deletions base/compiler/stmtinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ add_uncovered_edges_impl(edges::Vector{Any}, info::ConstCallInfo, @nospecialize(
"""
info::MethodResultPure <: CallInfo
This struct represents a method result constant was proven to be
effect-free, including being no-throw (typically because the value was computed
by calling an `@pure` function).
This struct represents a method result constant was proven to be effect-free.
"""
struct MethodResultPure <: CallInfo
info::CallInfo
Expand Down
20 changes: 10 additions & 10 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2979,13 +2979,14 @@ end
# a simplified model of abstract_call_gf_by_type for applicable
function abstract_applicable(interp::AbstractInterpreter, argtypes::Vector{Any},
sv::AbsIntState, max_methods::Int)
length(argtypes) < 2 && return Future(CallMeta(Bottom, Any, EFFECTS_THROWS, NoCallInfo()))
isvarargtype(argtypes[2]) && return Future(CallMeta(Bool, Any, EFFECTS_THROWS, NoCallInfo()))
length(argtypes) < 2 && return Future(CallMeta(Bottom, ArgumentError, EFFECTS_THROWS, NoCallInfo()))
isvarargtype(argtypes[2]) && return Future(CallMeta(Bool, ArgumentError, EFFECTS_THROWS, NoCallInfo()))
argtypes = argtypes[2:end]
atype = argtypes_to_type(argtypes)
matches = find_method_matches(interp, argtypes, atype; max_methods)
if isa(matches, FailedMethodMatch)
rt = Bool # too many matches to analyze
info = NoCallInfo()
else
(; valid_worlds, applicable) = matches
update_valid_age!(sv, valid_worlds)
Expand All @@ -2998,9 +2999,9 @@ function abstract_applicable(interp::AbstractInterpreter, argtypes::Vector{Any},
else
rt = Const(true) # has applicable matches
end
add_edges!(sv.edges, matches.info)
info = MethodResultPure(matches.info) # XXX this should probably be something like `VirtualizedCallInfo`
end
return Future(CallMeta(rt, Union{}, EFFECTS_TOTAL, NoCallInfo()))
return Future(CallMeta(rt, Union{}, EFFECTS_TOTAL, info))
end
add_tfunc(applicable, 1, INT_INF, @nospecs((𝕃::AbstractLattice, f, args...)->Bool), 40)

Expand Down Expand Up @@ -3034,15 +3035,14 @@ function _hasmethod_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, sv
update_valid_age!(sv, valid_worlds)
if match === nothing
rt = Const(false)
let vresults = MethodLookupResult(Any[], valid_worlds, true)
vinfo = MethodMatchInfo(vresults, mt, types, false)
add_edges!(sv.edges, vinfo) # XXX: this should actually be an invoke-type backedge
end
vresults = MethodLookupResult(Any[], valid_worlds, true)
vinfo = MethodMatchInfo(vresults, mt, types, false) # XXX: this should actually be an info with invoke-type edge
else
rt = Const(true)
add_edges!(sv.edges, InvokeCallInfo(match, nothing, types))
vinfo = InvokeCallInfo(match, nothing, types)
end
return CallMeta(rt, Any, EFFECTS_TOTAL, NoCallInfo())
info = MethodResultPure(vinfo) # XXX this should probably be something like `VirtualizedCallInfo`
return CallMeta(rt, Union{}, EFFECTS_TOTAL, info)
end

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

0 comments on commit a674c1c

Please sign in to comment.