anza-xyz / move

Move compiler targeting llvm supported backends
https://discord.gg/wFgfjG9J
Apache License 2.0
108 stars 33 forks source link

[Bug] unreachable code in struct type to llvm type conversion while compiling standard library tests #312

Closed dmakarov closed 1 year ago

dmakarov commented 1 year ago

🐛 Bug

Move-to-solana translator reaches an unreachable!() while converting a struct type to llvm type. This is triggered by struct type not being found by the struct name.

To reproduce

This bug is currently difficult to reproduce because it is triggered while compiling move-stdlib unit tests. This is enabled by the move test --solana that I'm currently working on.

The command to reproduce the problem follows (run in move repository top-level subdir)

RUST_LOG=move_to_solana=debug \
LLVM_SYS_150_PREFIX=<path/to/move-dev> \
PLATFORM_TOOLS_ROOT=<path/to/platform-tools> \
MOVE_NATIVE=language/move-native \
cargo run -p move-cli --features solana-backend --bin move -- \
test --solana -p language/tools/move-cli/tests/move_unit_tests/assign_dev_addr_for_dep -d

Stack trace/error message

[DEBUG language/solana/move-to-solana/src/lib.rs:419] Generating code for module 0x1__bcs_tests
thread '<unnamed>' panicked at 'internal error: entered unreachable code: struct type for 'struct.bcs_tests__Box63_bcs_tests__Box63_#0__' not found', language/solana/move-to-solana/src/stackless/module_context.rs:567:25

The move-cli with solana test runner currently exists only on my branch https://github.com/dmakarov/move/tree/dm/test

jcivlin commented 1 year ago

See this, may be the same: https://github.com/solana-labs/move/issues/250

jcivlin commented 1 year ago

Here is a simple reproducer.

sol@dev-equinix-new-york-2:~/work/git/move/language/tools/move-mv-llvm-compiler/tmp:090223-cli-corrections *$%$ pwd
/home/sol/work/git/move/language/tools/move-mv-llvm-compiler/tmp
sol@dev-equinix-new-york-2:~/work/git/move/language/tools/move-mv-llvm-compiler/tmp:090223-cli-corrections *$%$ ll Move.toml sources/
-rw-r--r-- 1 sol users  145 Sep  3 23:48 Move.toml

sources/:
total 12
drwxr-xr-x 2 sol users 4096 Sep  3 06:25 ./
drwxr-xr-x 6 sol users 4096 Sep  3 23:55 ../
-rw-r--r-- 1 sol users  247 Sep  4 00:42 my_option_tests.move
sol@dev-equinix-new-york-2:~/work/git/move/language/tools/move-mv-llvm-compiler/tmp:090223-cli-corrections *$%$ less Move.toml 
[package]
name = "my_option_tests"
version = "1.5.0"

[addresses]
std = "0x1"

[dependencies]
MoveStdlib = { local = "../../../move-stdlib/" }

sol@dev-equinix-new-york-2:~/work/git/move/language/tools/move-mv-llvm-compiler/tmp:090223-cli-corrections *$%$ less sources/my_option_tests.move 
#[test_only]
module 0x1::my_option_tests {
    use std::option;

    #[test]
    fun option_none_is_none() {
        let none = option::none<u64>();
        assert!(option::is_none(&none), 0);
        assert!(!option::is_some(&none), 1);
    }

}

One can reproduce the same error in any of these runs:

RUST_BACKTRACE=1 LLVM_SYS_150_PREFIX=/home/sol/move-dev PLATFORM_TOOLS_ROOT=/home/sol/work/git/platform-tools-1.38 MOVE_NATIVE=/home/sol/work/git/move/language/move-native /home/sol/work/git/move/target/debug/move-mv-llvm-compiler -p ./Move.toml --compile my_option_tests.move -S --test
thread 'main' panicked at 'internal error: entered unreachable code: struct type for 'struct.option__Option_u64_' not found', language/solana/move-to-solana/src/stackless/module_context.rs:567:25
stack backtrace:
   0: rust_begin_unwind
             at /rustc/2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74/library/core/src/panicking.rs:64:14
   2: move_to_solana::stackless::module_context::ModuleContext::to_llvm_type
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:567:25
   3: move_to_solana::stackless::module_context::ModuleContext::declare_move_function
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:390:26
   4: move_to_solana::stackless::module_context::ModuleContext::declare_functions_walk
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:347:13
   5: move_to_solana::stackless::module_context::ModuleContext::declare_functions_walk
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:373:17
   6: move_to_solana::stackless::module_context::ModuleContext::declare_functions
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:285:13
   7: move_to_solana::stackless::module_context::ModuleContext::translate
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:55:9
   8: move_mv_llvm_compiler::main
             at /home/sol/work/git/move/language/tools/move-mv-llvm-compiler/src/main.rs:237:13
   9: core::ops::function::FnOnce::call_once
             at /rustc/2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

or

LLVM_SYS_150_PREFIX=/home/sol/move-dev PLATFORM_TOOLS_ROOT=/home/sol/work/git/platform-tools-1.38 MOVE_NATIVE=/home/sol/work/git/move/language/move-native cargo run -p move-cli --features solana-backend --bin move -- test --solana -p ./Move.toml
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
warning: the following packages contain code that will be rejected by a future version of Rust: nom v5.1.2
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 194`
     Running `/home/sol/work/git/move/target/debug/move test --solana -p ./Move.toml`
INCLUDING DEPENDENCY MoveStdlib
BUILDING my_option_tests
Running Move unit tests
thread '<unnamed>' panicked at 'internal error: entered unreachable code: struct type for 'struct.bcs_tests__Box63_bcs_tests__Box63_#0__' not found', language/solana/move-to-solana/src/stackless/module_context.rs:567:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

or


sol@dev-equinix-new-york-2:~/work/git/move/language/tools/move-mv-llvm-compiler/tmp:090223-cli-corrections *$%$ RUST_BACKTRACE=1 LLVM_SYS_150_PREFIX=/home/sol/move-dev PLATFORM_TOOLS_ROOT=/home/sol/work/git/platform-tools-1.38 MOVE_NATIVE=/home/sol/work/git/move/language/move-native /home/sol/work/git/move/target/debug/move test --solana  -p ./Move.toml
INCLUDING DEPENDENCY MoveStdlib
BUILDING my_option_tests
Running Move unit tests
thread '<unnamed>' panicked at 'internal error: entered unreachable code: struct type for 'struct.bcs_tests__Box63_bcs_tests__Box63_#0__' not found', language/solana/move-to-solana/src/stackless/module_context.rs:567:25
stack backtrace:
   0: rust_begin_unwind
             at /rustc/2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74/library/core/src/panicking.rs:64:14
   2: move_to_solana::stackless::module_context::ModuleContext::to_llvm_type
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:567:25
   3: move_to_solana::stackless::module_context::ModuleContext::declare_structs
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:218:35
   4: move_to_solana::stackless::module_context::ModuleContext::translate
             at /home/sol/work/git/move/language/solana/move-to-solana/src/stackless/module_context.rs:50:9
   5: move_to_solana::compile
             at /home/sol/work/git/move/language/solana/move-to-solana/src/lib.rs:420:9
   6: move_to_solana::run_for_unit_test
             at /home/sol/work/git/move/language/solana/move-to-solana/src/lib.rs:523:11
   7: move_unit_test::test_runner::SharedTestingConfig::exec_module_tests_solana
             at /home/sol/work/git/move/language/tools/move-unit-test/src/test_runner.rs:857:40
   8: move_unit_test::test_runner::SharedTestingConfig::exec_module_tests
             at /home/sol/work/git/move/language/tools/move-unit-test/src/test_runner.rs:909:20
   9: move_unit_test::test_runner::TestRunner::run::{{closure}}::{{closure}}
             at /home/sol/work/git/move/language/tools/move-unit-test/src/test_runner.rs:217:43
  10: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &F>::call_mut
             at /rustc/2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74/library/core/src/ops/function.rs:274:13

...
  46: <rayon_core::registry::DefaultSpawn as rayon_core::registry::ThreadSpawn>::spawn::{{closure}}
             at /home/sol/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.11.0/src/registry.rs:99:20
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.```