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] BORROWFIELD_EXISTS_MUTABLE_BORROW_ERROR raised in factor_invalid_2 #12781

Closed
rahxephon89 opened this issue Apr 3, 2024 · 1 comment · Fixed by #13314
Closed
Assignees
Labels
bug Something isn't working 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 in the test case factor_invalid_2:

module 0x8675309::M {
    struct S { g: u64 }

    fun t1(root: &mut S, cond: bool) {
        let x1 = 0;
        let eps = if (cond) bar(root) else &x1;
        // Error: root has weak empty borrow and hence a field cannot be borrowed mutably
        &mut root.g;
        eps;
    }

    fun bar(a: &mut S): &u64 {
        &a.g
    }
}

the bytecode verification error: BORROWFIELD_EXISTS_MUTABLE_BORROW_ERROR is raised.

@rahxephon89 rahxephon89 added bug Something isn't working stale-exempt Prevents issues from being automatically marked and closed as stale compiler-v2 labels Apr 3, 2024
@rahxephon89 rahxephon89 self-assigned this Apr 3, 2024
@rahxephon89
Copy link
Contributor Author

This is a smaller POC:

module 0x8675309::M {
    struct S { g: u64 }
    fun t1(root: &mut S) {
        let eps = bar(root);
        &mut root.g;
        eps;
    }
    fun bar(a: &mut S): &u64 {
        &a.g
    }
}

However, the following program does not generate the bytecode verification error:

module 0x8675309::M {
    struct S { g: u64 }

    fun t1(root: &mut S) {
        let eps = &root.g;
        &mut root.g;
        eps;
    }
}

@rahxephon89 rahxephon89 removed their assignment Apr 4, 2024
@wrwg wrwg self-assigned this Apr 4, 2024
wrwg added a commit that referenced this issue May 17, 2024
Fixes #12781

This also refactors and simplifies the releasing of references before write operations. I initially thought this was the problem but it wasn't, anyway the refactoring simplifies the code a bit.
wrwg added a commit that referenced this issue May 21, 2024
Fixes #12781

This also refactors and simplifies the releasing of references before write operations. I initially thought this was the problem but it wasn't, anyway the refactoring simplifies the code a bit.
wrwg added a commit that referenced this issue May 22, 2024
Fixes #12781

This also refactors and simplifies the releasing of references before write operations. I initially thought this was the problem but it wasn't, anyway the refactoring simplifies the code a bit.
wrwg added a commit that referenced this issue May 22, 2024
Fixes #12781

This also refactors and simplifies the releasing of references before write operations. I initially thought this was the problem but it wasn't, anyway the refactoring simplifies the code a bit.
wrwg added a commit that referenced this issue May 22, 2024
Fixes #12781

This also refactors and simplifies the releasing of references before write operations. I initially thought this was the problem but it wasn't, anyway the refactoring simplifies the code a bit.
wrwg added a commit that referenced this issue May 22, 2024
Fixes #12781

This also refactors and simplifies the releasing of references before write operations. I initially thought this was the problem but it wasn't, anyway the refactoring simplifies the code a bit.
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 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