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

inference: don't infer const ABI for OpaqueClosure methods #55034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

topolarity
Copy link
Member

This IR is always destined for compilation, so the const ABI for these methods is not really useful.

This resolves part of #54377

Specifically, this is fast now:

foo() = Base.Experimental.@opaque Tuple{Float64}->_ x -> 0.0
bar() = Base.Experimental.@opaque Tuple{Float64}->_ x -> x

const oc1 = foo()
const oc2 = bar()

using BenchmarkTools
@btime sum(oc1, 1.0:100.0) # PR: 197.571 ns (0 allocations: 0 bytes)
                           # (compare to master: 2.932 μs (200 allocations: 6.25 KiB))
@btime sum(oc2, 1.0:100.0) # PR / master: 208.488 ns (0 allocations: 0 bytes)

The original MWE with the @opaque at toplevel is unfortunately still slow, because it does not get generated at compile-time and jl_new_opaque_closure currently does a poor job of enforcing its desired ABI.

This IR is always destined for compilation, since these functions are
not Const ABI eligible.

It is possible to generate shared const ABI wrappers that would be
shared by multiple OpaqueClosures that target the same ABI, but doing
the simple thing for now seems like the right move.
@topolarity topolarity requested review from vtjnash and Keno July 4, 2024 23:53
@aviatesk
Copy link
Sponsor Member

aviatesk commented Jul 5, 2024

The original MWE with the @opaque at toplevel is unfortunately still slow, because it does not get generated at compile-time and jl_new_opaque_closure currently does a poor job of enforcing its desired ABI.

Maybe we should force compilation on top-level thunks containing :jl_new_opaque_closure exprs?

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems an acceptable workaround for now, though it seems entirely incorrect for codegen to be unable to handle this. The presence of source code in the form of a CodeInfo in the inferred field is merely an unreliable implementation detail, and not some that can be safely accessed from CodeInstance by codegen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants