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

OpaqueClosure constructor does not survive pre-compilation #55073

Open
topolarity opened this issue Jul 8, 2024 · 1 comment
Open

OpaqueClosure constructor does not survive pre-compilation #55073

topolarity opened this issue Jul 8, 2024 · 1 comment
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@topolarity
Copy link
Member

module Foo

using Base.Experimental: @opaque

some_method(x) = 2x
make_oc() = @opaque (x::Int)->some_method(x)

precompile(make_oc, ())

end # module Foo

When using this, I am surprised to see that make_oc() was not pre-compiled after all (or at least is not usable as-is):

julia> using SnoopCompileCore, Foo
julia> tinf = @snoop_inference Foo.make_oc();
julia> only(tinf.children).mi_timing.mi_info.mi
MethodInstance for Foo.make_oc()
@topolarity topolarity added the bug Indicates an unexpected problem or unintended behavior label Jul 8, 2024
@topolarity
Copy link
Member Author

topolarity commented Jul 8, 2024

Looks like this might be related to the compile-time OpaqueClosure optimization (#55035 is probably related)

If we make sure that optimization doesn't apply:

make_oc2(x) = begin
    x = Base.inferencebarrier(true) ? x : [] # non-concrete closure environment prevents optimization
    return Base.Experimental.@opaque ()->some_method(x)
end
precompile(make_oc2, (Int,))

Then the constructor itself is fine - we only see inference for the OpaqueClosure method itself:

julia> tinf = @snoop_inference Foo.make_oc2(1)
julia> only(tinf.children).mi_timing.mi_info.mi
MethodInstance for (::Tuple{Int64})()

That inference is expected since it wasn't included in the precompile (it only ends up inferred/pre-compiled if the compile-time optimization applies).

Maybe we're messing up our caches when performing the compile-time optimization, in a way that breaks pre-compilation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant