So like
Rust has the ownership model

The ownership model says that you can have EITHER one writer XOR many readers

The ownership model has two benefits:
- Allows safe, exact memory management (concrete)
- Decreases bugs (claimed by Rust fans)

Say I wished to remove the XOR from the ownership model— I write a linear typed language, and my rule is only "at most one writer". Is there any reason this would be impossible? (Say I don't care about the claimed bug reduction, only memory management.)

Follow

@mcc

Nit: that's not exactly correct. You can have multiple mutrefs, but all but one have to be "borrowed from".

Do I UC that you'd want to not have readonly references at all?

I think it'd be possible, but exceedingly annoying: see what kinds of variants methods that e.g. split slices in Rust need (so that you can e.g. split a mutref to a slice into two mutrefs to parts of that slice _as long as they don't overlap_). You'd need to go through those hoops for nonmutable references too (so, you would not be able to multiply x with x without either making a copy of x or having a specialized squaring function). Also, closures would be barely practical: whatever they capture couldn't be touched until the closure goes out of scope.

@robryk I would consider "all mutrefs must be borrowed" to be another way of saying "there is only one mutref at a time". Insert the word "live' if it makes you more comfortable.

@robryk Also I am unsure whether your response is actually responsive to my question (I am interested in: Is the object freed when and exactly when there are no more references to it, not: is the logic of the language internally consisistent)

@robryk Also:

Do I UC that you'd want to not have readonly references at all?

No?

@mcc

> my rule is only "at most one writer"

So, any number of readers *and* at most one writer?

I don't quite see how this restriction helps with memory management (or rather, helps with statically ensuring that memory management is correct) over allowing multiple writers but requiring lifetimes of all references to ~match.

@robryk Well, maybe I should go with that last thing then.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.