Skip to content

Commit

Permalink
Merge branch 'master' into update/candid-87f42eefb1070381565d8de32356…
Browse files Browse the repository at this point in the history
…28a674641fbd
  • Loading branch information
mergify[bot] authored Jan 17, 2025
2 parents 010c5ad + 1312aff commit d7946de
Show file tree
Hide file tree
Showing 26 changed files with 184 additions and 94 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
14 changes: 7 additions & 7 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 Expand Up @@ -75,10 +75,10 @@
"homepage": "",
"owner": "dfinity",
"repo": "motoko-base",
"rev": "bf3b522b3e2dab992c9d2544cb438e10ef2fac1a",
"sha256": "0pyqwv7af6ccd3imwbnww64959k56vl8r9dsr2g25spmnfsnrl7a",
"rev": "010611b42d67b39aee1ec61b3c1f004771994359",
"sha256": "1gzlg84d28pnd68li735l3bk3hnc3anj985yy8fm62rf9h8p2jdx",
"type": "tarball",
"url": "https://github.com/dfinity/motoko-base/archive/bf3b522b3e2dab992c9d2544cb438e10ef2fac1a.tar.gz",
"url": "https://github.com/dfinity/motoko-base/archive/010611b42d67b39aee1ec61b3c1f004771994359.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"motoko-matchers": {
Expand Down
85 changes: 58 additions & 27 deletions rts/motoko-rts/src/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,49 +841,80 @@ pub(crate) unsafe fn memory_compatible(
}
true
}
(IDL_CON_record, IDL_CON_record) => {
(IDL_CON_record, IDL_CON_record) if !main_actor => {
// plain object/record subtyping
// symmetric to variant case
let mut n1 = leb128_decode(&mut tb1);
let n2 = leb128_decode(&mut tb2);
let mut tag1 = 0;
let mut t11 = 0;
let mut advance = true;
for _ in 0..n2 {
let tag2 = leb128_decode(&mut tb2);
let t21 = sleb128_decode(&mut tb2);
if n1 == 0 {
// Additional fields are only supported in the main actor type.
if variance == TypeVariance::Invariance || !main_actor {
return false;
}
continue;
};
if advance {
loop {
tag1 = leb128_decode(&mut tb1);
t11 = sleb128_decode(&mut tb1);
n1 -= 1;
// Do not skip fields during invariance check.
if variance == TypeVariance::Invariance || !(tag1 < tag2 && n1 > 0) {
break;
}
}
return false;
};
if tag1 > tag2 {
// Additional fields are only supported in the main actor type.
if variance == TypeVariance::Invariance || !main_actor {
return false;
let mut tag1: u32;
let mut t11: i32;
loop {
tag1 = leb128_decode(&mut tb1);
t11 = sleb128_decode(&mut tb1);
n1 -= 1;
if variance == TypeVariance::Invariance || !(tag1 < tag2 && n1 > 0) {
break;
}
advance = false; // reconsider this field in next round
continue;
}
if tag1 != tag2 {
return false;
};
if !memory_compatible(rel, variance, typtbl1, typtbl2, end1, end2, t11, t21, false)
{
return false;
}
advance = true;
}
variance != TypeVariance::Invariance || n1 == 0
}
(IDL_CON_record, IDL_CON_record) if main_actor => {
// memory compatibility
assert!(variance == TypeVariance::Covariance);
let mut n1 = leb128_decode(&mut tb1);
let mut n2 = leb128_decode(&mut tb2);
let mut tag1: u32;
let mut t11: i32;
let mut tag2: u32;
let mut t21: i32;
while n1 > 0 && n2 > 0 {
tag1 = leb128_decode(&mut tb1);
t11 = sleb128_decode(&mut tb1);
tag2 = leb128_decode(&mut tb2);
t21 = sleb128_decode(&mut tb2);
n1 -= 1;
n2 -= 1;
while tag1 != tag2 {
if tag1 < tag2 {
if n1 > 0 {
tag1 = leb128_decode(&mut tb1);
t11 = sleb128_decode(&mut tb1);
n1 -= 1;
continue;
};
return true;
};
if tag1 > tag2 {
if n2 > 0 {
tag2 = leb128_decode(&mut tb2);
t21 = sleb128_decode(&mut tb2);
n2 -= 1;
continue;
};
return true;
};
}
if !memory_compatible(rel, variance, typtbl1, typtbl2, end1, end2, t11, t21, false)
{
return false;
}
}
return true;
}
(IDL_CON_variant, IDL_CON_variant) => {
let n1 = leb128_decode(&mut tb1);
let mut n2 = leb128_decode(&mut tb2);
Expand Down
7 changes: 7 additions & 0 deletions src/ir_def/construct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ let primE prim es =
| DeserializePrim ts -> T.seq ts
| DeserializeOptPrim ts -> T.Opt (T.seq ts)
| OtherPrim "trap" -> T.Non
| OtherPrim "global_timer_set" -> T.nat64
| OtherPrim "call_perform_status" -> T.(Prim Nat32)
| OtherPrim "call_perform_message" -> T.text
| OtherPrim "array_len"
Expand Down Expand Up @@ -269,6 +270,12 @@ let nat32E n =
note = Note.{ def with typ = T.(Prim Nat32) }
}

let nat64E n =
{ it = LitE (Nat64Lit n);
at = no_region;
note = Note.{ def with typ = T.nat64 }
}

let natE n =
{ it = LitE (NatLit n);
at = no_region;
Expand Down
1 change: 1 addition & 0 deletions src/ir_def/construct.mli
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ val let_else_switch : pat -> exp -> exp -> exp
val natE : Mo_values.Numerics.Nat.t -> exp
val intE : Mo_values.Numerics.Int.t -> exp
val nat32E : Mo_values.Numerics.Nat32.t -> exp
val nat64E : Mo_values.Numerics.Nat64.t -> exp
val textE : string -> exp
val blobE : string -> exp
val letE : var -> exp -> exp -> exp
Expand Down
16 changes: 13 additions & 3 deletions src/ir_passes/await.ml
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,14 @@ and t_comp_unit context = function
preupgrade = t_exp LabelEnv.empty preupgrade;
postupgrade = t_exp LabelEnv.empty postupgrade;
heartbeat = t_ignore_throw LabelEnv.empty heartbeat;
timer = t_ignore_throw LabelEnv.empty timer;
timer = t_timer_throw LabelEnv.empty timer;
inspect = t_exp LabelEnv.empty inspect;
stable_record = t_exp LabelEnv.empty stable_record;
stable_type;
},
t)

and t_ignore_throw context exp =
and t_on_throw context exp t_exp =
match exp.it with
| Ir.PrimE (Ir.TupPrim, []) ->
exp
Expand All @@ -671,14 +671,24 @@ and t_ignore_throw context exp =
(LabelEnv.add Throw (Cont throw) context) in
let e = fresh_var "e" T.catch in
{ (blockE [
funcD throw e (tupE[]);
funcD throw e t_exp;
]
(c_exp context' exp (meta (T.unit) (fun v1 -> tupE []))))
(* timer logic requires us to preserve any source location,
or timer won't be initialized in compile.ml *)
with at = exp.at
}

and t_ignore_throw context exp = t_on_throw context exp (tupE[])

(* if self-call queue full: expire global timer soon and retry *)
and t_timer_throw context exp =
t_on_throw context exp
(blockE
[expD (primE
(OtherPrim "global_timer_set")
[Mo_values.Numerics.Nat64.of_int 1 |> nat64E])]
(tupE[]))

and t_prog (prog, flavor) =
(t_comp_unit LabelEnv.empty prog, { flavor with has_await = false })
Expand Down
8 changes: 4 additions & 4 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ and call_system_func_opt name es obj_typ =
let timer =
blockE
[ expD T.(callE (varE (var id.it note)) [Any]
(varE (var "@set_global_timer" (Func (Local, Returns, [], [Prim Nat64], []))))) ]
(unitE ()) in
(varE (var "@set_global_timer" T.global_timer_set_type))) ]
(unitE()) in
{ timer with at }
| "heartbeat" ->
blockE
Expand Down Expand Up @@ -605,8 +605,8 @@ and build_actor at ts self_id es obj_typ =
| Some call -> call
| None when !Mo_config.Flags.global_timer ->
blockE
[ expD T.(callE (varE (var "@timer_helper" Mo_frontend.Typing.heartbeat_type)) [unit] (unitE())) ]
(unitE ())
[ expD T.(callE (varE (var "@timer_helper" T.heartbeat_type)) [unit] (unitE())) ]
(unitE())
| None -> tupE []);
inspect =
(match call_system_func_opt "inspect" es obj_typ with
Expand Down
12 changes: 2 additions & 10 deletions src/mo_frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,10 @@ let infer_mut mut : T.typ -> T.typ =

(* System method types *)

let heartbeat_type =
T.(Func (Local, Returns, [scope_bind], [], [Async (Fut, Var (default_scope_var, 0), unit)]))

let timer_type =
T.(Func (Local, Returns, [scope_bind],
[Func (Local, Returns, [], [Prim Nat64], [])],
[Async (Fut, Var (default_scope_var, 0), unit)]))

let system_funcs tfs =
[
("heartbeat", heartbeat_type);
("timer", timer_type);
("heartbeat", T.heartbeat_type);
("timer", T.timer_type);
T.("preupgrade", Func (Local, Returns, [scope_bind], [], []));
T.("postupgrade", Func (Local, Returns, [scope_bind], [], []));
("inspect",
Expand Down
2 changes: 0 additions & 2 deletions src/mo_frontend/typing.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ val infer_prog : ?viper_mode:bool -> scope -> string option -> Async_cap.async_c
val check_lib : scope -> string option -> Syntax.lib -> scope Diag.result
val check_actors : ?viper_mode:bool -> ?check_actors:bool -> scope -> Syntax.prog list -> unit Diag.result
val check_stab_sig : scope -> Syntax.stab_sig -> (field list) Diag.result

val heartbeat_type : typ
20 changes: 17 additions & 3 deletions src/mo_types/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ let compare_field f1 f2 =
| {lab = l1; typ = _; _}, {lab = l2; typ = _; _} -> compare l1 l2


(* Short-hands *)
(* Shorthands *)

let unit = Tup []
let bool = Prim Bool
Expand All @@ -321,6 +321,7 @@ let char = Prim Char
let principal = Prim Principal
let region = Prim Region


let fields flds =
List.sort compare_field
(List.map (fun (lab, typ) -> {lab; typ; src = empty_src}) flds)
Expand Down Expand Up @@ -1341,6 +1342,19 @@ let default_scope_var = scope_var ""
let scope_bound = Any
let scope_bind = { var = default_scope_var; sort = Scope; bound = scope_bound }

(* Shorthands for replica callbacks *)

let heartbeat_type =
Func (Local, Returns, [scope_bind], [], [Async (Fut, Var (default_scope_var, 0), unit)])

let global_timer_set_type = Func (Local, Returns, [], [Prim Nat64], [])

let timer_type =
Func (Local, Returns, [scope_bind],
[global_timer_set_type],
[Async (Fut, Var (default_scope_var, 0), unit)])


(* Well-known fields *)

let motoko_async_helper_fld =
Expand Down Expand Up @@ -1420,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
5 changes: 4 additions & 1 deletion src/mo_types/type.mli
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ end
val is_shared_sort : 'a shared -> bool


(* Short-hands *)
(* Shorthands *)

val unit : typ
val bool : typ
Expand All @@ -97,6 +97,9 @@ val error : typ
val char : typ
val principal : typ
val region : typ
val heartbeat_type : typ
val timer_type : typ
val global_timer_set_type : typ

val sum : (lab * typ) list -> typ
val obj : obj_sort -> (lab * typ) list -> typ
Expand Down
Loading

0 comments on commit d7946de

Please sign in to comment.