-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Remove int2ptr cast in bevy_ptr::dangling_with_align and remove -Zmiri-permissive-provenance in CI
#15311
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
Merged
alice-i-cecile
merged 3 commits into
bevyengine:main
from
SkiFire13:bevy-ptr-dangling-from-null
Sep 19, 2024
Merged
Remove int2ptr cast in bevy_ptr::dangling_with_align and remove -Zmiri-permissive-provenance in CI
#15311
alice-i-cecile
merged 3 commits into
bevyengine:main
from
SkiFire13:bevy-ptr-dangling-from-null
Sep 19, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bevy_ptr::dangling_with_alignbevy_ptr::dangling_with_align and remove -Zmiri-permissive-provenance in CI
alice-i-cecile
approved these changes
Sep 19, 2024
bevy_ptr::dangling_with_align and remove -Zmiri-permissive-provenance in CIbevy_ptr::dangling_with_align and remove -Zmiri-permissive-provenance in CI
hymm
approved these changes
Sep 19, 2024
hymm
reviewed
Sep 19, 2024
mockersf
reviewed
Sep 19, 2024
Co-authored-by: François Mockers <[email protected]>
github-merge-queue bot
pushed a commit
that referenced
this pull request
Dec 9, 2025
# Objective - `bevy_ptr::dangling_with_align()` is only used once, in `bevy_ecs`'s `BlobArray::with_capacity()`, and it isn't generally useful outside of the engine's internals. We can remove the function and inline its implementation into its call site. - Additionally, `bevy_ptr::dangling_with_align()` has a TODO comment that was leftover from #15311 (comment), where it was suggested that `dangling_with_align()` should use `without_provenance()`. - `with_addr()`, mentioned in the TODO comment, could also be used, but it's a more roundabout solution. The reason it was mentioned was because the original author thought it would be stabilized before `without_provenance()`. ## Solution - Remove `dangling_with_align()`. - Replace its usage with `NonNull::without_provenance()` (since it is now stable and doesn't require `unsafe` or pointer math) ## Testing - I ran Miri with strict provenance checking enabled to ensure the behavior is maintained. - `MIRIFLAGS="-Zmiri-strict-provenance" cargo +nightly miri test` ## But what is this provenance thingy? [The official docs provide a more in-depth explanation](https://doc.rust-lang.org/stable/std/ptr/index.html#provenance), but basically a pointer is more than just a number referring to a memory address. Pointers have _permissions_ associated with them that track: - What set of memory addresses are allowed to be accessed - When the pointer is allowed to access those addresses - If the pointer is allowed to mutate the memory, or just read it These permissions are pointer provenance. They aren't stored at runtime, the Rust compiler doesn't know them at compile time! Miri is the only tool that I know of that tracks provenance, which it uses to ensure pointers adheres to their spatial, temporal, and mutability permissions. That's why I mentioned Miri in the Testing section. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Pointers
Relating to Bevy pointer abstractions
D-Unsafe
Touches with unsafe code in some way
P-Unsound
A bug that results in undefined compiler behavior
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
bevy_ptr::dangling_with_align-Zmiri-permissive-provenanceis used (like in CI)-Zmiri-permissive-provenancein CISolution
std::ptr::without_provenancedoes, i.e. by starting from a null pointer.