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][move-compiler-v2] unbound function module in function_info.move:99:12 #13216

Closed brmataptos closed 1 day ago

brmataptos commented 1 week ago

🐛 Bug

@movekevin reports that a user reports:

I started getting recently these kind of errors on deployment:
error: unbound module
   ┌─ /home/.../move/https___github_com_aptos-labs_aptos-core_git_main/aptos-move/framework/aptos-framework/sources/function_info.move:99:12
   │
99 │     friend aptos_framework::function_info_tests;
   │            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unbound module '(aptos_framework=0x1)::function_info_tests'
brmataptos commented 1 week ago

I've managed to see this problem intermittently but can't reproduce it reliably. I think that (1) the libraries are being built without #[test_only] code, but then a user #[test] function which includes module aptos_framework::function_info may wind up parsing the #[test_only] friend ... at the end of that module which refers to a module (function_info_tests) which doesn't exist in the current compilation environment. The right solution may be to fix the compiler to silently ignore a friend declaration referring to an unknown module.

File aptos-move/framework/aptos/framework/tests/function_info_tests_.move has:

#[test_only]
module aptos_framework::function_info_tests {
...
}

and file aptos-move/framework/aptos-framework/sources/function_info.move has:

/// The `function_info` module defines the `FunctionInfo` type which simulates a function pointer.
module aptos_framework::function_info {
...
    // Test only dependencies so we can invoke those friend functions.
    #[test_only]
    friend aptos_framework::function_info_tests;
}

I think the problem is that (1) the #[test_only] code is excluded from the compiled Aptos Framework, but the

brmataptos commented 1 day ago

This has been hard to reproduce, but I found it happening in a case where I had files from a previous build/tool left behind in a Move package build/ directory, which were found by the move-package mechanism to search for dependency source files.

We'll close this with 3 followup issues: