From f73858072c18f09c65490408e7102816570b5101 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Thu, 19 Aug 2021 03:51:12 +0900 Subject: [PATCH] use explicit keyword arguments for `specialize_method` (#41920) It would be a bit easier to reason about the configurations. --- base/compiler/abstractinterpretation.jl | 4 ++-- base/compiler/ssair/inlining.jl | 6 +++--- base/compiler/utilities.jl | 8 ++++---- test/compiler/validation.jl | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 296a30cdb2e0f..efcebf8c1408e 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -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 @@ -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 diff --git a/base/compiler/ssair/inlining.jl b/base/compiler/ssair/inlining.jl index 5bbf576d9f536..7e7baff136741 100644 --- a/base/compiler/ssair/inlining.jl +++ b/base/compiler/ssair/inlining.jl @@ -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 @@ -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 diff --git a/base/compiler/utilities.jl b/base/compiler/utilities.jl index ed31e382d1152..5d4d52172a300 100644 --- a/base/compiler/utilities.jl +++ b/base/compiler/utilities.jl @@ -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 @@ -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) diff --git a/test/compiler/validation.jl b/test/compiler/validation.jl index d07007069b5c8..3863d3b11351f 100644 --- a/test/compiler/validation.jl +++ b/test/compiler/validation.jl @@ -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))