move-language / move

Apache License 2.0
2.26k stars 689 forks source link

[Bug] inline function crash case A #870

Open ghost opened 1 year ago

ghost commented 1 year ago

🐛 Bug

It crashed.

To reproduce

Code snippet to reproduce

module me::test3 {
    use liquidswap::liquidity_pool::{get_reserves_size};

    public inline fun reserves_liquidswap<A, B, Curve>(order: bool, a1: u128, a2: u128) {
        if (order) {
            let (xx, yy) = get_reserves_size<A, B, Curve>();
            a1 = (xx as u128);
            a2 = (yy as u128);
        } else {
            let (yy, xx) = get_reserves_size<B, A, Curve>();
            a2 = (yy as u128);
            a1 = (xx as u128);
        };
    }

    public fun a<X, Y, Curve>(order: bool) {
        let (x, y);
        reserves_liquidswap<X, Y, Curve>(order, x, y);
    }
}
[package]
name = 'ass'
version = '1.0.0'
[dependencies]
AptosFramework={local="../af"}
Liquidswap={local="../iface/liquidswap"}
[addresses]
me = "0xd1b58e44ea11ffd326a280c453b080fd8af294298815a00e65b6e2bffc48d6ac"

Stack trace/error message

// Paste the output here
$ ./aptos move publish --bytecode-version 6 --skip-fetch-latest-git-deps --profile dev --included-artifacts none --package-dir ./assembly
Compiling, may take a little while to download git dependencies...
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY Liquidswap
INCLUDING DEPENDENCY MoveStdlib
BUILDING ass
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/runner/.cargo/git/checkouts/move-0639dd674f581c30/2336fe2/language/move-compiler/src/hlir/translate.rs:153:50
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Behavior

I don't know, you define it what should be.

System information

Please complete the following information:

Additional context

Add any other context about the problem here.

0xrelapse commented 1 year ago

I think the problem here is that you're reassigning the arguments.

So far, I've noticed you can't use inline if:

Besides those cases, the compiler crashes randomly sometimes due to some internal limit being exceeded

ghost commented 1 year ago

I think the problem here is that you're reassigning the arguments.

So far, I've noticed you can't use inline if:

* You reassign an argument

* You return from the function (the compiler has a proper error message for this now)

* You use the function argument directly like `fp_round(fp_mul(...))`

Besides those cases, the compiler crashes randomly sometimes due to some internal limit being exceeded

I am not going to use inline function at foreseen future, instead, https://github.com/mitsuhiko/minijinja