News for hackers. Stuff that matters.
Re:The Pain of Real Linear Types in Rust by arjie on Tuesday May 09, 2017 @03:10PM (#14302980)
Perhaps this is obvious to everyone else, but it isn't to me. Are you advocating explicitly dropping every variable I create? Like `init; use; drop;` explicitly where right now I essentially do `init; use;` and then there's an implicit drop when we exit scope?
Re:The Pain of Real Linear Types in Rust by millstone on Wednesday May 10, 2017 @12:04AM (#14305844)
You would be required to drop values that aren't moved elsewhere. Currently Rust has a one-bit reference count which dynamically tracks which values need to be dropped. Linear types would transform this into a static property that the compiler checks.

Part of the pain would come from conditionals:

    if something { 
        func(val1);
    } else {
        func(val2);
    }
This would be disallowed because the liveness of val1 and val2 can't be statically known after the conditional.
Re:The Pain of Real Linear Types in Rust by adrianratnapala on Wednesday May 10, 2017 @01:23AM (#14306085)
If "val1" and "val2" are really things that have to be used exactly once, then the above code is already in error (unless they are provably the same object), and a compiler with linear types will correctly complain about it.

This is indeed "pain", but of a good kind (at least it if the error message is decent).

I admit there are harder cases:

    if(foo)
      func(val1)
    else
      func(val2)

    ... do something that doesn't change foo or use val1, val2 
    ...  

    if(!foo)
      func(val1)
    else
      func(val2)
Is correct, if strange, code which I assume is hard for a compiler to understand. But then it is hard for humans too.
Re:The Pain of Real Linear Types in Rust by adrianratnapala on Tuesday May 09, 2017 @11:09PM (#14305647)
I guess it is only for ones with nontrivial destructors.

That makes the "trivialness" of a destructor part of the interface, which is a price. But then from my experience in C++, we pay that price anyway, because to have any sort of assurance about what you are doing, you need some clue about what the destructor does.