2 ms·
Can rust sanely encode constraints like "I don't want to be able to call functions that may call functions that sleep from atomic context" that would be checked
by megous 5y ago
Can rust sanely encode constraints like "I don't want to be able to call functions that may call functions that sleep from atomic context" that would be checked at compile time?
- guntars 5y agoI don't think so. Once a function is compiled, it basically becomes a black box with a type signature so unless sleeping in a function affects its signature, that information is erased. If you pass in some kind of a sleep token that has to be used to sleep, then yeah I think you could enforce it by only being able to get that token in a non-atomic context and making it leak proof. The Cortex-M crate does something similar, but for proving that you are in an atomic context. Another function that expects a CriticalSection type is then assured that it's running without interrupts enabled. The type itself is zero sized so it's completely optimized away. https://github.com/rust-embedded/cortex-m/blob/master/src/interrupt.rs#L55 https://github.com/rust-embedded/cortex-m/blob/master/src/in...