Could the gc-case be made noise-free by default?


#1

I am somewhat in awe of how Rust seems to distill the essence of pointers & memory management while offering great abstraction tools, and while still allowing a way out to more pampered programming, up to Gc.

However, for my applications, I initially approach my problems without wanting to think about lifetime & ownership, and only add that in when and if it becomes necessary. Consequently I also do not want to see any annotations that are related to lifetime & ownership until I actually want to think about them. At which point I will be extremely glad to have the Rust type-centered way to help structure those thoughts.

In this sense, those annotations constitute noise unless I want to think about them. I’d like to follow this path whether working in some typical business domain, or deep in the bowels of some embedded real-time code.

So in my dreams my typing would start off looking about as light-weight as in Haskell (other than the mandated top-level signatures, but without any Gc<T>), and other annotations like & 'a 'b Rc would only show up when I invite them in – in fact, if possible Gc would never even be explicitly needed at all.

Just wondering if this:

  1. makes sense as a language-design goal?
  2. was considered but turned out impossible for Rust?
  3. was not a goal?
  4. never will be a goal?

Thanks!


#2

Seems unlikely. One of Rust’s explicit goals is memory safety so you’ll need to consider ownership from day one of high-level architecture design.

I agree though that lifetime annotations, as they are now, have a rather noisy appearance. I asked the community to consider dropping the apostrophes, but the reception was cold.


#3

Once you’ve built your program around multiple references, it’s going to be hard to untangle.


#4

You cant avoid the type system. Rust has the power of memory safety without garbage collection because we have lifetimes and lifetime annotations, you cant just not use them because you don’t want to think about them

If you want a “gc-case” please go to Haskell, Python, Go, etc. That is not what this language is for.


#5

Thanks. I do understand that the annotations are essential for gc-less memory safety.

I believe gradually typed systems include an unknown “?” type where a type is not annotated or otherwise inferred, and then address the bridge between that ? and normal known types, including some run-time bridging costs. So my questions were whether a similar design goal might make sense on the memory-safety side of Rust types ("?" for unknown memory management attributes), and if it was ever considered. And I was wondering if there are somewhat systematic ways of bridging Gc and the other memory management types.


#6

I remember someone on Rust team on Reddit saying that maybe they could make an unsafe dialect of Rust, in lieu of Johnatan Blow criticism of Rust being a Big Idea Language. That’s about it. What an unsafe dialect of Rust would contain is anyone’s guess.

Although, gradual typing wasn’t mentioned as far as I’m aware.


#7

You can essentially push all compile time lifetime issues out to the runtime by using Arc<Mutex<T>> everywhere you would normally use a reference to T (or Rc<RefCell<T>> if you are confidently single-threaded, but this will restrict your code more). You can even alias it to P<T> to make it easy to type. Generally speaking this is an awful idea, but it seems pretty much the same as using gradual typing in spirit.

ISTM that a “no-friction” GC is unlikely to happen in safe Rust, because Rust just supports too much stuff. You can take away multithreading (and all code that requires Send / Sync) and get pretty noiseless GC, or take away ADTs and live with a Javaesque type system, or you can live without references as values at all, or you can just say “screw safety” and unsafe all the things. But none of those seem very frictionless to me. Even if you use one of those solutions, I very much doubt that any prototype you came up with would be any easier to convert to idiomatic Rust than if you’d done it in, say, Scala (only the Scala version would have been faster, easier to write, and been able to use the entire language).


#8

I am hoping that the default trait bounds will eventually be customizable. Among other uses, one could demand that every type implements Traceable (or whatever GC would use).


#9

I know how you feel when trying to design your application and being burdened with learning the language.

The good news is once you get better lifetimes will become easier. You might also find reference counted smart pointers easier to use in your application design by saving &-pointers for short lived local optimizations. Also keep in mind your types can wrap a smart pointer making it hidden and uncumbersome. For example MyType instead of Rc<MyType>.

Just keep learning and practicing and also keep in mind there may be improvements to Rust over time that make it easier!