What is the use of custom sections "motoko:stable-types" and "candid:args"?

I thought I put this in a separate thread.

While investigating the content of the custom sections that Motoko puts into the wasm (here), I found that it adds these two sections:

icp:private motoko:stable-types → ? it seems to contain the types of the stable variables
icp:public candid:args → ? it seems to contain the args of the actor

I find this very intriguing and would like to understand what is in there and what it is used for.

Is it used during deployment or during run-time, or is it really just metadata that is available for others to look at?

2 Likes

motoko:stable-types is a textual (extended) Candid representation of the types of the stable variables that the canister maintains through the upgrade process. By reading it (via dfx) and comparing with the corresponding definitions of a to-be-installed actor, the compiler is able to determine whether upgrade process is safe or there is danger of data loss. In the latter case a stark warning is presented by dfx.

2 Likes

Similarly, the “candid:args” and “candid:service” sections are used by dfx to type the canister installation argument and to check the interface of the actor has evolved to a candid subtype.

1 Like