Skip to content

Commit

Permalink
fix wrong assertion, just propagate Bottom instead
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Oct 21, 2021
1 parent 4ef88d2 commit c641d85
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
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

0 comments on commit c641d85

Please sign in to comment.