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

cg_llvm: Clean up FFI calls for operand bundles #132342

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Oct 30, 2024

All of these FFI functions have equivalents in the stable LLVM-C API, though LLVMBuildCallBr requires a temporary polyfill on LLVM 18.

This PR also creates a clear split between OperandBundleOwned and OperandBundle, and updates the internals of the owner to be a little less terrifying.

@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2024

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 30, 2024
@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member

added in LLVM 19: llvm/llvm-project@584253c

@Zalathar
Copy link
Contributor Author

Oh boo, that makes things a bit more complicated. Thanks for the pointer.

@Zalathar
Copy link
Contributor Author

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 30, 2024
@Zalathar
Copy link
Contributor Author

Rather than back out the switch to LLVMBuildCallBr, I've renamed the old LLVMRustBuildCallBr to be a polyfill for that function, for LLVM 18 only.

So after the next LLVM bump when 19 becomes baseline, the polyfill can just be deleted.

@Zalathar
Copy link
Contributor Author

In discussions elsewhere there was some brief confusion over whether the requirement should be 19.0 or 19.1.

It turns out that LLVM has switched to a policy of making their first release in a series X.1, to distinguish it from development builds prior to the release process: https://discourse.llvm.org/t/rfc-name-the-first-release-from-a-branch-n-1-0-instead-of-n-0-0/75384.

I'm going to stick with <19.0 as the condition for the polyfill, because I'd rather err on the side of not having the polyfill. If someone really wants to try building against prerelease LLVM 19 for some reason, whether or not that works is their problem.

@Zalathar
Copy link
Contributor Author

Looks like the polyfill works in PR CI.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 30, 2024
Comment on lines +335 to +337
/// Owns an [`OperandBundle`], and will dispose of it when dropped.
pub(crate) struct OperandBundleOwned<'a> {
raw: ptr::NonNull<OperandBundle<'a>>,
Copy link
Member

@workingjubilee workingjubilee Oct 30, 2024

Choose a reason for hiding this comment

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

ah, and the dependence on the &[&'a Value] is what means we can't just make OperandBundleOwned be actually this, right?

type OperandBundleOwned = OperandBundle<'static>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, from what I can tell an operand bundle holds copies of the value pointers internally, so it would be unsound for the bundle to outlive those values.

(In practice, I think the lifetime of values is always 'll, i.e. the lifetime of the LLVM context.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh one other relevant point, OperandBundleOwned is closer to Box<OperandBundle>, since its representation is a pointer to the underlying bundle, and the owner is responsible for deallocating on drop.

So the two types would still have to be different, unless we hypothetically had &own references to handle dropping.

@workingjubilee
Copy link
Member

I'm satisfied. @bors r+

@bors
Copy link
Contributor

bors commented Oct 30, 2024

📌 Commit c307159 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 30, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#129394 (Don't lint `irrefutable_let_patterns` on leading patterns if `else if` let-chains)
 - rust-lang#131856 (TypingMode: merge intercrate, reveal, and defining_opaque_types)
 - rust-lang#132322 (powerpc64-ibm-aix: update maintainters)
 - rust-lang#132327 (Point to Fuchsia team in platform support docs)
 - rust-lang#132332 (Use `token_descr` more in error messages)
 - rust-lang#132338 (Remove `Engine`)
 - rust-lang#132340 (cg_llvm: Consistently use safe wrapper function `set_section`)
 - rust-lang#132342 (cg_llvm: Clean up FFI calls for operand bundles)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 879c4d5 into rust-lang:master Oct 30, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 30, 2024
Rollup merge of rust-lang#132342 - Zalathar:operand-bundle, r=workingjubilee

cg_llvm: Clean up FFI calls for operand bundles

All of these FFI functions have equivalents in the stable LLVM-C API, though `LLVMBuildCallBr` requires a temporary polyfill on LLVM 18.

This PR also creates a clear split between `OperandBundleOwned` and `OperandBundle`, and updates the internals of the owner to be a little less terrifying.
@rustbot rustbot added this to the 1.84.0 milestone Oct 30, 2024
@Zalathar Zalathar deleted the operand-bundle branch October 30, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants