Skip to content

Commit

Permalink
compiler: unify singleton_type and argtype_to_function (#42342)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aviatesk authored Sep 23, 2021
1 parent 29609cd commit 5e8d7ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
16 changes: 2 additions & 14 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ function abstract_invoke(interp::AbstractInterpreter, argtypes::Vector{Any}, sv:
# t, a = ti.parameters[i], argtypes′[i]
# argtypes′[i] = t ⊑ a ? t : a
# end
const_result = abstract_call_method_with_const_args(interp, result, argtype_to_function(ft′), argtypes′, match, sv, false)
const_result = abstract_call_method_with_const_args(interp, result, singleton_type(ft′), argtypes′, match, sv, false)
if const_result !== nothing
const_rt, const_result = const_result
if const_rt !== rt && const_rt rt
Expand Down Expand Up @@ -1379,7 +1379,7 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
sv::InferenceState, max_methods::Int = InferenceParams(interp).MAX_METHODS)
#print("call ", e.args[1], argtypes, "\n\n")
ft = argtypes[1]
f = argtype_to_function(ft)
f = singleton_type(ft)
if isa(ft, PartialOpaque)
return abstract_call_opaque_closure(interp, ft, argtypes[2:end], sv)
elseif (uft = unwrap_unionall(ft); isa(uft, DataType) && uft.name === typename(Core.OpaqueClosure))
Expand All @@ -1396,18 +1396,6 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
return abstract_call_known(interp, f, fargs, argtypes, sv, max_methods)
end

function argtype_to_function(@nospecialize(ft))
if isa(ft, Const)
return ft.val
elseif isconstType(ft)
return ft.parameters[1]
elseif isa(ft, DataType) && isdefined(ft, :instance)
return ft.instance
else
return nothing
end
end

function sp_type_rewrap(@nospecialize(T), linfo::MethodInstance, isreturn::Bool)
isref = false
if T === Bottom
Expand Down
9 changes: 0 additions & 9 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,6 @@ function rewrite_invoke_exprargs!(argexprs::Vector{Any})
return argexprs
end

function singleton_type(@nospecialize(ft))
if isa(ft, Const)
return ft.val
elseif ft isa DataType && isdefined(ft, :instance)
return ft.instance
end
return nothing
end

function compileable_specialization(et::Union{EdgeTracker, Nothing}, match::MethodMatch)
mi = specialize_method(match; compilesig=true)
mi !== nothing && et !== nothing && push!(et, mi::MethodInstance)
Expand Down
15 changes: 15 additions & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ function method_for_inference_heuristics(method::Method, @nospecialize(sig), spa
return nothing
end

#########
# types #
#########

argextype(@nospecialize(x), state) = argextype(x, state.src, state.sptypes, state.slottypes)

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

function singleton_type(@nospecialize(ft))
if isa(ft, Const)
return ft.val
elseif isconstType(ft)
return ft.parameters[1]
elseif ft isa DataType && isdefined(ft, :instance)
return ft.instance
end
return nothing
end

###################
# SSAValues/Slots #
###################
Expand Down

2 comments on commit 5e8d7ed

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.