Skip to content

Commit

Permalink
inference: check argtype compatibility in abstract_call_opaque_closure
Browse files Browse the repository at this point in the history
- fixes #55627
  • Loading branch information
aviatesk committed Sep 2, 2024
1 parent 39f2ad1 commit aeed68c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
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}

0 comments on commit aeed68c

Please sign in to comment.