Skip to content

Commit

Permalink
fix: Use lower case for Wasm persistence modes (#4854)
Browse files Browse the repository at this point in the history
Related to dfinity/ic#3479.

This changes the variant names for the Wasm memory persistence modes used for enhanced orthogonal persistence to lower case to align it with the IC specification, i.e. using `keep` and `replace` instead of `Keep` and `Replace`.

For installed Motoko programs using enhanced orthogonal persistence, the change only affects the programmatic upgrades of Motoko actor class instances. Existing such programs would need to be recompiled with a new Motoko compiler and upgraded. The IC detects mismatching variant names of Wasm memory persistence by raising an error while still preserving persistent memory.
  • Loading branch information
luc-blaeser authored Jan 17, 2025
1 parent a9bc214 commit 6dcbc9b
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 35 deletions.
12 changes: 12 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Motoko compiler changelog

## 0.13.6 (tbd)

* motoko (`moc`)

* Breaking change (minor):

* For enhanced orthogonal persistence: The Wasm persistence modes used internally for canister upgrades have been changed to lower case names,
`keep` and `replace` and instead of `Keep` and `Replace`:

If using actor class instances with enhanced orthogonal persistence, you would need to recompile the program and upgrade with latest `moc` and `dfx`.
Otherwise, no action is needed.

## 0.13.5 (2024-12-06)

* motoko (`moc`)
Expand Down
15 changes: 2 additions & 13 deletions nix/drun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pkgs:
outputHashes = {
"build-info-0.0.27" = "sha256-SkwWwDNrTsntkNiCv6rsyTFGazhpRDnKtVzPpYLKF9U=";
"cloudflare-0.12.0" = "sha256-FxCAK7gUKp/63fdvzI5Ufsy4aur74fO4R/K3YFiUw0Y=";
"ic-bn-lib-0.1.0" = "sha256-wqWfF70B+YQWg63yiEvIxOq+LN1AasrNXcyPkDM4/jw=";
"ic-canister-sig-creation-1.1.0" = "sha256-c47Fh4kZbmezWCYVHMci2BMXJfESaOGsyNlWh8YR6oU=";
"icrc1-test-env-0.1.1" = "sha256-2PB7e64Owin/Eji3k8UoeWs+pfDfOOTaAyXjvjOZ/4g=";
"jsonrpc-0.12.1" = "sha256-3FtdZlt2PqVDkE5iKWYIp1eiIELsaYlUPRSP2Xp8ejM=";
"lmdb-rkv-0.14.99" = "sha256-5WcUzapkrc/s3wCBNCuUDhtbp17n67rTbm2rx0qtITg=";
Expand All @@ -42,19 +44,6 @@ pkgs:
EOF
cd -
# static linking of libunwind fails under nix Linux
patch rs/monitoring/backtrace/build.rs << EOF
@@ -1,8 +1,2 @@
fn main() {
- if std::env::var("TARGET").unwrap() == "x86_64-unknown-linux-gnu" {
- println!("cargo:rustc-link-lib=static=unwind");
- println!("cargo:rustc-link-lib=static=unwind-ptrace");
- println!("cargo:rustc-link-lib=static=unwind-x86_64");
- println!("cargo:rustc-link-lib=dylib=lzma");
- }
}
EOF
mkdir -p .cargo
cat > .cargo/config.toml << EOF
[target.x86_64-apple-darwin]
Expand Down
8 changes: 4 additions & 4 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"version": "3.2.25"
},
"ic": {
"branch": "luc/adjust-drun",
"branch": "luc/lower-case-persistence-modes",
"description": "Internet Computer blockchain source: the client/replica software run by nodes",
"homepage": "",
"owner": "luc-blaeser",
"repo": "ic",
"rev": "bebe89514a6abd26e940b295323823169911a965",
"sha256": "1g68fyi5acbcgs2kjribk97fj8ki5g6pd99nwl5azz1rw1b0xycx",
"rev": "48ba595fb1a6bc828e7e9dae976db42b5526a5b6",
"sha256": "0136hxidak4qsk0nhjdy2nmciwb0lprm07vs117xdw3cp4m6py2z",
"type": "tarball",
"url": "https://github.com/luc-blaeser/ic/archive/bebe89514a6abd26e940b295323823169911a965.tar.gz",
"url": "https://github.com/luc-blaeser/ic/archive/48ba595fb1a6bc828e7e9dae976db42b5526a5b6.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ic-hs": {
Expand Down
4 changes: 2 additions & 2 deletions src/mo_types/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1434,8 +1434,8 @@ let canister_settings_typ =

let wasm_memory_persistence_typ =
sum [
("Keep", unit);
("Replace", unit);
("keep", unit);
("replace", unit);
]

let upgrade_with_persistence_option_typ =
Expand Down
6 changes: 3 additions & 3 deletions src/prelude/internals.mo
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ module @ManagementCanister = {
};
type @WasmMemoryPersistence = {
#Keep;
#Replace;
#keep;
#replace;
};
type @UpgradeOptions = {
Expand Down Expand Up @@ -460,7 +460,7 @@ func @install_actor_helper(
};
case (#upgrade actor2) {
let wasm_memory_persistence = if enhanced_orthogonal_persistence {
?(#Keep)
?(#keep)
} else {
null
};
Expand Down
2 changes: 1 addition & 1 deletion test/bench/ok/region-mem.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 5_234_491_753}
debug.print: {heap_diff = 0; instr_diff = 5_240_635_753}
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/region0-mem.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 5_662_310_761}
debug.print: {heap_diff = 0; instr_diff = 5_668_454_761}
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/stable-mem.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 3_875_537_257}
debug.print: {heap_diff = 0; instr_diff = 3_881_681_257}
ingress Completed: Reply: 0x4449444c0000
4 changes: 2 additions & 2 deletions test/run-drun/actor-class-mgmt-enhanced.mo
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ actor a {
assert (c5 == c4);

let c6 = await
(system Cs.C)(#upgrade_with_persistence { wasm_memory_persistence = #Keep ; canister = c5 })(6, null);
(system Cs.C)(#upgrade_with_persistence { wasm_memory_persistence = #keep ; canister = c5 })(6, null);
assert ({args = 6; upgrades = 3} == (await c6.observe()));
assert (c6 == c5);

Expand All @@ -135,7 +135,7 @@ actor a {

// no need to add cycles
let c8 = await
(system Cs.C)(#upgrade_with_persistence { wasm_memory_persistence = #Replace ; canister = c7 })(8, null);
(system Cs.C)(#upgrade_with_persistence { wasm_memory_persistence = #replace ; canister = c7 })(8, null);
assert ({args = 8; upgrades = 0} == (await c8.observe()));
assert (c8 == c7);

Expand Down
4 changes: 2 additions & 2 deletions test/run-drun/map-mixed-upgrades/map0.mo
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ actor a {
case null {};
case (?n) {
nodes[i] :=
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #Keep; canister = n })(i)); // upgrade!
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #keep; canister = n })(i)); // upgrade!
}
}
}
Expand All @@ -80,7 +80,7 @@ actor a {
case null {};
case (?n) {
nodes[i] :=
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #Replace; canister = n })(i)); // upgrade!
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #replace; canister = n })(i)); // upgrade!
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/run-drun/map-mixed-upgrades/map1.mo
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ actor a {
case null {};
case (?n) {
nodes[i] :=
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #Keep; canister = n })(i)); // upgrade!
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #keep; canister = n })(i)); // upgrade!
}
}
}
Expand All @@ -91,7 +91,7 @@ actor a {
case null {};
case (?n) {
nodes[i] :=
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #Replace; canister = n })(i)); // upgrade!
? (await (system Lib.Node)(#upgrade_with_persistence { wasm_memory_persistence = #replace; canister = n })(i)); // upgrade!
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/run-drun/migration-paths/new-installer.mo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ actor {
switch testCanister {
case null Prim.trap("null canister");
case (?canister) {
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #Keep; canister })();
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #keep; canister })();
Prim.debugPrint("Upgraded (keep main memory)");
};
};
Expand All @@ -29,7 +29,7 @@ actor {
switch testCanister {
case null Prim.trap("null canister");
case (?canister) {
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #Replace; canister })();
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #replace; canister })();
Prim.debugPrint("Upgraded (replace main memory)");
};
};
Expand Down
4 changes: 2 additions & 2 deletions test/run-drun/migration-paths/old-installer.mo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ actor installer {
switch testCanister {
case null Prim.trap("null canister");
case (?canister) {
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #Keep; canister })();
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #keep; canister })();
Prim.debugPrint("Upgraded (keep main memory)");
}
}
Expand All @@ -41,7 +41,7 @@ actor installer {
switch testCanister {
case null Prim.trap("null canister");
case (?canister) {
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #Replace; canister })();
ignore await (system TestCanister.TestCanister)(#upgrade_with_persistence { wasm_memory_persistence = #replace; canister })();
Prim.debugPrint("Upgraded (replace main memory)");
}
}
Expand Down

0 comments on commit 6dcbc9b

Please sign in to comment.