Skip to content

Conversation

@crusso
Copy link
Contributor

@crusso crusso commented Sep 15, 2025

I don't understand why upgrading from version0 to version1 fails, while version2 is ok. I'd expect the upgrade to version1 to be ok too:

(The only difference is that verson2 retains a use to persistent function f, but both define f.

version0.mo

import Prim "mo:prim";

persistent actor {
    persistent func f() : {a : Int; b : Int} {
        {a=0; b=0};
    };

    stable let g = f;
    assert g().a == 0;

    Prim.debugPrint "version0";
}

version1.mo

import Prim "mo:prim";

// why does upgrading tois fail? Both f and g are declared with the same type (but th
ere is no-reference to f)

persistent actor {
    persistent func f() : {a: Int; b: Int} {
        {a = 1; b = 1};
    };


    stable let g : persistent () -> {a:Int; b: Int} = Prim.trap "unreachable";
    assert g().a == 1;
    // stable let h : Any = f; // why does upgrade fail without this reference to f?
    Prim.debugPrint "version1";

}

version2.mo

import Prim "mo:prim";

persistent actor {
    persistent func f() : {a: Int; b: Int} {
        {a = 1; b = 1};
    };


    stable let g : persistent () -> {a:Int; b: Int} = Prim.trap "unreachable";
    assert g().a == 1;
    stable let h : Any = f; // why does upgrade fail without this reference to f?
    Prim.debugPrint "version2";

}

Output:

crusso@crusso-Virtual-Machine:~/motoko/test/run-drun$ more ok/stable-weirdness.drun.ok 
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
debug.print: version0
ingress Completed: Reply: 0x4449444c0000
ingress Err: IC0503: Error from Canister rwlgt-iiaaa-aaaaa-aaaaa-cai: Canister called
 `ic0.trap` with message: 'RTS error: Incompatible upgrade: Stable function f is miss
ing in the new program version'.
Consider gracefully handling failures from this canister or altering the canister to 
handle exceptions. See documentation: https://internetcomputer.org/docs/current/refer
ences/execution-errors#trapped-explicitly
debug.print: version2
ingress Completed: Reply: 0x4449444c0000

@crusso crusso changed the base branch from master to luc/stable-functions September 15, 2025 12:41
@crusso crusso requested a review from luc-blaeser September 15, 2025 12:45
@github-actions
Copy link
Contributor

github-actions bot commented Sep 15, 2025

Comparing from c88e5ef to da5e151:
The produced WebAssembly code seems to be completely unchanged.
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant