Skip to content

inference: check argtype compatibility in abstract_call_opaque_closure #55672

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

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 9 additions & 4 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2334,11 +2334,16 @@ end
function abstract_call_opaque_closure(interp::AbstractInterpreter,
closure::PartialOpaque, arginfo::ArgInfo, si::StmtInfo, sv::AbsIntState, check::Bool=true)
sig = argtypes_to_type(arginfo.argtypes)
result = abstract_call_method(interp, closure.source::Method, sig, Core.svec(), false, si, sv)
(; rt, edge, effects, volatile_inf_result) = result
tt = closure.typ
sigT = (unwrap_unionall(tt)::DataType).parameters[1]
match = MethodMatch(sig, Core.svec(), closure.source, sig <: rewrap_unionall(sigT, tt))
ocargsig = rewrap_unionall((unwrap_unionall(tt)::DataType).parameters[1], tt)
ocargsig′ = unwrap_unionall(ocargsig)
ocargsig′ isa DataType || return CallMeta(Any, Any, Effects(), NoCallInfo())
ocsig = rewrap_unionall(Tuple{Tuple, ocargsig′.parameters...}, ocargsig)
hasintersect(sig, ocsig) || return CallMeta(Union{}, TypeError, EFFECTS_THROWS, NoCallInfo())
ocmethod = closure.source::Method
result = abstract_call_method(interp, ocmethod, sig, Core.svec(), false, si, sv)
(; rt, edge, effects, volatile_inf_result) = result
match = MethodMatch(sig, Core.svec(), ocmethod, sig <: ocsig)
𝕃ₚ = ipo_lattice(interp)
⊑ₚ = ⊑(𝕃ₚ)
const_result = volatile_inf_result
Expand Down
13 changes: 13 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6076,3 +6076,16 @@ end
fcondvarargs(a, b, c, d) = isa(d, Int64)
gcondvarargs(a, x...) = return fcondvarargs(a, x...) ? isa(a, Int64) : !isa(a, Int64)
@test Core.Compiler.return_type(gcondvarargs, Tuple{Vararg{Any}}) === Bool

# JuliaLang/julia#55627: argtypes check in `abstract_call_opaque_closure`
issue55627_some_method(x) = 2x
issue55627_make_oc() = Base.Experimental.@opaque (x::Int)->issue55627_some_method(x)

@test Base.infer_return_type() do
f = issue55627_make_oc()
return f(1), f()
end == Union{}
@test Base.infer_return_type((Vector{Int},)) do xs
f = issue55627_make_oc()
return f(1), f(xs...)
end == Tuple{Int,Int}