r/ProgrammingLanguages • u/FedericoBruzzone • Apr 30 '26
The Mutable Value Semantics (MVS): A Non-superficial Study
I’m researching a new semantics for a new language. During this process, I studied the Mutable Value Semantics (MVS) and I wrote a post about it. I simply want to share this study with you all and I'd love to hear your thoughts.
A new post will be coming soon where I'll discuss the limitations I’m finding in current models, and what I’d like to have for my own.
Link: https://federicobruzzone.github.io/posts/eter/MVS.html
28
Upvotes
11
u/tmzem May 01 '26
I've tried to design my own language with MVS and eventually given up, since the conflicting requirements are just pulling in too many directions and I've come to the conclusion that there is no good sweet spot, also most of the potential design space is already thoroughly explored by Mojo, Hylo, Inko (and maybe now Eter, I will give it a look).
Your post sums up some of the broader issues, but the really hairy part starts as soon as you want to return aliases/references from functions, or put them as fields into data types. This capability is pretty much necessary for implementing common features found in modern languages, like closures, iterators (and the optionals and key-value-pairs required for them) and slices. Once you add them, there is a bunch of points to consider:
Memory safety: Will require some kind of lifetime/borrow system, with some common cases not being easily representable via "sane defaults"/lifetime elison:
Second-class references & generics: The reference-ness can be either a type qualifier (like in C++) or a property of the variable/parameter (like in C#). Either way, generics pose a problem:
8
u/SkiFire13 May 01 '26
A small note on this: in theory Rust could have supported this but unfortunately it is unsound when combined with catching panics/unwinds. That is, if
own_tpanics/unwinds and the caller ofref_mut_tcatched this panic/unwind they would be able to observe the mutable reference now pointing to invalid memory. Rust has a trait for unwind safety but despite the name it was never used for soundness (e.g. preventing a&mutfrom being passed tocatch_unwind) so this issue can no longer be prevented.I'm curious to see how Hylo will approach this.
2
u/dabrahams May 03 '26 edited May 03 '26
There are a few points in your article that seem to reflect misunderstandings.
Swift absolutely does not try to make values look like references: it goes out of its way to present a pure value semantics. Structs in general do not use copy on write. CoW is merely an implementation technique used in the standard library to provide value semantics for variable size data structures like arrays and dictionaries (the only possible way in fact because there are no copy constructors). There is no user experience of shared mutable state whatsoever unless you opt in by using reference types or closures with mutable captures (an unfortunate design compromise).
What you call a central tension doesn't make sense to me: runtime efficiency, local reasoning, and value equivalence are perfectly compatible, and arguably support one another. Certainly, Hylo provides all three and we don't ever feel the need to compromise one of them to get another.
Also, the use of the term "deep copy" is a bit of a red flag. The only time you ever say "deep copy" or "shallow copy" is when you don't understand the extent of your value. In fact, there is only "copy", which copies the value, and nothing more or less. Our paper says as much in section 2.4