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][Compiler-v2] GLOBAL_REFERENCE_ERROR error due to invalid acquiring of resource #13146

Closed
rahxephon89 opened this issue May 1, 2024 · 1 comment · Fixed by #13484
Closed
Assignees
Labels
bug Something isn't working compiler-v2-stable compiler-v2 stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@rahxephon89
Copy link
Contributor

🐛 Bug

When compiling the following code:

module 0x8675309::A {
    use std::signer;
    struct T1 has key {v: u64}

    public fun test(account: &signer) acquires T1 {
        let x = borrow_global_mut<T1>(signer::address_of(account));
        acquires_t1(account);
        move x;
    }

    fun acquires_t1(account: &signer) acquires T1 {
        T1 { v: _ } = move_from<T1>(signer::address_of(account));
    }
}

V2 will generate bytecode verification error:

bug: BYTECODE VERIFICATION FAILED
  ┌─ tests/acquires-checker/v1-borrow-tests/borrow_global_acquires_invalid_1.move:7:9
  │
7 │         acquires_t1(account);
  │         ^^^^^^^^^^^^^^^^^^^^ ICE failed bytecode verifier: VMError {
    major_status: GLOBAL_REFERENCE_ERROR,
    sub_status: None,
    message: None,
    exec_state: None,
    location: Module(
        ModuleId {
            address: 0000000000000000000000000000000000000000000000000000000008675309,
            name: Identifier(
                "A",
            ),
        },
    ),
    indices: [
        (
            FunctionDefinition,
            1,
        ),
    ],
    offsets: [
        (
            FunctionDefinitionIndex(1),
            7,
        ),
    ],
}

While V1 generates the following compilation error:

error[E07003]: invalid operation, could create dangling a reference
  ┌─ tests/move_check/translated_ir_tests/move/borrow_tests/borrow_global_acquires_invalid_1.move:7:9
  │
6 │         let x = borrow_global_mut<T1>(signer::address_of(account));
  │                 -------------------------------------------------- It is still being mutably borrowed by this reference
7 │         acquires_t1(account);
  │         ^^^^^^^^^^^^^^^^^^^^ Invalid acquiring of resource 'T1'
@rahxephon89 rahxephon89 added bug Something isn't working stale-exempt Prevents issues from being automatically marked and closed as stale compiler-v2 labels May 1, 2024
wrwg added a commit that referenced this issue May 30, 2024
Closes #13146

Adds a check that a global resource is not borrowed when it is declared in the access specifier list of a function.

This implements the full semantics of Move 2.0 access specifiers. However, if the 2.0 language is not enabled, access specifiers other then `acquires` will be rejected by the context checker, and for that special case the behavior is equivalent.

In order to test the extended access specifier semantics, we need to disable the existing acquires checker, which is not yet implemented for general access specifiers.
wrwg added a commit that referenced this issue May 30, 2024
Closes #13146

Adds a check that a global resource is not borrowed when it is declared in the access specifier list of a function.

This implements the full semantics of Move 2.0 access specifiers. However, if the 2.0 language is not enabled, access specifiers other then `acquires` will be rejected by the context checker, and for that special case the behavior is equivalent.

In order to test the extended access specifier semantics, we need to disable the existing acquires checker, which is not yet implemented for general access specifiers.
wrwg added a commit that referenced this issue May 30, 2024
Closes #13146

Adds a check that a global resource is not borrowed when it is declared in the access specifier list of a function.

This implements the full semantics of Move 2.0 access specifiers. However, if the 2.0 language is not enabled, access specifiers other then `acquires` will be rejected by the context checker, and for that special case the behavior is equivalent.

In order to test the extended access specifier semantics, we need to disable the existing acquires checker, which is not yet implemented for general access specifiers.
wrwg added a commit that referenced this issue May 30, 2024
Closes #13146

Adds a check that a global resource is not borrowed when it is declared in the access specifier list of a function.

This implements the full semantics of Move 2.0 access specifiers. However, if the 2.0 language is not enabled, access specifiers other then `acquires` will be rejected by the context checker, and for that special case the behavior is equivalent.

In order to test the extended access specifier semantics, we need to disable the existing acquires checker, which is not yet implemented for general access specifiers.
JoshLind pushed a commit that referenced this issue May 30, 2024
Closes #13146

Adds a check that a global resource is not borrowed when it is declared in the access specifier list of a function.

This implements the full semantics of Move 2.0 access specifiers. However, if the 2.0 language is not enabled, access specifiers other then `acquires` will be rejected by the context checker, and for that special case the behavior is equivalent.

In order to test the extended access specifier semantics, we need to disable the existing acquires checker, which is not yet implemented for general access specifiers.
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 stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants