Skip to content

Commit 5bb8181

Browse files
aviateskKristofferC
authored andcommitted
compiler: unify singleton_type and argtype_to_function (#42342)
They are supposed to do the same thing. Previously `singleton_type` didn't handle the case where `isconstType(ft) -> ft.parameters[1]`, but it can just include that.
1 parent cc30586 commit 5bb8181

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ function abstract_invoke(interp::AbstractInterpreter, argtypes::Vector{Any}, sv:
12351235
# t, a = ti.parameters[i], argtypes′[i]
12361236
# argtypes′[i] = t ⊑ a ? t : a
12371237
# end
1238-
const_result = abstract_call_method_with_const_args(interp, result, argtype_to_function(ft′), argtypes′, match, sv, false)
1238+
const_result = abstract_call_method_with_const_args(interp, result, singleton_type(ft′), argtypes′, match, sv, false)
12391239
if const_result !== nothing
12401240
const_rt, const_result = const_result
12411241
if const_rt !== rt && const_rt rt
@@ -1379,7 +1379,7 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
13791379
sv::InferenceState, max_methods::Int = InferenceParams(interp).MAX_METHODS)
13801380
#print("call ", e.args[1], argtypes, "\n\n")
13811381
ft = argtypes[1]
1382-
f = argtype_to_function(ft)
1382+
f = singleton_type(ft)
13831383
if isa(ft, PartialOpaque)
13841384
return abstract_call_opaque_closure(interp, ft, argtypes[2:end], sv)
13851385
elseif (uft = unwrap_unionall(ft); isa(uft, DataType) && uft.name === typename(Core.OpaqueClosure))
@@ -1396,18 +1396,6 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
13961396
return abstract_call_known(interp, f, fargs, argtypes, sv, max_methods)
13971397
end
13981398

1399-
function argtype_to_function(@nospecialize(ft))
1400-
if isa(ft, Const)
1401-
return ft.val
1402-
elseif isconstType(ft)
1403-
return ft.parameters[1]
1404-
elseif isa(ft, DataType) && isdefined(ft, :instance)
1405-
return ft.instance
1406-
else
1407-
return nothing
1408-
end
1409-
end
1410-
14111399
function sp_type_rewrap(@nospecialize(T), linfo::MethodInstance, isreturn::Bool)
14121400
isref = false
14131401
if T === Bottom

base/compiler/ssair/inlining.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -717,15 +717,6 @@ function rewrite_invoke_exprargs!(argexprs::Vector{Any})
717717
return argexprs
718718
end
719719

720-
function singleton_type(@nospecialize(ft))
721-
if isa(ft, Const)
722-
return ft.val
723-
elseif ft isa DataType && isdefined(ft, :instance)
724-
return ft.instance
725-
end
726-
return nothing
727-
end
728-
729720
function compileable_specialization(et::Union{EdgeTracker, Nothing}, match::MethodMatch)
730721
mi = specialize_method(match; compilesig=true)
731722
mi !== nothing && et !== nothing && push!(et, mi::MethodInstance)

base/compiler/utilities.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ function method_for_inference_heuristics(method::Method, @nospecialize(sig), spa
222222
return nothing
223223
end
224224

225+
#########
226+
# types #
227+
#########
228+
225229
argextype(@nospecialize(x), state) = argextype(x, state.src, state.sptypes, state.slottypes)
226230

227231
const empty_slottypes = Any[]
@@ -259,6 +263,17 @@ function argextype(@nospecialize(x), src, sptypes::Vector{Any}, slottypes::Vecto
259263
end
260264
end
261265

266+
function singleton_type(@nospecialize(ft))
267+
if isa(ft, Const)
268+
return ft.val
269+
elseif isconstType(ft)
270+
return ft.parameters[1]
271+
elseif ft isa DataType && isdefined(ft, :instance)
272+
return ft.instance
273+
end
274+
return nothing
275+
end
276+
262277
###################
263278
# SSAValues/Slots #
264279
###################

0 commit comments

Comments
 (0)