Conversation

My entire point is that static analysis works much better when it's supported by the type system / language. External static analysis is greatly enhanced by a language providing stronger static guarantees that making code easier to analyze. It's easy to think about and evaluate.
2
1
But you also support addition types of annotation I presume that could help with more extensive analysis like with shared memory structures etc ? It's a difficult problem to think through. The problems I saw with analysis were with memory allocator implementations 1/
1
and streams interfaces with dynamic memory structures. Shared memory is also subject to race condition issues and other runtime scenarios that makes it difficult for static analysis. I'm sure these are well known issues but I'm a frustrated with language designer's 2/
2
In Rust, the language has a concept of types that are thread safe and can be shared, along with types that are safe to send between threads. For example, Rc<T> uses non-atomic reference counting and isn't Send. Arc<T> is a Send variant. Mutex<T> is a Sync variation of RefCell<T>.
1
1
So you can use Arc<Mutex<T>> for thread-safe shared mutable data. It also supports sharing mutable data between threads via atomics or without any synchronization at all via the standard reference safety system which enforces that mutable references do not alias anything else.
2
1
So for example you can divide up an array into non-overlapping mutable slices (pointer + length views) sent to different threads with their lifetimes constrained by the compiler to not outlive the data. It prevents data races (not higher level race conditions) in the type system.
2
1
Linux kernel driver layers can have rather complicated nested structures. Some are a hybrid of of two subsystems like USB and ALSA (audio). Both have smaller structures inside them per each subsystems. In the case of a class compliant USB audio driver, both subsystems 1/
2
are combined into one structure. They then have to share references in the code across subsystem which, from my picture of modern type systems, can be really complicated if it's in the form of type inheritance. Maybe i'm misunderstanding you here but that's my internal picture 2/
1
The way that Mutex<T> works is that you call the method to obtain the lock, and it gives you a mutable reference that the compiler prevents from outliving the lock scope. It simply uses the existing language features, just like the collections / iterators. It's pure library code.
1
1
RefCell<T> is pretty much the same thing for single-threaded cases, if you need dynamic mutable references for something that cannot be represented via the usual static aliasing checks. It's usually not needed as the rules for static checks can represent a lot of patterns.
1
1
Show replies