move icon indicating copy to clipboard operation
move copied to clipboard

[Bug] ICE invalid assign tmp local

Open zekun000 opened this issue 3 years ago • 5 comments

    struct Foo {
        a: u64,
    }

    #[test]
    fun ice() {
        use Std::Vector;
        let v = Vector::empty();
        Vector::push_back(&mut v, Foo {a: 10});
        let b = Vector::borrow(&v, 0);
        while (true) {
            b = &Vector::pop_back(&mut v);
            let Foo {a: _} = *b;
        };
        Vector::destroy_empty(v);
    }

this piece of code caused "ICE invalid assign tmp local"

zekun000 avatar May 04 '22 03:05 zekun000

Ah yes this one again... Should really give a better error message as I don't htink we will fix the underlying issue anytime soon

tnowacki avatar May 05 '22 17:05 tnowacki

So what is the issue and what is the workaround?

wrwg avatar May 05 '22 17:05 wrwg

No real workaround, if you expanded this to locals instead of temps, you will still get a borrow checker issue.

The minimal repro is

while (cond) {
   let tmp = e;
   let b = &tmp;
   ... use b ...
}

In the borrow checker, first time through the loop:

while (cond) {
   let tmp = e;  // assignment okay
   let b = &tmp; // b = { &tmp }
   ... use b ...
}

Second time through the loop

while (cond) {
   let tmp = e;  // ERROR assignment invalid! 'tmp' is still borrowed by 'b'!
   let b = &tmp; // b = { &tmp }
   ... use b ...
}

The error message just assumed this couldn't happen with a local variable created by the compiler, which happens if you make this example into:

while (cond) {
   let b = &e; 
   ... use b ...
}

You cannot borrow values on the stack in Move, so e gets bound to some local variable. and then the example is equivalent to the first one.

tnowacki avatar May 05 '22 17:05 tnowacki

I think we just need a proper error message instead of ICE for now

zekun000 avatar May 05 '22 19:05 zekun000

I think we just need a proper error message instead of ICE for now And line / column of the issue? (IIUC currently we don't have them)

msmouse avatar May 05 '22 19:05 msmouse