aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
5.85k stars 3.54k forks source link

[Bug][compiler-v2] Reference safety has different behavior when mut refs and inline functions are involved #13177

Open vineethk opened 2 weeks ago

vineethk commented 2 weeks ago

🐛 Bug

Consider the following Move program:

module 0xc0ffee::m {
    inline fun inc(x: &mut u64): u64 {
        *x = *x + 1;
        *x
    }

    fun add(x: u64, y: u64): u64 {
        x + y
    }

    public fun test(): u64 {
        let x = 1;
        x + inc(&mut x) + inc(&mut x)
    }
}

When it is compiled with v1, we get a reference safety error ("invalid operation, could create dangling a reference"). When compiled with v2, there is no compiler error or runtime error.

Because this is a divergent behavior between the compiler, I am opening an issue to track it; we may decide this is not an actual bug, but that v2 just accepts more (safe) programs than v1.