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

Implement feature for disabling opaque pointers on LLVM 15 and 16 #570

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Derppening
Copy link

@Derppening Derppening commented Feb 17, 2025

Description

This pull request implements support for using typed pointers in LLVM 15. This is implemented by several steps:

  • Add feature typed-pointers to distinguish APIs for typed vs opaque pointers
  • Implicitly set the use of typed pointers during Context creation
  • Add typed-pointers feature dependency on all LLVM versions that only have typed pointer support (i.e. LLVM 4-14)
  • Updated #[cfg(...)] blocks to use feature = "typed-pointers" instead of version guards for pointer-related APIs
  • Add version guards in lib.rs to ensure that the typed-pointers feature can only be enabled in LLVM 15-16

Note that previous defaults are still present - LLVM 15 and 16 still uses opaque pointers by default, and will only switch to typed pointers if the typed-pointers feature is enabled.

Some points of note or for discussion with regards to the current implementation:

  • The current implementation uses a Cargo feature to guard typed vs opaque pointer API usage. Are there any known use-cases where a user of this library requires both?
    • If so, how should we handle APIs that have previously been version-guarded? E.g. Builder::build_load, where the typed pointer version of this API calls LLVMBuildLoad while the opaque pointer version calls LLVMBuildLoad2.
  • LLVM technically supports both typed and opaque pointers from LLVM 13-16 15-16, although only LLVM 15 officially supports both. Should I also expand the scope of this PR to include opt-in into opaque pointers in LLVM 13-14, as well as opt-out out of opaque pointers in LLVM 16?
    • If so, how should this look like?
    • Edit: I just realized that LLVMContextSetOpaquePointers is only available in LLVM 15-16, so please disregard my message regarding LLVM 13-14.

Related Issue

#489

How This Has Been Tested

This PR is tested using:

$ cargo test --workspace --features llvm15-0-prefer-dynamic,no-libffi-linking
$ cargo test --workspace --features llvm15-0-prefer-dynamic,no-libffi-linking,typed-pointers
$ cargo test --workspace --features llvm16-0-prefer-dynamic,no-libffi-linking
$ cargo test --workspace --features llvm16-0-prefer-dynamic,no-libffi-linking,typed-pointers

AFAICT all tests (including doctests) pass with LLVM 15 and 16 under both opaque pointer and typed pointer modes.

Checklist

@Derppening
Copy link
Author

v2: Added the ability to disable opaque pointers in LLVM 16 as well. PR description is also updated to reflect this fact.

@Derppening Derppening changed the title Implement feature for disabling opaque pointers on LLVM 15 Implement feature for disabling opaque pointers on LLVM 15 and 16 Feb 17, 2025
@TheDan64 TheDan64 self-requested a review February 17, 2025 21:47
@TheDan64
Copy link
Owner

Ahh, adding typed-pointers as a feature flag is a neat idea!

@TheDan64 TheDan64 added this to the 0.6.0 milestone Feb 17, 2025
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