From 17863873553fe334dfd4baee817c80f30b259af0 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Thu, 30 Oct 2025 00:01:56 +0000 Subject: [PATCH 1/4] repro for crash --- test/run-drun/await-dot.mo | 11 +++++++++++ test/run-drun/ok/await-dot.comp.ok | 2 ++ test/run-drun/ok/await-dot.comp.ret.ok | 1 + test/run-drun/ok/await-dot.diff-ir.ok | 5 +++++ test/run-drun/ok/await-dot.diff-low.ok | 5 +++++ test/run-drun/ok/await-dot.run-ir.ok | 2 ++ test/run-drun/ok/await-dot.run-ir.ret.ok | 1 + test/run-drun/ok/await-dot.run-low.ok | 2 ++ test/run-drun/ok/await-dot.run-low.ret.ok | 1 + 9 files changed, 30 insertions(+) create mode 100644 test/run-drun/await-dot.mo create mode 100644 test/run-drun/ok/await-dot.comp.ok create mode 100644 test/run-drun/ok/await-dot.comp.ret.ok create mode 100644 test/run-drun/ok/await-dot.diff-ir.ok create mode 100644 test/run-drun/ok/await-dot.diff-low.ok create mode 100644 test/run-drun/ok/await-dot.run-ir.ok create mode 100644 test/run-drun/ok/await-dot.run-ir.ret.ok create mode 100644 test/run-drun/ok/await-dot.run-low.ok create mode 100644 test/run-drun/ok/await-dot.run-low.ret.ok diff --git a/test/run-drun/await-dot.mo b/test/run-drun/await-dot.mo new file mode 100644 index 00000000000..ad0a1f6a870 --- /dev/null +++ b/test/run-drun/await-dot.mo @@ -0,0 +1,11 @@ +persistent actor { + + module Nat { + public func id(self : Nat) : Nat { self }; + }; + + public func go () { + ignore (await (async 1)).id() == 1; + } + +} diff --git a/test/run-drun/ok/await-dot.comp.ok b/test/run-drun/ok/await-dot.comp.ok new file mode 100644 index 00000000000..45f6f78b481 --- /dev/null +++ b/test/run-drun/ok/await-dot.comp.ok @@ -0,0 +1,2 @@ +Ill-typed intermediate code after Desugaring (use -v to see dumped IR): +await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.comp.ret.ok b/test/run-drun/ok/await-dot.comp.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/run-drun/ok/await-dot.comp.ret.ok @@ -0,0 +1 @@ +Return code 1 diff --git a/test/run-drun/ok/await-dot.diff-ir.ok b/test/run-drun/ok/await-dot.diff-ir.ok new file mode 100644 index 00000000000..bd6b178a094 --- /dev/null +++ b/test/run-drun/ok/await-dot.diff-ir.ok @@ -0,0 +1,5 @@ +--- await-dot.run ++++ await-dot.run-ir +@@ -0,0 +1,2 @@ ++Ill-typed intermediate code after Desugaring (use -v to see dumped IR): ++await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.diff-low.ok b/test/run-drun/ok/await-dot.diff-low.ok new file mode 100644 index 00000000000..9cd17abb8d8 --- /dev/null +++ b/test/run-drun/ok/await-dot.diff-low.ok @@ -0,0 +1,5 @@ +--- await-dot.run ++++ await-dot.run-low +@@ -0,0 +1,2 @@ ++Ill-typed intermediate code after Desugaring (use -v to see dumped IR): ++await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.run-ir.ok b/test/run-drun/ok/await-dot.run-ir.ok new file mode 100644 index 00000000000..45f6f78b481 --- /dev/null +++ b/test/run-drun/ok/await-dot.run-ir.ok @@ -0,0 +1,2 @@ +Ill-typed intermediate code after Desugaring (use -v to see dumped IR): +await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.run-ir.ret.ok b/test/run-drun/ok/await-dot.run-ir.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/run-drun/ok/await-dot.run-ir.ret.ok @@ -0,0 +1 @@ +Return code 1 diff --git a/test/run-drun/ok/await-dot.run-low.ok b/test/run-drun/ok/await-dot.run-low.ok new file mode 100644 index 00000000000..45f6f78b481 --- /dev/null +++ b/test/run-drun/ok/await-dot.run-low.ok @@ -0,0 +1,2 @@ +Ill-typed intermediate code after Desugaring (use -v to see dumped IR): +await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.run-low.ret.ok b/test/run-drun/ok/await-dot.run-low.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/run-drun/ok/await-dot.run-low.ret.ok @@ -0,0 +1 @@ +Return code 1 From f2759bbd54a6f9a5ec72630fed9b336115191ce6 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Thu, 6 Nov 2025 17:33:39 +0000 Subject: [PATCH 2/4] compute and maintain effects --- src/mo_def/syntax.ml | 11 ++++++++--- src/mo_frontend/typing.ml | 5 ++++- test/run-drun/ok/await-dot.comp.ok | 2 -- test/run-drun/ok/await-dot.comp.ret.ok | 1 - test/run-drun/ok/await-dot.diff-ir.ok | 5 ----- test/run-drun/ok/await-dot.diff-low.ok | 5 ----- test/run-drun/ok/await-dot.run-ir.ok | 2 -- test/run-drun/ok/await-dot.run-ir.ret.ok | 1 - test/run-drun/ok/await-dot.run-low.ok | 2 -- test/run-drun/ok/await-dot.run-low.ret.ok | 1 - 10 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 test/run-drun/ok/await-dot.comp.ok delete mode 100644 test/run-drun/ok/await-dot.comp.ret.ok delete mode 100644 test/run-drun/ok/await-dot.diff-ir.ok delete mode 100644 test/run-drun/ok/await-dot.diff-low.ok delete mode 100644 test/run-drun/ok/await-dot.run-ir.ok delete mode 100644 test/run-drun/ok/await-dot.run-ir.ret.ok delete mode 100644 test/run-drun/ok/await-dot.run-low.ok delete mode 100644 test/run-drun/ok/await-dot.run-low.ret.ok diff --git a/src/mo_def/syntax.ml b/src/mo_def/syntax.ml index 2b4b49cc879..c3fb4cc1cc3 100644 --- a/src/mo_def/syntax.ml +++ b/src/mo_def/syntax.ml @@ -391,11 +391,16 @@ let contextual_dot_args e1 e2 dot_note = let arity = match dot_note.note.note_typ with | T.Func(_, _, _, args, _) -> List.length args | _ -> raise (Invalid_argument "non-function type in contextual dot note") in + let effect eff = + match (e1.note.note_eff, eff) with + | T.Triv, T.Triv -> T.Triv + | _, _ -> T.Await + in let args = match e2 with | { it = TupE []; at; note = { note_eff;_ } } -> - { it = e1.it; at; note = { note_eff; note_typ = e1.note.note_typ } } + { it = e1.it; at; note = { note_eff = effect note_eff; note_typ = e1.note.note_typ } } | { it = TupE exps; at; note = { note_eff; note_typ = T.Tup ts } } when arity <> 2 -> - { it = TupE (e1::exps); at; note = { note_eff; note_typ = T.Tup (e1.note.note_typ::ts) } } + { it = TupE (e1::exps); at; note = { note_eff = effect note_eff; note_typ = T.Tup (e1.note.note_typ::ts) } } | { at; note = { note_eff; _ }; _ } -> - { it = TupE ([e1; e2]); at; note = { note_eff; note_typ = T.Tup ([e1.note.note_typ; e2.note.note_typ]) } } + { it = TupE ([e1; e2]); at; note = { note_eff = effect note_eff; note_typ = T.Tup ([e1.note.note_typ; e2.note.note_typ]) } } in args diff --git a/src/mo_frontend/typing.ml b/src/mo_frontend/typing.ml index a5533ba2f8a..9ade99e13af 100644 --- a/src/mo_frontend/typing.ml +++ b/src/mo_frontend/typing.ml @@ -2667,8 +2667,11 @@ and infer_callee env exp = mk_error env | Ok { module_name; path; func_ty; inst; _ } -> note := Some path; - if not env.pre then + if not env.pre then begin check_exp env func_ty path; + let note_eff = A.infer_effect_exp exp in + exp.note <- {note_typ = exp.note.note_typ; note_eff} + end; func_ty, Some (exp1, t1, id.it, inst) end | _ -> diff --git a/test/run-drun/ok/await-dot.comp.ok b/test/run-drun/ok/await-dot.comp.ok deleted file mode 100644 index 45f6f78b481..00000000000 --- a/test/run-drun/ok/await-dot.comp.ok +++ /dev/null @@ -1,2 +0,0 @@ -Ill-typed intermediate code after Desugaring (use -v to see dumped IR): -await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.comp.ret.ok b/test/run-drun/ok/await-dot.comp.ret.ok deleted file mode 100644 index 69becfa16f9..00000000000 --- a/test/run-drun/ok/await-dot.comp.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 1 diff --git a/test/run-drun/ok/await-dot.diff-ir.ok b/test/run-drun/ok/await-dot.diff-ir.ok deleted file mode 100644 index bd6b178a094..00000000000 --- a/test/run-drun/ok/await-dot.diff-ir.ok +++ /dev/null @@ -1,5 +0,0 @@ ---- await-dot.run -+++ await-dot.run-ir -@@ -0,0 +1,2 @@ -+Ill-typed intermediate code after Desugaring (use -v to see dumped IR): -+await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.diff-low.ok b/test/run-drun/ok/await-dot.diff-low.ok deleted file mode 100644 index 9cd17abb8d8..00000000000 --- a/test/run-drun/ok/await-dot.diff-low.ok +++ /dev/null @@ -1,5 +0,0 @@ ---- await-dot.run -+++ await-dot.run-low -@@ -0,0 +1,2 @@ -+Ill-typed intermediate code after Desugaring (use -v to see dumped IR): -+await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.run-ir.ok b/test/run-drun/ok/await-dot.run-ir.ok deleted file mode 100644 index 45f6f78b481..00000000000 --- a/test/run-drun/ok/await-dot.run-ir.ok +++ /dev/null @@ -1,2 +0,0 @@ -Ill-typed intermediate code after Desugaring (use -v to see dumped IR): -await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.run-ir.ret.ok b/test/run-drun/ok/await-dot.run-ir.ret.ok deleted file mode 100644 index 69becfa16f9..00000000000 --- a/test/run-drun/ok/await-dot.run-ir.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 1 diff --git a/test/run-drun/ok/await-dot.run-low.ok b/test/run-drun/ok/await-dot.run-low.ok deleted file mode 100644 index 45f6f78b481..00000000000 --- a/test/run-drun/ok/await-dot.run-low.ok +++ /dev/null @@ -1,2 +0,0 @@ -Ill-typed intermediate code after Desugaring (use -v to see dumped IR): -await-dot.mo:8.33-8.35: IR type error [M0000], inferred effect not a subtype of expected effect diff --git a/test/run-drun/ok/await-dot.run-low.ret.ok b/test/run-drun/ok/await-dot.run-low.ret.ok deleted file mode 100644 index 69becfa16f9..00000000000 --- a/test/run-drun/ok/await-dot.run-low.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 1 From 518018a5d602d91614fd281ffcae984ffe73c59d Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Thu, 6 Nov 2025 17:38:03 +0000 Subject: [PATCH 3/4] update test --- test/run-drun/ok/await-dot.drun-run.ok | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/run-drun/ok/await-dot.drun-run.ok diff --git a/test/run-drun/ok/await-dot.drun-run.ok b/test/run-drun/ok/await-dot.drun-run.ok new file mode 100644 index 00000000000..a6f776f43c6 --- /dev/null +++ b/test/run-drun/ok/await-dot.drun-run.ok @@ -0,0 +1,2 @@ +ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 +ingress Completed: Reply: 0x4449444c0000 From 1df32051832b5610ff0e9f52e9ad453fda5b571f Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Thu, 6 Nov 2025 17:40:28 +0000 Subject: [PATCH 4/4] Changelog++ --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 238000a1371..f7e0b929723 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,8 @@ * motoko (`moc`) + * Fix for #5618 (compiling dotted `await`s) (#5622). + * Improved type inference of the record update syntax (#5625). * New flag `--error-recovery` to enable reporting of multiple syntax errors (#5632).