This also looks relevant for @simonmar’s proposal:
Interior mutability is a design pattern in Rust that allows you to mutate data even when there are immutable references to that data; normally, this action is disallowed by the borrowing rules. To mutate data, the pattern uses
unsafe
code inside a data structure to bend Rust’s usual rules that govern mutation and borrowing.
… and near the end of that article:
[…] By using
RefCell<T>
, we have an outwardly immutableList
value. But we can use the methods onRefCell<T>
that provide access to its interior mutability so we can modify our data when we need to. The runtime checks of the borrowing rules protect us from data races, and it’s sometimes worth trading a bit of speed for this flexibility in our data structures.
Hmm: “runtime checks”? “data races” ? Here’s an proposal that has already been accepted:
So the question is:
- will runtime checks also be needed in GHC for mutable fields in data constructors when used by multi-threaded programs?
If they are, it would seem to erase the main advantage of having mutable fields, namely improved performance (unless atomicity checks are now much cheaper).