Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][move-compiler] V2 does not warn semantic difference #14588

Open
zzjas opened this issue Sep 10, 2024 · 1 comment
Open

[Bug][move-compiler] V2 does not warn semantic difference #14588

zzjas opened this issue Sep 10, 2024 · 1 comment
Assignees
Labels
bug Something isn't working compiler-v2-stable compiler-v2 move-smith stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@zzjas
Copy link

zzjas commented Sep 10, 2024

🐛 Bug

//# publish
module 0xCAFE::Module0 {
    use std::vector;
    struct S has copy, drop, store, key {
        v: vector<u8>
    }

    public fun f1(s: signer) acquires S{
        move_to<S>(&s, S {v: vector::empty()});
        f2(1)
        ^ 
        if (true) {
            f2(2)
        } else { 0 };
    }

    public fun f2(x: u8): u8 acquires S {
        let s = borrow_global_mut<S>(@0xBEEF);
        vector::push_back(&mut s.v, x);
        x
    }
}

//# run 0xCAFE::Module0::f1 --signers 0xBEEF

//# view --address 0xBEEF --resource 0xCAFE::Module0::S

Running this as transactional test will give:

comparison between v1 and v2 failed:
= processed 3 tasks
= 
= task 2 'view'. lines 27-27:
= copy drop store key 0xcafe::Module0::S {
-     v: 0201
+     v: 0102
= }
=

A warning about the difference between V1 and V2 semantics is expected.

@zzjas
Copy link
Author

zzjas commented Sep 14, 2024

Similar case:

//# publish
module 0xCAFE::FuzzStore {
    struct S has drop, copy, store, key {
        x: u8
    }

    fun init(s: signer) {
        move_to<S>(&s, S { x: 0 });
    }
    public fun inc() acquires S {
        let s = borrow_global_mut<S>(@0xBEEF);
        s.x = s.x + 1;
    }
}

//# run 0xCAFE::FuzzStore::init --signers 0xBEEF

//# publish
module 0xCAFE::Module0 {
    use 0xCAFE::FuzzStore::inc;
    public fun f1(): u8 {
        f2() ^ (return 123u8);
        0
    }

    public fun f2(): u8 {
        inc();
        0
    }
}

//# run 0xCAFE::Module0::f1

//# view --address 0xBEEF --resource 0xCAFE::FuzzStore::S

Transactional output:

...
= task 4 'view'. lines 34-34:
= copy drop store key 0xcafe::FuzzStore::S {
-     x: 0u8
+     x: 1u8
= }

Compiling with aptos move compile --compiler-version=2 --language-version=1 didn't give any warning.

I had to use a separate module for this one because V1 will optimize away the left operand -- making the compiler fail with extraneous acquires error.

@brmataptos brmataptos added the stale-exempt Prevents issues from being automatically marked and closed as stale label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler-v2-stable compiler-v2 move-smith stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
Status: Assigned
Development

No branches or pull requests

3 participants