From d99d569f18245f4095de75c9b852094ba8f24a69 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 14 Nov 2024 14:19:28 -0500 Subject: [PATCH] inference: Don't try to infer optimized opaque_closure (#56557) We don't have frontend syntax for it, but there is a use case for having `:new_opaque_closure` take an OC constructed from an optimized OpaqueClosure (and just replacing the capture environment). In this case, there is nothing inference can do to introspect into the opaque closure, so it just needs to bail out early. --- Compiler/src/abstractinterpretation.jl | 8 ++++++++ Compiler/src/stmtinfo.jl | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Compiler/src/abstractinterpretation.jl b/Compiler/src/abstractinterpretation.jl index 67e7ecfbce66a..faaba0c2dc44f 100644 --- a/Compiler/src/abstractinterpretation.jl +++ b/Compiler/src/abstractinterpretation.jl @@ -2633,6 +2633,14 @@ function abstract_call_opaque_closure(interp::AbstractInterpreter, ocsig = rewrap_unionall(Tuple{Tuple, ocargsigā€².parameters...}, ocargsig) hasintersect(sig, ocsig) || return Future(CallMeta(Union{}, Union{MethodError,TypeError}, EFFECTS_THROWS, NoCallInfo())) ocmethod = closure.source::Method + if !isdefined(ocmethod, :source) + # This opaque closure was created from optimized source. We cannot infer it further. + ocrt = rewrap_unionall((unwrap_unionall(tt)::DataType).parameters[2], tt) + if isa(ocrt, DataType) + return Future(CallMeta(ocrt, Any, Effects(), NoCallInfo())) + end + return Future(CallMeta(Any, Any, Effects(), NoCallInfo())) + end match = MethodMatch(sig, Core.svec(), ocmethod, sig <: ocsig) mresult = abstract_call_method(interp, ocmethod, sig, Core.svec(), false, si, sv) ocsig_box = Core.Box(ocsig) diff --git a/Compiler/src/stmtinfo.jl b/Compiler/src/stmtinfo.jl index 4cbd2ab39fd46..83d0b66e4d564 100644 --- a/Compiler/src/stmtinfo.jl +++ b/Compiler/src/stmtinfo.jl @@ -352,7 +352,7 @@ allow the optimizer to rewrite the return type parameter of the `OpaqueClosure` struct OpaqueClosureCreateInfo <: CallInfo unspec::CallMeta function OpaqueClosureCreateInfo(unspec::CallMeta) - @assert isa(unspec.info, OpaqueClosureCallInfo) + @assert isa(unspec.info, Union{OpaqueClosureCallInfo, NoCallInfo}) return new(unspec) end end