GankroOPrust•

Here's a TL;DR for those who just want to know the high level details:

https://gist.github.com/Gankro/1f79fbf2a9776302a9d4c8c0097cc40e

Most interesting to Rust people:

  • shared XOR mut
  • implicit RefCell-ish things when static analysis is too strict (class props, globals, escaping closures)
  • coroutines as the primary mechanism for "returning" borrowed values (important because mutable refs can require a "cleanup" step)
  • shared access is still pass-by-value
  • move semantics are very low priority, something users should be able to learn late if ever
  • no lifetimes (ever?) or concurrency (yet)
32
kibwen•

Yet to begin reading this epic wall of text, but if "no lifetimes ever" is really their sentiment, then AFAIR this would seem to represent critical backtracking from the future that Lattner was publicly envisioning.

14
dbaupprust•

I don't recall Lattner ever mentioning anything about explicit lifetimes, only general "imaginings" about Rust-inspired ownership features.

11
kibwen•

Maybe I'm just reading too much into it, but I thought I remembered the word "borrowing" being thrown around, which to me implies explicit lifetimes somewhere. I can't remember the source though, so maybe I'm just delusional.

5
GankroOPrust•

The coroutine system gives many of the same effects/benefits as lifetimes. The main thing missing from this design is a struct being able to directly store a "reference" (rather than materializing them from a getter).

edit: for instance, I believe this system makes IterMut actually work the way you want it (statically preventing access to parent collection), however you can't persist mutable references outside their iteration of the loop. This is a pretty good 90% outcome.

13
dbaupprust•

Yeah, I think you (perfectly understandably) read too much into it. As Gankro says in a sibling, borrowing and explicit lifetimes are somewhat independent: one can have a subset of Rust's borrowing without explicit lifetimes, and lifetime elision is exactly an example of this. Not being able to explicit connect different borrows with lifetimes is definitely less powerful, but still allows many common things to work (again, see the success of lifetime elision in Rust).

10
pjmlp•

If I remember correctly, the sentiment was more a feature to be only used when reaching out for high performance, not something that a regular Swift developer would need to worry about on his/her daily coding.

3
digikata•

Theres no mention of this that I see, but could this be a way of integrating with garbage collection? E.g. when the compiler tracks ownership you might be able to hold off GC operation until key points such as when the compiler 'knows' when ownership expires at the end of a lifetime.

1
GankroOPrust•

I'm unaware of any interest in the Swift community in integrating with GC.

ARC is love. ARC is life.

10
pjmlp•

They already have a GC, just not a tracing one. :)

But it doesn't make any sense to change, Swift has ARC because it needs to interoperate with Objective-C runtime.

Having a tracing GC would mean a solution like .NET has for interoperability with COM, where the runtime wraps the COM instances and takes care of translating the semantics between tracing collection and reference counting, leading to a more complex design.

Runtime Callable Wrapper

COM Callable Wrapper

3
desiringmachines•

This is interesting but for my purposes its a little disappointing. I was hoping that in experimenting with ownership without our 'zero-cost' requirement, Swift would make breakthroughs in usability. This does not seem more easy to use than our system, with all of the other concepts it has to incorporate from Swift as it exists.

One thing Swift has going for it is that you can usually learn about the language's complexity incrementally, rather than upfront. I'd like to see us get somewhat closer to that, which is a big part of what 2017's roadmap is about.

15
arconx•

In all honesty, not seeing a lot of progress on that front. With Rust hitting 1.17 there have been only a few semantic changes that make it more easy to read. But it does not alters the whole ownership/lifetime/etc concept that a lot of new people struggle with.

Then there is also the issue that a lot of older rust programmer will write in the "old" way, showing example more "old style". And most of the Rust example on the internet suffering the same.

Swift has the same issue with it transition from Swift 1 to 2 and 3. Too much examples are leftovers from the "old" way.

The advantage of swift there way is people can learn with ARC and slowly move to non-arc if they want or need to. Best of both worlds.

Rust does not have that luxury.

1
ThePantsThief•

What would you like to have seen instead? Curious

1
desiringmachines•

I was hoping it would have something I had never considered before; I don't know of a way to make borrowing easier while still giving the same static analysis guarantees, even if you're willing to be slower at runtime.

1
[deleted]•

[removed]

-8