-
Notifications
You must be signed in to change notification settings - Fork 64
TrustCell fixes #223
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
TrustCell fixes #223
Conversation
`&mut T` which can be used to move `T` between threads!
address stacked borrows UB detected by Miri. This is similar to mozilla/atomic_refcell#18
Imberflur
left a comment
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.
Here are some notes to help reviewers
| miri: | ||
| name: "Miri" | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: true # Needed until all Miri errors are fixed |
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.
Added Miri to the CI, however it still runs into some errors in the MetaTable code that is handling vtable pointers. So I set continue-on-error: true for now (hopefully this does what I think it does...)
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.
Well it seems like there is no way to not show the red X in the PR list: https://github.com/orgs/community/discussions/15452
| black_box(world.fetch::<DeltaTime>()); | ||
| black_box(world.fetch::<VecStorage<Pos>>()); | ||
| black_box(world.fetch::<VecStorage<Spring>>()); |
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.
I added black_box just to be more sure that the compiler doesn't optimize these out (didn't really see much difference in the benchmark though)
| // https://github.com/rust-lang/rust/issues/63787 | ||
| #[test] | ||
| fn drop_and_borrow_in_fn_call() { | ||
| fn drop_and_borrow(cell: &TrustCell<u8>, borrow: Ref<'_, u8>) { | ||
| drop(borrow); | ||
| *cell.borrow_mut() = 7u8; | ||
| } | ||
|
|
||
| let a = TrustCell::new(4u8); | ||
| let borrow = a.borrow(); | ||
| drop_and_borrow(&a, borrow); | ||
| } |
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.
I added this to reproduce the scenario in the issue linked in the comment, however Miri was already reporting UB due to retagging of the reference by the mem::forget call in RefMut::map.
Fixing some unsoundness, see commit messages.
I'm hoping to eventually replace TrustCell with atomic_refcell::AtomicRefCell, however that should probably wait on mozilla/atomic_refcell#18