Closed lachlansneff closed 4 years ago
That would indeed be cool. I'm not aware of any prior discussion about it in the context of Wasm. However, as you guessed correctly, it would require a much more sophisticated type system, and such type systems are prone to be super-hard to combine with a variety of other features (cf. Rust and the decade-long quest to iron out the details of its semantics). It might also be difficult to target by compilers. Altogether very much a research problem -- which I'd be very curious to see somebody tackling.
@lukewagner and I were chatting about something like this in the context of Interface Types. But rather than guarantee safety through static types (because, as @rossberg said, that requires fairly sophisticated types), we would guarantee it through dynamic means in a way that would interact well with memory management. Anyways, we were halfway through the conversation when I got distracted by deadlines outside of wasm, but maybe we'll have something to get your thoughts on later.
@RossTate My initial thought was being able to convert an regular ref into an owning ref when there's just a single reference to the value, but I wasn't sure that's viable with a tracing garbage collector.
Agreeing with @rossberg here, a type system is a no go. But, that being said, I'd love to see discussion about dynamically enforcing this.
Cool. Will try to remember to follow up later. In the meanwhile, this probably is not an issue for the reference types proposal. The GC or Design proposals might be better fits.
I am closing this, since it is outside the scope of the current proposal. If there is enough interest, somebody should start a follow-up proposal.
I understand this is very late in this proposal's lifespan, so likely nothing can be changed at this point, but I'm wondering about whether move semantics were ever considered for references.
For example, in a situation where you're opening and closing a reference to a file (like in this example in the type imports proposal), you are required to have a "zombie" state where the file is closed internally, but there may still be references to the File alive. If some sort of move semantics were allowed, where you had an owning ref, and a non-owning ref, this kind of thing could be avoided.
I haven't really thought through whether this is possible without a really strong type-system (and lifetimes or something similar), so really I'm just wondering if there is prior discussion about something along these lines.