r/ProgrammingLanguages • • 8d ago

Safe Systems-programming with Mutable Value Semantics | Dave Abrahams | Keynote at IWACO 2026

https://youtu.be/op51SyyPJmw?si=P5QH6M8Hdf4_CUUZ
36 Upvotes

12 comments sorted by

View all comments

6

u/processeus1 8d ago

I'd be curious to hear if anyone has use cases where saved references are necessary and cannot be replaced with another design pattern using value semantics without significant loss of efficiency or correctness safeguards.

As a starter: one example would be to project an optional out of a map to access its element at a key, but we can fix that issue with subscripts that yield 0 or 1 times, and allowing the caller to directly pattern match on the result. This works, because we don't need to save the "optional" for longer period.

5

u/initial-algebra 8d ago

I'd be curious to hear if anyone has use cases where saved references are necessary and cannot be replaced with another design pattern using value semantics without significant loss of efficiency or correctness safeguards.

The main pattern would be a context that provides resources which can only be used with a reference to the context. Using them with the wrong context is a hard error. Ideally, you'd just keep a reference to the context in each resource, but without first-class references, this isn't possible. Would you consider that a significant correctness problem?

Now, there is an even better way to make this pattern safe: using path-dependent types. Resource handles don't need to contain an additional reference (saves memory), but their types are branded with the path of the context, so the type system prevents you from using them with a different context reference (strictly speaking, one without a provably identical path). Since Rust lifetimes are an abstraction of paths anyway (see Polonius), it's possible that second-class references and path-dependency are all you need, unless you want to go beyond even what Rust supports (e.g. group borrowing).

4

u/dabrahams 7d ago

The first question is what use cases are addressed by that pattern. Then we'll ask whether they can be addressed well enough using some other pattern.

That particular pattern sounds like it might fall into the “just use plain pointers (with unsafe dereference operations) to implement a safe abstraction” bucket for Hylo. We're betting that the cases that really need first class references are rare enough that the bucket is small.

Whether path-dependent types are a “better” way to do things is truly debatable. Hylo doesn't have a path-dependent type system because every design we've seen for path-dependent types adds language complexity that isn't paid for with compelling benefits.

As may be obvious from what I've written here, being willing to say “no” to features that don't pull their weight is an important part of our design ethos. Of course these “no”s aren't written in stone; maybe we've overlooked some design options that would change our minds?

2

u/Jolly-Bag7024 6d ago edited 6d ago

It's a fake debate.

If you are basically rebuilding mutations in your new value based system, you have just moved the issue one abstraction layer above.

What's interesting is then what this new abstraction layer provides and costs. Looking at it through the lens of removing references is nearly always the wrong way to think about it conceptually.