Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inference: forward Conditional inter-procedurally #42529

Merged
merged 4 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix wrong assertion, just propagate Bottom instead
  • Loading branch information
aviatesk committed Oct 21, 2021
commit c641d85d1b8f7f55012c8a2e29a65a9f584260fb
2 changes: 1 addition & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function abstract_call_method_with_const_args(interp::AbstractInterpreter, resul
return nothing
end
end
inf_result = InferenceResult(mi; arginfo, va_override)
inf_result = InferenceResult(mi, arginfo, va_override)
if !any(inf_result.overridden_by_const)
add_remark!(interp, sv, "[constprop] Could not handle constant info in matching_cache_argtypes")
return nothing
Expand Down
26 changes: 12 additions & 14 deletions base/compiler/inferenceresult.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function matching_cache_argtypes(
linfo::MethodInstance, (; fargs, argtypes)::ArgInfo, va_override::Bool)
@assert isa(linfo.def, Method) # ensure the next line works
nargs::Int = linfo.def.nargs
cache_argtypes, overridden_by_const = matching_cache_argtypes(linfo, nothing, va_override)
given_argtypes = Vector{Any}(undef, length(argtypes))
local condargs = nothing
for i in 1:length(argtypes)
Expand All @@ -33,20 +34,18 @@ function matching_cache_argtypes(
cnd = argtype
slotid = find_constrained_arg(cnd, fargs)
if slotid !== nothing
if condargs === nothing
condargs = Tuple{Int,Int}[]
end
# using union-split signature, we may be able to narrow down `Conditional` to `Const`
vtype = tmeet(cnd.vtype, widenconst(argtypes[slotid]))
elsetype = tmeet(cnd.elsetype, widenconst(argtypes[slotid]))
if vtype === Bottom
given_argtypes[i] = Const(false)
# union-split should never find a more precise information about `fargs[slotid]` than `Conditional`,
# otherwise there should have been a bug around `Conditional` construction or maintainance
@assert elsetype !== Bottom "invalid Conditional element"
elseif elsetype === Bottom
given_argtypes[i] = Const(true)
# using union-split signature, we may be able to narrow down `Conditional`
sigt = widenconst(slotid > nargs ? argtypes[slotid] : cache_argtypes[slotid])
vtype = tmeet(cnd.vtype, sigt)
elsetype = tmeet(cnd.elsetype, sigt)
if vtype === Bottom && elsetype === Bottom
# we accidentally proved this method match is impossible
# TODO bail out here immediately rather than just propagating Bottom ?
given_argtypes[i] = Bottom
else
if condargs === nothing
condargs = Tuple{Int,Int}[]
end
push!(condargs, (slotid, i))
given_argtypes[i] = Conditional(SlotNumber(slotid), vtype, elsetype)
end
Expand Down Expand Up @@ -80,7 +79,6 @@ function matching_cache_argtypes(
given_argtypes = isva_given_argtypes
end
@assert length(given_argtypes) == nargs
cache_argtypes, overridden_by_const = matching_cache_argtypes(linfo, nothing, va_override)
for i in 1:nargs
given_argtype = given_argtypes[i]
cache_argtype = cache_argtypes[i]
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mutable struct InferenceResult
result # ::Type, or InferenceState if WIP
src #::Union{CodeInfo, OptimizationState, Nothing} # if inferred copy is available
valid_worlds::WorldRange # if inference and optimization is finished
function InferenceResult(linfo::MethodInstance;
function InferenceResult(linfo::MethodInstance,
arginfo::Union{Nothing,ArgInfo} = nothing,
va_override::Bool = false)
argtypes, overridden_by_const = matching_cache_argtypes(linfo, arginfo, va_override)
Expand Down