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

Fix opaque closure codegen ABI #40001

Merged
merged 1 commit into from
Mar 15, 2021
Merged

Fix opaque closure codegen ABI #40001

merged 1 commit into from
Mar 15, 2021

Conversation

Keno
Copy link
Member

@Keno Keno commented Mar 12, 2021

At the moment our ABI for specfun opaque closures is that the
opaque closure itself remains a GC tracked pointer out of which
the function itself implicitly loads the environment and the world
age. In the future we may want to improve this ABI, but it seems
fine for now. However, this ABI wasn't quite implemented correctly
after we've started turning on inference of OpaqueClosure where
the first argument of the MethodInstance's linfo actually stores
the type of the closure environment rather than the closure itself.
Fix this by manually forcing the signature determination code to
just treat that argument as Any, though of course in the future
we may want to do something fancier.

src/codegen.cpp Outdated
Comment on lines 6477 to 6478
argType = jl_unwrap_unionall(
(jl_value_t*)jl_opaque_closure_type);
Copy link
Member

Choose a reason for hiding this comment

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

seems strange to intentionally introduce an invalid type object here as the argument type with jl_unwrap_unionall

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is to make emit_getfield_knownidx below work since the layout is independent of the type parameters. I guess I could just do OpaqueClosure{Tuple{Any}, Any} to make something valid or we could just manually compute the offset. Maybe the latter makes the most sense.

Copy link
Member

Choose a reason for hiding this comment

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

ah, yeah, I'm surprised we don't end up tagging that load with some nonsensical type too and causing confusion

I guess the latter possibly does make the most sense, as later the intent is to inline the data, rather than making it a separate Tuple{Any} allocation

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, alright, let me just do that.

At the moment our ABI for specfun opaque closures is that the
opaque closure itself remains a GC tracked pointer out of which
the function itself implicitly loads the environment and the world
age. In the future we may want to improve this ABI, but it seems
fine for now. However, this ABI wasn't quite implemented correctly
after we've started turning on inference of OpaqueClosure where
the first argument of the MethodInstance's linfo actually stores
the type of the closure environment rather than the closure itself.
Fix this by manually forcing the signature determination code to
just treat that argument as `Any`, though of course in the future
we may want to do something fancier.
@Keno Keno merged commit 11016bf into master Mar 15, 2021
@Keno Keno deleted the kf/ocodegenfix branch March 15, 2021 14:55
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
At the moment our ABI for specfun opaque closures is that the
opaque closure itself remains a GC tracked pointer out of which
the function itself implicitly loads the environment and the world
age. In the future we may want to improve this ABI, but it seems
fine for now. However, this ABI wasn't quite implemented correctly
after we've started turning on inference of OpaqueClosure where
the first argument of the MethodInstance's linfo actually stores
the type of the closure environment rather than the closure itself.
Fix this by manually forcing the signature determination code to
just treat that argument as `Any`, though of course in the future
we may want to do something fancier.
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request May 9, 2021
At the moment our ABI for specfun opaque closures is that the
opaque closure itself remains a GC tracked pointer out of which
the function itself implicitly loads the environment and the world
age. In the future we may want to improve this ABI, but it seems
fine for now. However, this ABI wasn't quite implemented correctly
after we've started turning on inference of OpaqueClosure where
the first argument of the MethodInstance's linfo actually stores
the type of the closure environment rather than the closure itself.
Fix this by manually forcing the signature determination code to
just treat that argument as `Any`, though of course in the future
we may want to do something fancier.
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.

2 participants