Comments (4)
I believe this is basically an area that Miri or sanitizer should handle. It would be very difficult to detect the okay assume_init call such as MaybeUninit<[T;N]>
-> [MaybeUninit<T>;N]
on the library side.
from loom.
It would be very difficult to detect the okay assume_init call such as MaybeUninit<[T;N]> -> [MaybeUninit;N] on the library side.
It may be difficult if we wanted to detect every possible way of interacting with the MaybeUninit value. But I think this would already be very useful when we can detect issues if users restrict themselves to a subset of the std API (i.e. don't use pointers or transmute). The advantage of loom is that it can explore all possible interleavings, which I don't think miri or sanitizers could offer.
What I have in mind boils down to the following:
function | Behavior |
---|---|
as_ptr / as_mut_ptr |
Transition the state to Unknown , which effectively disables assertions as long as we are in this state. |
new |
Create with state initialized |
assume_init and friends |
Assert that the value is initialized (unless we are in the Unknown state) |
uninit |
Create with state uninit |
write |
Set state to initialized |
read |
Assert that the value is initialized (unless we are in the Unknown state) and transition to unknown |
take |
assert that the value is initialized and transition the state to uninit |
zeroed |
Create with state Unknown |
from loom.
assert that the value is initialized and transition the state to uninit
This is not always correct. The type could be Copy
, in which case it remains initialized (and its not possible to check whether its Copy in generic code). It's also possible that the type has only Copy fields but isn't Copy itself — in this case it can still be ok for it to remain initialized. Furthermore, the user could also mem::forget
the value and conceptually have this transfer the value back into the MaybeUninit
.
from loom.
This is not always correct. The type could be Copy, in which case it remains initialized (and its not possible to check whether its Copy in generic code).
I updated the table to also include a read
method which transitions to the Unknown state.
take
is meant to be used when the user explicitly wants to take ownership of the value and move it out.
There are very clear limitations of what we can check, but I think it would work well for data structures like a queue or stack, where you want to insert something once, and then take the value out again exactly once and never twice.
from loom.
Related Issues (20)
- Atomic operations on part of an atomic integer? HOT 3
- What to do when loom::AtomicUsize do not implement as_mut_ptr() HOT 7
- Using `Notify` reports deadlock, while a hand-rolled event does not
- Loom panics HOT 6
- Document for debugging a test case
- Implement atomic-await
- Constructing a !Sized UnsafeCell HOT 4
- Provide a method for spawning scoped threads
- Stack size of spawned threads is not configurable HOT 2
- Panic at loom-0.6.0/src/rt/scheduler.rs:134:48
- `repr(transparent)` for `UnsafeCell`
- Is it possible for `loom::sync::Mutex::new` to be const available? HOT 7
- Add lock_arc API to loom Mutex
- panicked at 'called `Option::unwrap()` HOT 4
- Missing SyncUnsafeCell HOT 1
- Upgrade generator to 0.8
- [feature request] Configure stack size of default thread
- `loom::thread_local` does not support const-initialization
- `loom::LocalKey` does not support specialized implementations for `LocalKey<Cell<T>>` or `LocalKey<RefCell<T>>`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loom.