Skip to content

Commit

Permalink
use explicit keyword arguments for specialize_method (JuliaLang#41920)
Browse files Browse the repository at this point in the history
It would be a bit easier to reason about the configurations.
  • Loading branch information
aviatesk authored Aug 18, 2021
1 parent 2cb8e17 commit f738580
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter, result::Me
end
end
force |= allconst
mi = specialize_method(match, !force)
mi = specialize_method(match; preexisting=!force)
if mi === nothing
add_remark!(interp, sv, "[constprop] Failed to specialize")
return nothing
Expand Down Expand Up @@ -983,7 +983,7 @@ end
function is_method_pure(method::Method, @nospecialize(sig), sparams::SimpleVector)
if isdefined(method, :generator)
method.generator.expand_early || return false
mi = specialize_method(method, sig, sparams, false)
mi = specialize_method(method, sig, sparams)
isa(mi, MethodInstance) || return false
staged = get_staged(mi)
(staged isa CodeInfo && (staged::CodeInfo).pure) || return false
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,13 @@ function singleton_type(@nospecialize(ft))
end

function compileable_specialization(et::Union{EdgeTracker, Nothing}, match::MethodMatch)
mi = specialize_method(match, false, true)
mi = specialize_method(match; compilesig=true)
mi !== nothing && et !== nothing && push!(et, mi::MethodInstance)
return mi
end

function compileable_specialization(et::Union{EdgeTracker, Nothing}, (; linfo)::InferenceResult)
mi = specialize_method(linfo.def::Method, linfo.specTypes, linfo.sparam_vals, false, true)
mi = specialize_method(linfo.def::Method, linfo.specTypes, linfo.sparam_vals; compilesig=true)
mi !== nothing && et !== nothing && push!(et, mi::MethodInstance)
return mi
end
Expand Down Expand Up @@ -809,7 +809,7 @@ function analyze_method!(match::MethodMatch, atypes::Vector{Any},
end

# See if there exists a specialization for this method signature
mi = specialize_method(match, true) # Union{Nothing, MethodInstance}
mi = specialize_method(match; preexisting=true) # Union{Nothing, MethodInstance}
if !isa(mi, MethodInstance)
return compileable_specialization(et, match)
end
Expand Down
8 changes: 4 additions & 4 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function normalize_typevars(method::Method, @nospecialize(atypes), sparams::Simp
end

# get a handle to the unique specialization object representing a particular instantiation of a call
function specialize_method(method::Method, @nospecialize(atypes), sparams::SimpleVector, preexisting::Bool=false, compilesig::Bool=false)
function specialize_method(method::Method, @nospecialize(atypes), sparams::SimpleVector; preexisting::Bool=false, compilesig::Bool=false)
if isa(atypes, UnionAll)
atypes, sparams = normalize_typevars(method, atypes, sparams)
end
Expand All @@ -193,14 +193,14 @@ function specialize_method(method::Method, @nospecialize(atypes), sparams::Simpl
return ccall(:jl_specializations_get_linfo, Ref{MethodInstance}, (Any, Any, Any), method, atypes, sparams)
end

function specialize_method(match::MethodMatch, preexisting::Bool=false, compilesig::Bool=false)
return specialize_method(match.method, match.spec_types, match.sparams, preexisting, compilesig)
function specialize_method(match::MethodMatch; kwargs...)
return specialize_method(match.method, match.spec_types, match.sparams; kwargs...)
end

# This function is used for computing alternate limit heuristics
function method_for_inference_heuristics(method::Method, @nospecialize(sig), sparams::SimpleVector)
if isdefined(method, :generator) && method.generator.expand_early && may_invoke_generator(method, sig, sparams)
method_instance = specialize_method(method, sig, sparams, false)
method_instance = specialize_method(method, sig, sparams)
if isa(method_instance, MethodInstance)
cinfo = get_staged(method_instance)
if isa(cinfo, CodeInfo)
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
msig = Tuple{typeof(f22938),Int,Int,Int,Int}
world = typemax(UInt)
match = Base._methods_by_ftype(msig, -1, world)[]
mi = Core.Compiler.specialize_method(match, false)
mi = Core.Compiler.specialize_method(match)
c0 = Core.Compiler.retrieve_code_info(mi)

@test isempty(Core.Compiler.validate_code(mi))
Expand Down

0 comments on commit f738580

Please sign in to comment.