News for hackers. Stuff that matters.
Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by staticassertion on Thursday December 23, 2021 @01:00PM (#29664469)
It doesn't guarantee it under all circumstances, like if your computer shuts off obviously destructors don't get called. But you can rely on the behavior to be deterministic.
Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by klodolph on Thursday December 23, 2021 @01:25PM (#29664757)
You can rely on the behavior to be deterministic, but the Rust type system provides no way on relying on this determinism. For example, if you have a stack variable and pass a reference to a short-lived thread, Rust will just throw an error, because there is no way for Rust to prove that the lifetime of the borrow is short enough (bounded from above) because Rust does not have linear types.

I want it to be exactly clear what I'm saying... While you (the programmer) may understand when an object is destroyed, and Rust (the compiler) will agree with you, that information is not present in the type system and you cannot use it in your programs. In this aspect, Rust has the same problems as C++... but where C++ still lets you write code, Rust will just throw an error and force you to use "unsafe" here.

Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by zozbot234 on Thursday December 23, 2021 @01:40PM (#29664941)
> For example, if you have a stack variable and pass a reference to a short-lived thread, Rust will just throw an error, because there is no way for Rust to prove that the lifetime of the borrow is short enough (bounded from above) because Rust does not have linear types.

Rust has scoped threads for this use case. Generally this uses closures as opposed to lifetimes to "bound borrows from above" in a safe way.

Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by klodolph on Thursday December 23, 2021 @01:43PM (#29664990)
Rust has crossbeam, but it is not a complete solution to the problem. Scoped threads were removed.
Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by ssokolow on Thursday December 23, 2021 @02:29PM (#29665520)
Would you mind elaborating?

It was removed from the standard library ages ago, but `crossbeam::scope` appears to still be there in the newest release of crossbeam and the git repo.

Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by klodolph on Thursday December 23, 2021 @10:55PM (#29669987)
Using a scope for spawning threads is a solution to a narrow slice of a much larger problem.
Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by staticassertion on Thursday December 23, 2021 @01:27PM (#29664782)
Yes, that's correct. I just want to be clear that it's not like destructors in rust are unreliable in the way that finalizers are in Java.
Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by klodolph on Thursday December 23, 2021 @01:34PM (#29664865)
To be clear, I definitely wasn't talking about that.

Since you can't use the type system to guarantee that an object is destroyed, there are a few things in Rust that are a major pain to get working. Like passing a reference to a short-lived thread.

Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by staticassertion on Thursday December 23, 2021 @03:52PM (#29666323)
It's not that hard in my experience. You generally do it by using a guarded scope where the user provides a callback and doesn't manage the resource (like a thread) themselves.
Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by klodolph on Thursday December 23, 2021 @10:58PM (#29669992)
Sure, if that works for you, it's easy. Stuff like crossbeam::scope only solves a subset of the problem, though. When that solution doesn't work for you, it's a pain.

Using a scope is, strictly speaking, less powerful and more annoying to work with than a more general system of linear types. It's like Go's defer, or C#'s using/IDisposable... they work in certain scenarios, but there's a percentage of the time where a lexical scope or function scope doesn't match the lifetime of your object, or can't match the lifetime of your object.

Re:Does the Bronze Garbage Collector Make Rust Easier to Use? by staticassertion on Friday December 24, 2021 @11:41AM (#29675022)
Yep, agreed.