-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 by Bors] - Add a method for converting MutUntyped
-> Mut<T>
#7113
Conversation
I relaxed the language on the |
I disagree with this PR adding alignment safety invariants to |
We should add the invariant to |
The docs make no mention of any alignment requirement for these types:
The docs for
Again, no alignment requirements. Since these types have no alignment guarantee, you need to ensure they are aligned when you dereference them. This PR isn't adding any invariants, it's documenting invariants that used to be implicit. We could add the requirement that these types must be aligned. But as discussed in #7117, it is useful to be able to create unaligned pointers. I don't think we should do this, it would make these types less valuable. Also, to clarify one point that might be confusing:
This does not require the pointer to be aligned. Alignment is a property of a pointer, not the value it is pointing to. |
I'm aware of this. This should be changed by documenting alignment requirements.
They could implicitly be on
This is reasonable if its enforced on construction, imo the only safety invariants on
as mentioned in #7117 we could have separate types for when alignment is not being upheld (which if we were starting from a position of having
A better way of wording the safety invaraints on |
I've reverted everything to use the incorrect invariants again, so we can have this discussion elsewhere. |
Agreed, this deserves its own issue or PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
# Objective `MutUntyped` is a struct that stores a `PtrMut` alongside change tick metadata. Working with this type is cumbersome, and has few benefits over storing the pointer and change ticks separately. Related: #6430 (title is out of date) ## Solution Add a convenience method for transforming an untyped change detection pointer into its typed counterpart. --- ## Changelog - Added the method `MutUntyped::with_type`.
MutUntyped
-> Mut<T>
MutUntyped
-> Mut<T>
…7117) # Objective Improve safety testing when using `bevy_ptr` types. This is a follow-up to #7113. ## Solution Add a debug-only assertion that pointers are aligned when casting to a concrete type. This should very quickly catch any unsoundness from unaligned pointers, even without miri. However, this can have a large negative perf impact on debug builds. --- ## Changelog Added: `Ptr::deref` will now panic in debug builds if the pointer is not aligned. Added: `PtrMut::deref_mut` will now panic in debug builds if the pointer is not aligned. Added: `OwningPtr::read` will now panic in debug builds if the pointer is not aligned. Added: `OwningPtr::drop_as` will now panic in debug builds if the pointer is not aligned.
# Objective `MutUntyped` is a struct that stores a `PtrMut` alongside change tick metadata. Working with this type is cumbersome, and has few benefits over storing the pointer and change ticks separately. Related: bevyengine#6430 (title is out of date) ## Solution Add a convenience method for transforming an untyped change detection pointer into its typed counterpart. --- ## Changelog - Added the method `MutUntyped::with_type`.
…evyengine#7117) # Objective Improve safety testing when using `bevy_ptr` types. This is a follow-up to bevyengine#7113. ## Solution Add a debug-only assertion that pointers are aligned when casting to a concrete type. This should very quickly catch any unsoundness from unaligned pointers, even without miri. However, this can have a large negative perf impact on debug builds. --- ## Changelog Added: `Ptr::deref` will now panic in debug builds if the pointer is not aligned. Added: `PtrMut::deref_mut` will now panic in debug builds if the pointer is not aligned. Added: `OwningPtr::read` will now panic in debug builds if the pointer is not aligned. Added: `OwningPtr::drop_as` will now panic in debug builds if the pointer is not aligned.
# Objective `MutUntyped` is a struct that stores a `PtrMut` alongside change tick metadata. Working with this type is cumbersome, and has few benefits over storing the pointer and change ticks separately. Related: bevyengine#6430 (title is out of date) ## Solution Add a convenience method for transforming an untyped change detection pointer into its typed counterpart. --- ## Changelog - Added the method `MutUntyped::with_type`.
…evyengine#7117) # Objective Improve safety testing when using `bevy_ptr` types. This is a follow-up to bevyengine#7113. ## Solution Add a debug-only assertion that pointers are aligned when casting to a concrete type. This should very quickly catch any unsoundness from unaligned pointers, even without miri. However, this can have a large negative perf impact on debug builds. --- ## Changelog Added: `Ptr::deref` will now panic in debug builds if the pointer is not aligned. Added: `PtrMut::deref_mut` will now panic in debug builds if the pointer is not aligned. Added: `OwningPtr::read` will now panic in debug builds if the pointer is not aligned. Added: `OwningPtr::drop_as` will now panic in debug builds if the pointer is not aligned.
Objective
MutUntyped
is a struct that stores aPtrMut
alongside change tick metadata. Working with this type is cumbersome, and has few benefits over storing the pointer and change ticks separately.Related: #6430 (title is out of date)
Solution
Add a convenience method for transforming an untyped change detection pointer into its typed counterpart.
Changelog
MutUntyped::with_type
.