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

[Merged by Bors] - Panic on dropping NonSend in non-origin thread. #6534

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
bbb7e85
Abort on dropping NonSend in non-origin thread.
james7132 Nov 10, 2022
0f4b73d
Fix safety comments
james7132 Nov 10, 2022
e83e8e3
Invert is_send
james7132 Nov 10, 2022
e46ec0c
Factor out drop-abort
james7132 Nov 10, 2022
0898a54
Fix access, replace MainThreadValidator
james7132 Nov 16, 2022
e4d61c1
Update docs
james7132 Nov 16, 2022
944b83c
Switch to always panic, use ManuallyDrop
james7132 Nov 16, 2022
9b712df
Formatting
james7132 Nov 16, 2022
776ffaf
Merge branch 'main' into abort-on-nonsend-drop
james7132 Dec 1, 2022
ba27136
Split out into NonSendResources
james7132 Dec 2, 2022
c3708d4
Cleanup docs and type definitions
james7132 Dec 2, 2022
16ae491
Fix CI
james7132 Dec 2, 2022
cc4c611
Merge branch 'main' into abort-on-nonsend-drop
james7132 Dec 2, 2022
1a09486
Update safety docs.
james7132 Dec 2, 2022
f935aa2
Actually fix CI
james7132 Dec 2, 2022
f4281e6
Small cleanup
james7132 Dec 2, 2022
1692da8
Fix WorldCell's use of NonSend
james7132 Dec 2, 2022
2b11ea3
Fix bevy_window
james7132 Dec 2, 2022
638e95c
Use const generics to split on Send/!Send
james7132 Dec 2, 2022
c37f26e
Use const generics instead of duplicating code
james7132 Dec 2, 2022
ee5de65
Use the right branch
james7132 Dec 2, 2022
d195cb6
Add panic sections to World's API docs
james7132 Dec 3, 2022
93334a0
Apply suggestions from code review
james7132 Dec 3, 2022
8f72292
Remove non_send_scope
james7132 Dec 3, 2022
b3fffd9
Split insert_non_send_by_id from insert_resource_by_id
james7132 Dec 3, 2022
54e5a50
Fix safety comment and tests
james7132 Dec 3, 2022
5f6e91b
Exhaustively decompose Storages in check_change_ticks
james7132 Dec 3, 2022
cfb8173
Remove spurious is_send in docs
james7132 Dec 3, 2022
5900696
Update safety docs on initialize_resource_internal
james7132 Dec 3, 2022
95e575f
Check that Send resources have correct metadata on initialization
james7132 Dec 3, 2022
2bff28c
Formatting
james7132 Dec 3, 2022
6af4c4e
Undo changes to BlobVec, how the hell did this get in here
james7132 Dec 3, 2022
e056626
Fix docs link
james7132 Dec 3, 2022
58bcb66
Apply suggestions from code review
james7132 Dec 4, 2022
9db8041
Stronger assert
james7132 Dec 4, 2022
d713d84
Fix CI
james7132 Dec 4, 2022
314a86e
Apply suggestions from code review
james7132 Dec 5, 2022
e06677a
Small cleanup
james7132 Dec 5, 2022
de05d57
Update crates/bevy_ecs/src/world/mod.rs
james7132 Dec 5, 2022
b4d6303
Merge branch 'main' into abort-on-nonsend-drop
james7132 Dec 6, 2022
a9895c0
Merge branch 'abort-on-nonsend-drop' of github.com:james7132/bevy int…
james7132 Dec 7, 2022
db4c6d7
Apply suggestions from code review
james7132 Dec 8, 2022
7578306
Merge branch 'main' into abort-on-nonsend-drop
james7132 Dec 8, 2022
5e182fc
Move std::thread::panicking check to Drop impl
james7132 Dec 8, 2022
263ed85
Update safety comment about validate_access in Drop
james7132 Dec 8, 2022
e4a0a9a
Add the missing get_non_send_by_id APIs
james7132 Dec 8, 2022
5be8450
Formatting
james7132 Dec 8, 2022
587ea78
Add test for distinct storage and missing panic comments
james7132 Dec 8, 2022
68de55f
Make the safety comments on _by_id APIs more accurate
james7132 Dec 9, 2022
4e8412f
Reword panic docs.
james7132 Dec 12, 2022
ebe33dd
Merge branch 'main' into abort-on-nonsend-drop
james7132 Dec 12, 2022
87c88ab
Fix CI
james7132 Dec 12, 2022
6d39cd5
Merge branch 'main' into abort-on-nonsend-drop
james7132 Dec 19, 2022
8b8a735
Revert changes with NonSendMarker
james7132 Dec 19, 2022
6c8e988
Merge branch 'main' into abort-on-nonsend-drop
james7132 Jan 2, 2023
2c5be6d
Formatting
james7132 Jan 2, 2023
b236f9d
Merge branch 'main' into abort-on-nonsend-drop
james7132 Jan 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix CI
  • Loading branch information
james7132 committed Dec 4, 2022
commit d713d8440321fc160a308ad88e7ab994aff8072e
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/storage/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ impl<const SEND: bool> ResourceData<SEND> {
/// # Panics
/// If `SEND` is false, this will panic if a value is present and is not removed from the
/// original thread it was inserted from.
///
#[inline]
#[must_use = "The returned pointer to the removed component should be used or dropped"]
pub(crate) fn remove(&mut self) -> Option<(OwningPtr<'_>, ComponentTicks)> {
Expand All @@ -164,9 +163,8 @@ impl<const SEND: bool> ResourceData<SEND> {
/// # Panics
/// If `SEND` is false, this will panic if a value is present and is not
/// accessed from the original thread it was inserted in.
///
#[inline]
pub(crate) unsafe fn remove_and_drop(&mut self) {
pub(crate) fn remove_and_drop(&mut self) {
if self.is_present() {
self.validate_access();
self.column.clear();
Expand Down Expand Up @@ -236,7 +234,9 @@ impl<const SEND: bool> Resources<SEND> {
) -> &mut ResourceData<SEND> {
james7132 marked this conversation as resolved.
Show resolved Hide resolved
self.resources.get_or_insert_with(component_id, || {
let component_info = components.get_info(component_id).unwrap();
assert!(SEND == component_info.is_send_and_sync());
if SEND {
assert!(component_info.is_send_and_sync());
}
ResourceData {
column: ManuallyDrop::new(Column::with_capacity(component_info, 1)),
type_name: String::from(component_info.name()),
Expand Down
25 changes: 9 additions & 16 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,8 +1224,7 @@ impl World {
.storages
.resources
.get_mut(component_id)
// SAFETY: The type R is Send and Sync or we've already validated that we're on the main thread.
.and_then(|info| unsafe { info.remove() })
.and_then(|info| info.remove())
.unwrap_or_else(|| panic!("resource does not exist: {}", std::any::type_name::<R>()));
// Read the value onto the stack to avoid potential mut aliasing.
// SAFETY: pointer is of type R
Expand Down Expand Up @@ -1555,13 +1554,10 @@ impl World {
/// **You should prefer to use the typed API [`World::remove_resource`] where possible and only
/// use this in cases where the actual types are not known at compile time.**
pub fn remove_resource_by_id(&mut self, component_id: ComponentId) -> Option<()> {
// SAFETY: The underlying type is Send and Sync or we've already validated we're on the main thread
unsafe {
self.storages
.resources
.get_mut(component_id)?
.remove_and_drop();
}
self.storages
.resources
.get_mut(component_id)?
.remove_and_drop();
Some(())
}

Expand All @@ -1570,13 +1566,10 @@ impl World {
/// **You should prefer to use the typed API [`World::remove_resource`] where possible and only
/// use this in cases where the actual types are not known at compile time.**
pub fn remove_non_send_by_id(&mut self, component_id: ComponentId) -> Option<()> {
// SAFETY: The underlying type is Send and Sync or we've already validated we're on the main thread
unsafe {
self.storages
.non_send_resources
.get_mut(component_id)?
.remove_and_drop();
}
self.storages
.non_send_resources
.get_mut(component_id)?
.remove_and_drop();
Some(())
}

Expand Down