From 66fae26f51fdec93aac59224e88390a8bdfb5e5f Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sun, 29 Sep 2024 17:26:57 +0200 Subject: [PATCH 01/67] initial testcase --- test/run-drun/ok/pass-self.diff-ir.ok | 5 +++++ test/run-drun/ok/pass-self.diff-low.ok | 5 +++++ test/run-drun/ok/pass-self.drun-run.ok | 2 ++ test/run-drun/ok/pass-self.run-ir.ok | 1 + test/run-drun/ok/pass-self.run-low.ok | 1 + test/run-drun/ok/pass-self.run.ok | 1 + test/run-drun/ok/pass-self.run.ret.ok | 1 + test/run-drun/ok/pass-self.tc.ok | 1 + test/run-drun/pass-self.mo | 10 ++++++++++ 9 files changed, 27 insertions(+) create mode 100644 test/run-drun/ok/pass-self.diff-ir.ok create mode 100644 test/run-drun/ok/pass-self.diff-low.ok create mode 100644 test/run-drun/ok/pass-self.drun-run.ok create mode 100644 test/run-drun/ok/pass-self.run-ir.ok create mode 100644 test/run-drun/ok/pass-self.run-low.ok create mode 100644 test/run-drun/ok/pass-self.run.ok create mode 100644 test/run-drun/ok/pass-self.run.ret.ok create mode 100644 test/run-drun/ok/pass-self.tc.ok create mode 100644 test/run-drun/pass-self.mo diff --git a/test/run-drun/ok/pass-self.diff-ir.ok b/test/run-drun/ok/pass-self.diff-ir.ok new file mode 100644 index 00000000000..57639da4939 --- /dev/null +++ b/test/run-drun/ok/pass-self.diff-ir.ok @@ -0,0 +1,5 @@ +--- pass-self.run ++++ pass-self.run-ir +@@ -1 +1 @@ +-pass-self.mo:9.12-9.16: execution error, accessing identifier before its definition ++pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.diff-low.ok b/test/run-drun/ok/pass-self.diff-low.ok new file mode 100644 index 00000000000..2a223f814ca --- /dev/null +++ b/test/run-drun/ok/pass-self.diff-low.ok @@ -0,0 +1,5 @@ +--- pass-self.run ++++ pass-self.run-low +@@ -1 +1 @@ +-pass-self.mo:9.12-9.16: execution error, accessing identifier before its definition ++pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.drun-run.ok b/test/run-drun/ok/pass-self.drun-run.ok new file mode 100644 index 00000000000..a6f776f43c6 --- /dev/null +++ b/test/run-drun/ok/pass-self.drun-run.ok @@ -0,0 +1,2 @@ +ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 +ingress Completed: Reply: 0x4449444c0000 diff --git a/test/run-drun/ok/pass-self.run-ir.ok b/test/run-drun/ok/pass-self.run-ir.ok new file mode 100644 index 00000000000..40dd69d3163 --- /dev/null +++ b/test/run-drun/ok/pass-self.run-ir.ok @@ -0,0 +1 @@ +pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.run-low.ok b/test/run-drun/ok/pass-self.run-low.ok new file mode 100644 index 00000000000..40dd69d3163 --- /dev/null +++ b/test/run-drun/ok/pass-self.run-low.ok @@ -0,0 +1 @@ +pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.run.ok b/test/run-drun/ok/pass-self.run.ok new file mode 100644 index 00000000000..b80143c1f51 --- /dev/null +++ b/test/run-drun/ok/pass-self.run.ok @@ -0,0 +1 @@ +pass-self.mo:9.12-9.16: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/pass-self.run.ret.ok b/test/run-drun/ok/pass-self.run.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/run-drun/ok/pass-self.run.ret.ok @@ -0,0 +1 @@ +Return code 1 diff --git a/test/run-drun/ok/pass-self.tc.ok b/test/run-drun/ok/pass-self.tc.ok new file mode 100644 index 00000000000..8c1914c63ae --- /dev/null +++ b/test/run-drun/ok/pass-self.tc.ok @@ -0,0 +1 @@ +pass-self.mo:3.1-10.2: warning [M0016], cannot use Self before Self has been defined diff --git a/test/run-drun/pass-self.mo b/test/run-drun/pass-self.mo new file mode 100644 index 00000000000..992bc34803a --- /dev/null +++ b/test/run-drun/pass-self.mo @@ -0,0 +1,10 @@ +import { debugPrint } = "mo:⛔"; + +actor Self { + public func method() : async () { debugPrint "YESS!" }; + + var c : ?(shared () -> async ()) = null; + func caller(callee : shared () -> async ()) { c := ?callee }; + + caller(Self.method) +} From e5e84eeb59f1fa88dddba7ca4cdc2e09abe0f62a Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 13:50:22 +0200 Subject: [PATCH 02/67] simplify --- src/mo_values/prim.ml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mo_values/prim.ml b/src/mo_values/prim.ml index 28a21b2f7a6..0248598a95a 100644 --- a/src/mo_values/prim.ml +++ b/src/mo_values/prim.ml @@ -295,8 +295,9 @@ let prim trap = ) - | "blobOfPrincipal" -> fun _ v k -> k v - | "principalOfBlob" -> fun _ v k -> k v + | "cast" + | "blobOfPrincipal" + | "principalOfBlob" | "principalOfActor" -> fun _ v k -> k v | "blobToArray" -> fun _ v k -> @@ -316,8 +317,6 @@ let prim trap = Char.chr (Nat8.to_int (Value.as_nat8 !(Value.as_mut v))) ) (Array.to_seq (Value.as_array v))))) - | "cast" -> fun _ v k -> k v - (* calls never fail in the interpreter *) | "call_perform_status" -> fun _ v k -> k (Nat32 Nat32.zero) | "call_perform_message" -> fun _ v k -> k (Value.Text "") From 84de9b2e9714b79fd334e3a04a590be8e77901a9 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 14:34:10 +0200 Subject: [PATCH 03/67] simplify more --- src/mo_interpreter/interpret.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 91afb0740a0..a41709846ba 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -890,7 +890,7 @@ and interpret_obj env obj_sort dec_fields (k : V.value V.cont) = | T.Actor -> let self = V.fresh_id() in let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in - let env' = adjoin_vals { env with self = self } ve_in in + let env' = adjoin_vals { env with self } ve_in in interpret_dec_fields env' dec_fields ve_ex (fun obj -> (env.actor_env := V.Env.add self obj !(env.actor_env); From 49d7f1eaa4d45c453248426b9ecc41c783e64a96 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 15:22:10 +0200 Subject: [PATCH 04/67] note when it comes officially --- src/lib/lib.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/lib.mli b/src/lib/lib.mli index 795e35f1054..8165ca54bad 100644 --- a/src/lib/lib.mli +++ b/src/lib/lib.mli @@ -84,7 +84,7 @@ end module Seq : sig - val for_all : ('a -> bool) -> 'a Seq.t -> bool + val for_all : ('a -> bool) -> 'a Seq.t -> bool (* 4.14 *) end module Option : From b5ae4a80d5d73247ef00e2e35e3a21ea3f443544 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 18:30:17 +0200 Subject: [PATCH 05/67] WIP: hacky way to make some progress --- src/mo_frontend/definedness.ml | 4 ++-- src/mo_interpreter/interpret.ml | 24 ++++++++++++++++++------ test/run-drun/ok/pass-self.diff-ir.ok | 6 ++++-- test/run-drun/ok/pass-self.diff-low.ok | 6 ++++-- test/run-drun/ok/pass-self.drun-run.ok | 3 +++ test/run-drun/ok/pass-self.run-ir.ok | 1 + test/run-drun/ok/pass-self.run-low.ok | 1 + test/run-drun/ok/pass-self.run.ok | 1 - test/run-drun/ok/pass-self.run.ret.ok | 1 - test/run-drun/ok/pass-self.tc.ok | 2 +- test/run-drun/pass-self.mo | 19 +++++++++++++------ 11 files changed, 47 insertions(+), 21 deletions(-) delete mode 100644 test/run-drun/ok/pass-self.run.ok delete mode 100644 test/run-drun/ok/pass-self.run.ret.ok diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index 9255bff48c3..a0da6b1e43f 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -206,10 +206,10 @@ and group msgs (grp : group) : f = defined after j *) if j < i then () (* all izz well *) - else + else (*assert eager;*) Diag.add_msg msgs - (Diag.error_message + (Diag.warning_message at "M0016" "definedness" diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index a41709846ba..19b72723395 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -785,7 +785,7 @@ and declare_pat_fields pfs ve : val_env = and define_id env id v = define_id' env id.it v -and define_id' env id v = +and define_id' env id v = if not(Lib.Promise.is_fulfilled (find id env.vals)) then Lib.Promise.fulfill (find id env.vals) v and define_pat env pat v = @@ -889,12 +889,18 @@ and interpret_obj env obj_sort dec_fields (k : V.value V.cont) = match obj_sort with | T.Actor -> let self = V.fresh_id() in - let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in + let self' = V.Blob self in + let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty (*Lib.Promise.make_fulfilled self' |> V.Env.singleton "SelfX"*) V.Env.empty in let env' = adjoin_vals { env with self } ve_in in - interpret_dec_fields env' dec_fields ve_ex + define_id' env' "Self" self'; + let partial () = + let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_in in + env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) + in + interpret_dec_fields' env' (Some partial) dec_fields ve_ex (fun obj -> (env.actor_env := V.Env.add self obj !(env.actor_env); - k (V.Blob self))) + k self')) | _ -> let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals env ve_in in @@ -909,15 +915,21 @@ and declare_dec_fields dec_fields ve_ex ve_in : val_env * val_env = let ve_in' = V.Env.adjoin ve_in ve' in declare_dec_fields dec_fields' ve_ex' ve_in' -and interpret_dec_fields env dec_fields ve (k : V.value V.cont) = +and interpret_dec_fields' env upd dec_fields ve (k : V.value V.cont) = + let commit = function + | None -> () + | Some f -> f () in match dec_fields with | [] -> let obj = V.Obj (V.Env.map Lib.Promise.value ve) in k obj | {it = {dec; _}; _}::dec_fields' -> - interpret_dec env dec (fun _v -> interpret_dec_fields env dec_fields' ve k) + interpret_dec env dec (fun _v -> commit upd; interpret_dec_fields' env upd dec_fields' ve k) +and interpret_dec_fields env dec_fields ve (k : V.value V.cont) = + interpret_dec_fields' env None dec_fields ve k + (* Blocks and Declarations *) and interpret_block env decs ro (k : V.value V.cont) = diff --git a/test/run-drun/ok/pass-self.diff-ir.ok b/test/run-drun/ok/pass-self.diff-ir.ok index 57639da4939..f8b80d95909 100644 --- a/test/run-drun/ok/pass-self.diff-ir.ok +++ b/test/run-drun/ok/pass-self.diff-ir.ok @@ -1,5 +1,7 @@ --- pass-self.run +++ pass-self.run-ir -@@ -1 +1 @@ --pass-self.mo:9.12-9.16: execution error, accessing identifier before its definition +@@ -1,3 +1,2 @@ + BEFORE! +-ys6dh-5cjiq-5dc +-So far so good! +pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.diff-low.ok b/test/run-drun/ok/pass-self.diff-low.ok index 2a223f814ca..ca24b7fcd7d 100644 --- a/test/run-drun/ok/pass-self.diff-low.ok +++ b/test/run-drun/ok/pass-self.diff-low.ok @@ -1,5 +1,7 @@ --- pass-self.run +++ pass-self.run-low -@@ -1 +1 @@ --pass-self.mo:9.12-9.16: execution error, accessing identifier before its definition +@@ -1,3 +1,2 @@ + BEFORE! +-ys6dh-5cjiq-5dc +-So far so good! +pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.drun-run.ok b/test/run-drun/ok/pass-self.drun-run.ok index a6f776f43c6..8c041c36d6a 100644 --- a/test/run-drun/ok/pass-self.drun-run.ok +++ b/test/run-drun/ok/pass-self.drun-run.ok @@ -1,2 +1,5 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 +debug.print: BEFORE! +debug.print: rwlgt-iiaaa-aaaaa-aaaaa-cai +debug.print: So far so good! ingress Completed: Reply: 0x4449444c0000 diff --git a/test/run-drun/ok/pass-self.run-ir.ok b/test/run-drun/ok/pass-self.run-ir.ok index 40dd69d3163..693ecfbdfb9 100644 --- a/test/run-drun/ok/pass-self.run-ir.ok +++ b/test/run-drun/ok/pass-self.run-ir.ok @@ -1 +1,2 @@ +BEFORE! pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.run-low.ok b/test/run-drun/ok/pass-self.run-low.ok index 40dd69d3163..693ecfbdfb9 100644 --- a/test/run-drun/ok/pass-self.run-low.ok +++ b/test/run-drun/ok/pass-self.run-low.ok @@ -1 +1,2 @@ +BEFORE! pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.run.ok b/test/run-drun/ok/pass-self.run.ok deleted file mode 100644 index b80143c1f51..00000000000 --- a/test/run-drun/ok/pass-self.run.ok +++ /dev/null @@ -1 +0,0 @@ -pass-self.mo:9.12-9.16: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/pass-self.run.ret.ok b/test/run-drun/ok/pass-self.run.ret.ok deleted file mode 100644 index 69becfa16f9..00000000000 --- a/test/run-drun/ok/pass-self.run.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 1 diff --git a/test/run-drun/ok/pass-self.tc.ok b/test/run-drun/ok/pass-self.tc.ok index 8c1914c63ae..23113706c6d 100644 --- a/test/run-drun/ok/pass-self.tc.ok +++ b/test/run-drun/ok/pass-self.tc.ok @@ -1 +1 @@ -pass-self.mo:3.1-10.2: warning [M0016], cannot use Self before Self has been defined +pass-self.mo:3.1-17.2: warning [M0016], cannot use Self before Self has been defined diff --git a/test/run-drun/pass-self.mo b/test/run-drun/pass-self.mo index 992bc34803a..71313620bac 100644 --- a/test/run-drun/pass-self.mo +++ b/test/run-drun/pass-self.mo @@ -1,10 +1,17 @@ -import { debugPrint } = "mo:⛔"; +import { debugPrint; principalOfActor } = "mo:⛔"; -actor Self { - public func method() : async () { debugPrint "YESS!" }; +actor /*class () =*/ Self { + public func method() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; + func caller(_callee : shared () -> async ()) { }; - var c : ?(shared () -> async ()) = null; - func caller(callee : shared () -> async ()) { c := ?callee }; + debugPrint "BEFORE!"; + ignore principalOfActor Self; + caller(Self.method); + caller(method); + debugPrint (debug_show(principalOfActor Self)); + debugPrint "So far so good!"; - caller(Self.method) + //caller(method1); + //public func method1() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; + } From e2e025538c57b94b4490aae2849e49418b56d1ff Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 18:34:56 +0200 Subject: [PATCH 06/67] WIP --- src/mo_interpreter/interpret.ml | 4 ++-- test/run-drun/ok/pass-self.run.ok | 3 +++ test/run-drun/pass-self.mo | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 test/run-drun/ok/pass-self.run.ok diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 19b72723395..56109644ce8 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -890,9 +890,9 @@ and interpret_obj env obj_sort dec_fields (k : V.value V.cont) = | T.Actor -> let self = V.fresh_id() in let self' = V.Blob self in - let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty (*Lib.Promise.make_fulfilled self' |> V.Env.singleton "SelfX"*) V.Env.empty in + let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in - define_id' env' "Self" self'; + define_id' env' "Self" self'; (* HACK *) let partial () = let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_in in env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) diff --git a/test/run-drun/ok/pass-self.run.ok b/test/run-drun/ok/pass-self.run.ok new file mode 100644 index 00000000000..3d8710031e8 --- /dev/null +++ b/test/run-drun/ok/pass-self.run.ok @@ -0,0 +1,3 @@ +BEFORE! +ys6dh-5cjiq-5dc +So far so good! diff --git a/test/run-drun/pass-self.mo b/test/run-drun/pass-self.mo index 71313620bac..7d9d77b0225 100644 --- a/test/run-drun/pass-self.mo +++ b/test/run-drun/pass-self.mo @@ -11,7 +11,7 @@ actor /*class () =*/ Self { debugPrint (debug_show(principalOfActor Self)); debugPrint "So far so good!"; - //caller(method1); - //public func method1() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; + caller(method1); + public func method1() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; } From bfbb6b9212718fbaccc32d45d610fc386c31ae80 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 18:49:51 +0200 Subject: [PATCH 07/67] accept --- test/run-drun/ok/pass-self.diff-ir.ok | 3 ++- test/run-drun/ok/pass-self.diff-low.ok | 3 ++- test/run-drun/ok/pass-self.run.ok | 1 + test/run-drun/ok/pass-self.tc.ok | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/run-drun/ok/pass-self.diff-ir.ok b/test/run-drun/ok/pass-self.diff-ir.ok index f8b80d95909..0d67a8b204f 100644 --- a/test/run-drun/ok/pass-self.diff-ir.ok +++ b/test/run-drun/ok/pass-self.diff-ir.ok @@ -1,7 +1,8 @@ --- pass-self.run +++ pass-self.run-ir -@@ -1,3 +1,2 @@ +@@ -1,4 +1,2 @@ BEFORE! -ys6dh-5cjiq-5dc -So far so good! +-pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition +pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.diff-low.ok b/test/run-drun/ok/pass-self.diff-low.ok index ca24b7fcd7d..df0ba19b830 100644 --- a/test/run-drun/ok/pass-self.diff-low.ok +++ b/test/run-drun/ok/pass-self.diff-low.ok @@ -1,7 +1,8 @@ --- pass-self.run +++ pass-self.run-low -@@ -1,3 +1,2 @@ +@@ -1,4 +1,2 @@ BEFORE! -ys6dh-5cjiq-5dc -So far so good! +-pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition +pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.run.ok b/test/run-drun/ok/pass-self.run.ok index 3d8710031e8..5577a10c839 100644 --- a/test/run-drun/ok/pass-self.run.ok +++ b/test/run-drun/ok/pass-self.run.ok @@ -1,3 +1,4 @@ BEFORE! ys6dh-5cjiq-5dc So far so good! +pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/pass-self.tc.ok b/test/run-drun/ok/pass-self.tc.ok index 23113706c6d..2bc43232d94 100644 --- a/test/run-drun/ok/pass-self.tc.ok +++ b/test/run-drun/ok/pass-self.tc.ok @@ -1 +1,2 @@ +pass-self.mo:14.5-14.20: warning [M0016], cannot use method1 before method1 has been defined pass-self.mo:3.1-17.2: warning [M0016], cannot use Self before Self has been defined From f2c047a9391ad39f18ac72ce8feb7bae10be7d2d Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 18:53:09 +0200 Subject: [PATCH 08/67] simpler --- test/run-drun/ok/pass-self.tc.ok | 2 +- test/run-drun/pass-self.mo | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/run-drun/ok/pass-self.tc.ok b/test/run-drun/ok/pass-self.tc.ok index 2bc43232d94..10668a749f6 100644 --- a/test/run-drun/ok/pass-self.tc.ok +++ b/test/run-drun/ok/pass-self.tc.ok @@ -1,2 +1,2 @@ pass-self.mo:14.5-14.20: warning [M0016], cannot use method1 before method1 has been defined -pass-self.mo:3.1-17.2: warning [M0016], cannot use Self before Self has been defined +pass-self.mo:3.1-16.2: warning [M0016], cannot use Self before Self has been defined diff --git a/test/run-drun/pass-self.mo b/test/run-drun/pass-self.mo index 7d9d77b0225..d7655d92f13 100644 --- a/test/run-drun/pass-self.mo +++ b/test/run-drun/pass-self.mo @@ -12,6 +12,5 @@ actor /*class () =*/ Self { debugPrint "So far so good!"; caller(method1); - public func method1() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; - + public func method1() : async () { }; } From 3a51fa8b33df043b77e819d943e3593a200ef02b Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 30 Sep 2024 18:58:01 +0200 Subject: [PATCH 09/67] `Self.` should only see `public` fields --- src/mo_interpreter/interpret.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 56109644ce8..5fb1f12aaea 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -894,7 +894,7 @@ and interpret_obj env obj_sort dec_fields (k : V.value V.cont) = let env' = adjoin_vals { env with self } ve_in in define_id' env' "Self" self'; (* HACK *) let partial () = - let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_in in + let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) in interpret_dec_fields' env' (Some partial) dec_fields ve_ex From cfe59f0ca9b5647ee877079a8b9e57052fd85081 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 1 Oct 2024 10:59:23 +0200 Subject: [PATCH 10/67] simplify --- src/ir_interpreter/interpret_ir.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index b3e1b79139b..0c7a6465c8c 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -572,13 +572,14 @@ and interpret_exp_mut env exp (k : V.value V.cont) = and interpret_actor env ds fs k = let self = V.fresh_id () in - let env0 = {env with self = self} in + let self' = V.Blob self in + let env0 = {env with self} in let ve = declare_decs ds V.Env.empty in let env' = adjoin_vals env0 ve in interpret_decs env' ds (fun _ -> let obj = interpret_fields env' fs in env.actor_env := V.Env.add self obj !(env.actor_env); - k (V.Blob self) + k self' ) and interpret_lexp env lexp (k : (V.value ref) V.cont) = From 89334985a6c145680f80fb7e69e6c2cea472fda1 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 1 Oct 2024 14:26:56 +0200 Subject: [PATCH 11/67] fix the IR-interpreter --- src/ir_interpreter/interpret_ir.ml | 22 +++++++++++++++++----- test/run-drun/ok/pass-self.diff-ir.ok | 8 -------- test/run-drun/ok/pass-self.diff-low.ok | 8 -------- test/run-drun/ok/pass-self.run-ir.ok | 4 +++- test/run-drun/ok/pass-self.run-low.ok | 4 +++- 5 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 test/run-drun/ok/pass-self.diff-ir.ok delete mode 100644 test/run-drun/ok/pass-self.diff-low.ok diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 0c7a6465c8c..515f6cbcb1e 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -572,14 +572,15 @@ and interpret_exp_mut env exp (k : V.value V.cont) = and interpret_actor env ds fs k = let self = V.fresh_id () in - let self' = V.Blob self in let env0 = {env with self} in let ve = declare_decs ds V.Env.empty in let env' = adjoin_vals env0 ve in - interpret_decs env' ds (fun _ -> + let increments () = + env'.actor_env := V.Env.add self (defined_fields env' fs) !(env'.actor_env) in + interpret_decs env' ~increments ds (fun _ -> let obj = interpret_fields env' fs in env.actor_env := V.Env.add self obj !(env.actor_env); - k self' + k (V.Blob self) ) and interpret_lexp env lexp (k : (V.value ref) V.cont) = @@ -605,6 +606,17 @@ and interpret_lexp env lexp (k : (V.value ref) V.cont) = ) ) +and defined_fields env fs = + let ve = + List.fold_left + (fun ve (f : field) -> + match V.Env.find_opt f.it.var env.vals with + | Some binding when Lib.Promise.is_fulfilled binding + -> V.Env.disjoint_add f.it.name (Lib.Promise.value binding) ve + | _ -> ve + ) V.Env.empty fs in + V.Obj ve + and interpret_fields env fs = let ve = List.fold_left @@ -801,10 +813,10 @@ and interpret_dec env dec k = k () ) -and interpret_decs env decs (k : unit V.cont) = +and interpret_decs env ?(increments=ignore) decs (k : unit V.cont) = match decs with | [] -> k () - | d::ds -> interpret_dec env d (fun () -> interpret_decs env ds k) + | d::ds -> interpret_dec env d (fun () -> increments (); interpret_decs env ~increments ds k) and interpret_func env at sort x args f c v (k : V.value V.cont) = if env.flags.trace then trace "%s%s" x (string_of_arg env v); diff --git a/test/run-drun/ok/pass-self.diff-ir.ok b/test/run-drun/ok/pass-self.diff-ir.ok deleted file mode 100644 index 0d67a8b204f..00000000000 --- a/test/run-drun/ok/pass-self.diff-ir.ok +++ /dev/null @@ -1,8 +0,0 @@ ---- pass-self.run -+++ pass-self.run-ir -@@ -1,4 +1,2 @@ - BEFORE! --ys6dh-5cjiq-5dc --So far so good! --pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition -+pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.diff-low.ok b/test/run-drun/ok/pass-self.diff-low.ok deleted file mode 100644 index df0ba19b830..00000000000 --- a/test/run-drun/ok/pass-self.diff-low.ok +++ /dev/null @@ -1,8 +0,0 @@ ---- pass-self.run -+++ pass-self.run-low -@@ -1,4 +1,2 @@ - BEFORE! --ys6dh-5cjiq-5dc --So far so good! --pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition -+pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" diff --git a/test/run-drun/ok/pass-self.run-ir.ok b/test/run-drun/ok/pass-self.run-ir.ok index 693ecfbdfb9..5577a10c839 100644 --- a/test/run-drun/ok/pass-self.run-ir.ok +++ b/test/run-drun/ok/pass-self.run-ir.ok @@ -1,2 +1,4 @@ BEFORE! -pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" +ys6dh-5cjiq-5dc +So far so good! +pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/pass-self.run-low.ok b/test/run-drun/ok/pass-self.run-low.ok index 693ecfbdfb9..5577a10c839 100644 --- a/test/run-drun/ok/pass-self.run-low.ok +++ b/test/run-drun/ok/pass-self.run-low.ok @@ -1,2 +1,4 @@ BEFORE! -pass-self.mo:9.12-9.23: execution error, Unknown actor "ID:1" +ys6dh-5cjiq-5dc +So far so good! +pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition From d558928cd5e6292febfa48b035bb725796979ad8 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 1 Oct 2024 15:03:24 +0200 Subject: [PATCH 12/67] clean up the idiom --- src/mo_interpreter/interpret.ml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 5fb1f12aaea..0176a1fde13 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -893,11 +893,11 @@ and interpret_obj env obj_sort dec_fields (k : V.value V.cont) = let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in define_id' env' "Self" self'; (* HACK *) - let partial () = + let increments () = let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) in - interpret_dec_fields' env' (Some partial) dec_fields ve_ex + interpret_dec_fields env' ~increments dec_fields ve_ex (fun obj -> (env.actor_env := V.Env.add self obj !(env.actor_env); k self')) @@ -915,20 +915,13 @@ and declare_dec_fields dec_fields ve_ex ve_in : val_env * val_env = let ve_in' = V.Env.adjoin ve_in ve' in declare_dec_fields dec_fields' ve_ex' ve_in' -and interpret_dec_fields' env upd dec_fields ve (k : V.value V.cont) = - let commit = function - | None -> () - | Some f -> f () in +and interpret_dec_fields env ?(increments=ignore) dec_fields ve (k : V.value V.cont) = match dec_fields with | [] -> let obj = V.Obj (V.Env.map Lib.Promise.value ve) in k obj | {it = {dec; _}; _}::dec_fields' -> - interpret_dec env dec (fun _v -> commit upd; interpret_dec_fields' env upd dec_fields' ve k) - - -and interpret_dec_fields env dec_fields ve (k : V.value V.cont) = - interpret_dec_fields' env None dec_fields ve k + interpret_dec env dec (fun _v -> increments (); interpret_dec_fields env ~increments dec_fields' ve k) (* Blocks and Declarations *) From b3e59173893584ad4b2826eb986b89a3a9acc54f Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 1 Oct 2024 15:29:29 +0200 Subject: [PATCH 13/67] tweak --- src/ir_interpreter/interpret_ir.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 515f6cbcb1e..6b365068165 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -463,7 +463,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = in k (V.Obj ve) | SelfRef _, [] -> - k (V.Blob env.self) + k (context env) | SystemTimePrim, [] -> k (V.Nat64 (Numerics.Nat64.of_int 42)) | SystemCyclesRefundedPrim, [] -> (* faking it *) From c776e5e41a4a0b3895b4b41ec3cd00e1f9b03187 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 11:50:15 +0200 Subject: [PATCH 14/67] indent --- src/lowering/desugar.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lowering/desugar.ml b/src/lowering/desugar.ml index bcbb995e46d..b4e943bde7d 100644 --- a/src/lowering/desugar.ml +++ b/src/lowering/desugar.ml @@ -1145,7 +1145,7 @@ let transform_unit_body (u : S.comp_unit_body) : Ir.comp_unit = let actor_expression = build_actor u.at [] self_id fields u.note.S.note_typ in begin match actor_expression with | I.ActorE (ds, fs, u, t) -> - I.ActorU (None, ds, fs, u, t) + I.ActorU (None, ds, fs, u, t) | _ -> assert false end From 60f4efcb1f4fde1b9e98ca28ef6e01cb4b040b71 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 12:21:17 +0200 Subject: [PATCH 15/67] WIP: know thy self --- src/mo_def/arrange.ml | 2 +- src/mo_def/compUnit.ml | 4 ++-- src/mo_def/syntax.ml | 2 +- src/mo_frontend/parser.mly | 9 +++++---- src/mo_frontend/typing.ml | 2 +- src/mo_interpreter/interpret.ml | 12 ++++++------ src/viper/traversals.ml | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/mo_def/arrange.ml b/src/mo_def/arrange.ml index b5a1500d74f..382b077092e 100644 --- a/src/mo_def/arrange.ml +++ b/src/mo_def/arrange.ml @@ -69,7 +69,7 @@ module Make (Cfg : Config) = struct | FromCandidE e -> "FromCandidE" $$ [exp e] | TupE es -> "TupE" $$ exps es | ProjE (e, i) -> "ProjE" $$ [exp e; Atom (string_of_int i)] - | ObjBlockE (s, t, dfs) -> "ObjBlockE" $$ [obj_sort s; match t with None -> Atom "_" | Some t -> typ t] @ List.map dec_field dfs + | ObjBlockE (s, (_FIXME ,t), dfs) -> "ObjBlockE" $$ [obj_sort s; match t with None -> Atom "_" | Some t -> typ t] @ List.map dec_field dfs | ObjE ([], efs) -> "ObjE" $$ List.map exp_field efs | ObjE (bases, efs) -> "ObjE" $$ exps bases @ [Atom "with"] @ List.map exp_field efs | DotE (e, x) -> "DotE" $$ [exp e; id x] diff --git a/src/mo_def/compUnit.ml b/src/mo_def/compUnit.ml index f61a1cecd9c..a71aafa29de 100644 --- a/src/mo_def/compUnit.ml +++ b/src/mo_def/compUnit.ml @@ -80,14 +80,14 @@ let obj_decs obj_sort at note id_opt fields = match id_opt with | None -> [ { it = ExpD { - it = ObjBlockE ( { it = obj_sort; at; note = () }, None, fields); + it = ObjBlockE ( { it = obj_sort; at; note = () }, (None, None), fields); at; note }; at; note }] | Some id -> [ { it = LetD ( { it = VarP id; at; note = note.note_typ }, - { it = ObjBlockE ({ it = obj_sort; at; note = () }, None, fields); + { it = ObjBlockE ({ it = obj_sort; at; note = () }, (None, None), fields); at; note; }, None); at; note diff --git a/src/mo_def/syntax.ml b/src/mo_def/syntax.ml index 5fa55b9053c..5917938b628 100644 --- a/src/mo_def/syntax.ml +++ b/src/mo_def/syntax.ml @@ -165,7 +165,7 @@ and exp' = | OptE of exp (* option injection *) | DoOptE of exp (* option monad *) | BangE of exp (* scoped option projection *) - | ObjBlockE of obj_sort * typ option * dec_field list (* object block *) + | ObjBlockE of obj_sort * (id option * typ option) * dec_field list (* object block *) | ObjE of exp list * exp_field list (* record literal/extension *) | TagE of id * exp (* variant *) | DotE of exp * id (* object projection *) diff --git a/src/mo_frontend/parser.mly b/src/mo_frontend/parser.mly index 73353a1720f..85de84694bd 100644 --- a/src/mo_frontend/parser.mly +++ b/src/mo_frontend/parser.mly @@ -195,13 +195,13 @@ let share_dec_field (df : dec_field) = } | _ -> df -and objblock s ty dec_fields = +and objblock s id ty dec_fields = List.iter (fun df -> match df.it.vis.it, df.it.dec.it with | Public _, ClassD (_, id, _, _, _, _, _, _) when is_anon_id id -> syntax_error df.it.dec.at "M0158" "a public class cannot be anonymous, please provide a name" | _ -> ()) dec_fields; - ObjBlockE(s, ty, dec_fields) + ObjBlockE(s, (id, ty), dec_fields) %} @@ -872,12 +872,13 @@ dec_nonvar : let named, x = xf sort $sloc in let e = if s.it = Type.Actor then + let id = if named then Some x else None in AwaitE (Type.Fut, AsyncE(Type.Fut, scope_bind (anon_id "async" (at $sloc)) (at $sloc), - objblock s t (List.map share_dec_field efs) @? at $sloc) + objblock s id t (List.map share_dec_field efs) @? at $sloc) @? at $sloc) @? at $sloc - else objblock s t efs @? at $sloc + else objblock s None t efs @? at $sloc in let_or_exp named x e.it e.at } | sp=shared_pat_opt FUNC xf=id_opt diff --git a/src/mo_frontend/typing.ml b/src/mo_frontend/typing.ml index 350747ccc99..212260556f9 100644 --- a/src/mo_frontend/typing.ml +++ b/src/mo_frontend/typing.ml @@ -1291,7 +1291,7 @@ and infer_exp'' env exp : T.typ = in let t = infer_obj env' obj_sort.it dec_fields exp.at in begin match env.pre, typ_opt with - | false, Some typ -> + | false, (_FIXME, Some typ) -> let t' = check_typ env' typ in if not (T.sub t t') then local_error env exp.at "M0192" diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 0176a1fde13..8efb8d874c3 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -482,8 +482,8 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | _ -> assert false) | ProjE (exp1, n) -> interpret_exp env exp1 (fun v1 -> k (List.nth (V.as_tup v1) n)) - | ObjBlockE (obj_sort, _, dec_fields) -> - interpret_obj env obj_sort.it dec_fields k + | ObjBlockE (obj_sort, (self_id_opt, _), dec_fields) -> + interpret_obj env obj_sort.it self_id_opt dec_fields k | ObjE (exp_bases, exp_fields) -> let fields fld_env = interpret_exp_fields env exp_fields fld_env (fun env -> k (V.Obj env)) in let open V.Env in @@ -885,14 +885,14 @@ and match_shared_pat env shared_pat c = (* Objects *) -and interpret_obj env obj_sort dec_fields (k : V.value V.cont) = +and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = match obj_sort with | T.Actor -> let self = V.fresh_id() in let self' = V.Blob self in let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in - define_id' env' "Self" self'; (* HACK *) + Option.iter (fun id -> define_id' env' id.it self') self_id; let increments () = let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) @@ -971,7 +971,7 @@ and interpret_dec env dec (k : V.value V.cont) = let f = interpret_func env id.it shared_pat pat (fun env' k' -> if obj_sort.it <> T.Actor then let env'' = adjoin_vals env' (declare_id id') in - interpret_obj env'' obj_sort.it dec_fields (fun v' -> + interpret_obj env'' obj_sort.it None dec_fields (fun v' -> define_id env'' id' v'; k' v') else @@ -983,7 +983,7 @@ and interpret_dec env dec (k : V.value V.cont) = rets = Some k''; throws = Some r } in - interpret_obj env''' obj_sort.it dec_fields (fun v' -> + interpret_obj env''' obj_sort.it (Some id') dec_fields (fun v' -> define_id env''' id' v'; k'' v')) k') diff --git a/src/viper/traversals.ml b/src/viper/traversals.ml index c5cf7933ea4..bdf02154c6e 100644 --- a/src/viper/traversals.ml +++ b/src/viper/traversals.ml @@ -48,7 +48,7 @@ let rec over_exp (v : visitor) (exp : exp) : exp = | TupE exps -> { exp with it = TupE (List.map (over_exp v) exps) } | ArrayE (x, exps) -> { exp with it = ArrayE (x, List.map (over_exp v) exps) } | BlockE ds -> { exp with it = BlockE (List.map (over_dec v) ds) } - | ObjBlockE (x, t, dfs) -> { exp with it = ObjBlockE (x, Option.map (over_typ v) t, List.map (over_dec_field v) dfs) } + | ObjBlockE (x, (n, t), dfs) -> { exp with it = ObjBlockE (x, (n, Option.map (over_typ v) t), List.map (over_dec_field v) dfs) } | ObjE (bases, efs) -> { exp with it = ObjE (List.map (over_exp v) bases, List.map (over_exp_field v) efs) } | IfE (exp1, exp2, exp3) -> { exp with it = IfE(over_exp v exp1, over_exp v exp2, over_exp v exp3) } | TryE (exp1, cases, exp2) -> { exp with it = TryE (over_exp v exp1, List.map (over_case v) cases, Option.map (over_exp v) exp2) } From 3490b616a9889122f9b22c951908b89b3436ae17 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 12:37:31 +0200 Subject: [PATCH 16/67] simplify --- src/mo_interpreter/interpret.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 8efb8d874c3..d1d6e3381aa 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -892,7 +892,7 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = let self' = V.Blob self in let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in - Option.iter (fun id -> define_id' env' id.it self') self_id; + Option.iter (fun id -> define_id env' id self') self_id; let increments () = let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) From 66b0ecc4ea4e1f45feb9ac9f86286a7123db85f8 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 13:06:58 +0200 Subject: [PATCH 17/67] tweak --- src/mo_interpreter/interpret.ml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index d1d6e3381aa..04b6c66661d 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -785,7 +785,7 @@ and declare_pat_fields pfs ve : val_env = and define_id env id v = define_id' env id.it v -and define_id' env id v = if not(Lib.Promise.is_fulfilled (find id env.vals)) then +and define_id' env id v = Lib.Promise.fulfill (find id env.vals) v and define_pat env pat v = @@ -797,19 +797,20 @@ and define_pat env pat v = false and match_lit lit v : bool = + let open Numerics in match !lit, v with | NullLit, V.Null -> true | BoolLit b, V.Bool b' -> b = b' - | NatLit n, V.Int n' -> Numerics.Int.eq n n' - | Nat8Lit n, V.Nat8 n' -> Numerics.Nat8.eq n n' - | Nat16Lit n, V.Nat16 n' -> Numerics.Nat16.eq n n' - | Nat32Lit n, V.Nat32 n' -> Numerics.Nat32.eq n n' - | Nat64Lit n, V.Nat64 n' -> Numerics.Nat64.eq n n' - | IntLit i, V.Int i' -> Numerics.Int.eq i i' - | Int8Lit i, V.Int8 i' -> Numerics.Int_8.eq i i' - | Int16Lit i, V.Int16 i' -> Numerics.Int_16.eq i i' - | Int32Lit i, V.Int32 i' -> Numerics.Int_32.eq i i' - | Int64Lit i, V.Int64 i' -> Numerics.Int_64.eq i i' + | NatLit n, V.Int n' -> Int.eq n n' + | Nat8Lit n, V.Nat8 n' -> Nat8.eq n n' + | Nat16Lit n, V.Nat16 n' -> Nat16.eq n n' + | Nat32Lit n, V.Nat32 n' -> Nat32.eq n n' + | Nat64Lit n, V.Nat64 n' -> Nat64.eq n n' + | IntLit i, V.Int i' -> Int.eq i i' + | Int8Lit i, V.Int8 i' -> Int_8.eq i i' + | Int16Lit i, V.Int16 i' -> Int_16.eq i i' + | Int32Lit i, V.Int32 i' -> Int_32.eq i i' + | Int64Lit i, V.Int64 i' -> Int_64.eq i i' | FloatLit z, V.Float z' -> z = z' | CharLit c, V.Char c' -> c = c' | TextLit u, V.Text u' -> u = u' From c4f8c157f0f49e058eabb931dc43bba4436438d5 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 15:10:54 +0200 Subject: [PATCH 18/67] WIP: deal with self-binding --- src/mo_frontend/definedness.ml | 10 +++++++--- test/run-drun/ok/pass-self.tc.ok | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index a0da6b1e43f..4ce399799b2 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -101,9 +101,9 @@ let rec exp msgs e : f = match e.it with | FromCandidE e -> exp msgs e | TupE es -> exps msgs es | ProjE (e, i) -> exp msgs e - | ObjBlockE (s, _, dfs) -> + | ObjBlockE (s, (self_id_opt, _), dfs) -> (* For actors, this may be too permissive; to be revised when we work on actors again *) - group msgs (dec_fields msgs dfs) + group msgs ~extern:self_id_opt (dec_fields msgs dfs) | ObjE (bases, efs) -> exps msgs bases ++ exp_fields msgs efs | DotE (e, i) -> exp msgs e | AssignE (e1, e2) -> exps msgs [e1; e2] @@ -192,9 +192,13 @@ and decs msgs decs : group = (d.at, defs, eager_vars f, delayed_vars f) ) decs -and group msgs (grp : group) : f = +and group msgs ?(extern=None) (grp : group) : f = (* Create a map from declared variable to their definition point *) let defWhen = M.disjoint_unions (List.mapi (fun i (_, defs, _, _) -> map_of_set i defs) grp) in + (* Insert the externally defined binding in front if present, non-shadowing *) + let defWhen = match extern with + | Some b when M.find_opt b.it defWhen |> Option.is_none -> M.add b.it (-1) defWhen + | _ -> defWhen in (* Calculate the relation R *) let r = NameRel.unions (List.map (fun (_, defs, _, delayed) -> NameRel.cross defs delayed) grp) in (* Check for errors *) diff --git a/test/run-drun/ok/pass-self.tc.ok b/test/run-drun/ok/pass-self.tc.ok index 10668a749f6..2ec3fe3d836 100644 --- a/test/run-drun/ok/pass-self.tc.ok +++ b/test/run-drun/ok/pass-self.tc.ok @@ -1,2 +1 @@ pass-self.mo:14.5-14.20: warning [M0016], cannot use method1 before method1 has been defined -pass-self.mo:3.1-16.2: warning [M0016], cannot use Self before Self has been defined From bb3e9a1dce23e041b8f3d717036ba948fc7b255a Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 15:28:47 +0200 Subject: [PATCH 19/67] tweak --- src/mo_frontend/definedness.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index 4ce399799b2..a75ac98eab6 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -246,4 +246,3 @@ let check_lib lib = ignore (group msgs (decs msgs (imp_ds @ ds))); Some () ) - From 9a2efc77e0cca12bf8bed30db960ffd41e325afa Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 15:58:50 +0200 Subject: [PATCH 20/67] fix the double-fulfill problem --- src/mo_interpreter/interpret.ml | 7 ++++++- test/fail/access-self-prematurely.mo | 6 ++++++ test/fail/ok/access-self-prematurely.tc.ok | 1 + test/run-drun/ok/pass-self.drun-run.ok | 2 +- test/run-drun/ok/pass-self.run-ir.ok | 3 +-- test/run-drun/ok/pass-self.run-low.ok | 3 +-- test/run-drun/ok/pass-self.run.ok | 3 +-- test/run-drun/ok/pass-self.tc.ok | 1 - test/run-drun/pass-self.mo | 5 +---- 9 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 test/fail/access-self-prematurely.mo create mode 100644 test/fail/ok/access-self-prematurely.tc.ok delete mode 100644 test/run-drun/ok/pass-self.tc.ok diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 04b6c66661d..898ad4f8993 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -893,8 +893,13 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = let self' = V.Blob self in let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in + (* Define self_id when there is non-shadowing way to do it *) + (* FIXME: when non-shadow *) + let env' = match self_id with + | Some self -> adjoin_vals env' (declare_id self) + | _ -> env' in Option.iter (fun id -> define_id env' id self') self_id; - let increments () = + let increments () = (* FIXME: shadowing? *) let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) in diff --git a/test/fail/access-self-prematurely.mo b/test/fail/access-self-prematurely.mo new file mode 100644 index 00000000000..718228d4511 --- /dev/null +++ b/test/fail/access-self-prematurely.mo @@ -0,0 +1,6 @@ +actor /*class () =*/ Self { + func caller(_callee : shared () -> async ()) { }; + caller(Self.method1); // FIXME: should be error too + caller(method1); + public func method1() : async () { }; +} diff --git a/test/fail/ok/access-self-prematurely.tc.ok b/test/fail/ok/access-self-prematurely.tc.ok new file mode 100644 index 00000000000..548b3550dea --- /dev/null +++ b/test/fail/ok/access-self-prematurely.tc.ok @@ -0,0 +1 @@ +access-self-prematurely.mo:4.5-4.20: warning [M0016], cannot use method1 before method1 has been defined diff --git a/test/run-drun/ok/pass-self.drun-run.ok b/test/run-drun/ok/pass-self.drun-run.ok index 8c041c36d6a..79f28bef6a0 100644 --- a/test/run-drun/ok/pass-self.drun-run.ok +++ b/test/run-drun/ok/pass-self.drun-run.ok @@ -1,5 +1,5 @@ ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 -debug.print: BEFORE! +debug.print: Before! debug.print: rwlgt-iiaaa-aaaaa-aaaaa-cai debug.print: So far so good! ingress Completed: Reply: 0x4449444c0000 diff --git a/test/run-drun/ok/pass-self.run-ir.ok b/test/run-drun/ok/pass-self.run-ir.ok index 5577a10c839..9deafdd2f39 100644 --- a/test/run-drun/ok/pass-self.run-ir.ok +++ b/test/run-drun/ok/pass-self.run-ir.ok @@ -1,4 +1,3 @@ -BEFORE! +Before! ys6dh-5cjiq-5dc So far so good! -pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/pass-self.run-low.ok b/test/run-drun/ok/pass-self.run-low.ok index 5577a10c839..9deafdd2f39 100644 --- a/test/run-drun/ok/pass-self.run-low.ok +++ b/test/run-drun/ok/pass-self.run-low.ok @@ -1,4 +1,3 @@ -BEFORE! +Before! ys6dh-5cjiq-5dc So far so good! -pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/pass-self.run.ok b/test/run-drun/ok/pass-self.run.ok index 5577a10c839..9deafdd2f39 100644 --- a/test/run-drun/ok/pass-self.run.ok +++ b/test/run-drun/ok/pass-self.run.ok @@ -1,4 +1,3 @@ -BEFORE! +Before! ys6dh-5cjiq-5dc So far so good! -pass-self.mo:14.12-14.19: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/pass-self.tc.ok b/test/run-drun/ok/pass-self.tc.ok deleted file mode 100644 index 2ec3fe3d836..00000000000 --- a/test/run-drun/ok/pass-self.tc.ok +++ /dev/null @@ -1 +0,0 @@ -pass-self.mo:14.5-14.20: warning [M0016], cannot use method1 before method1 has been defined diff --git a/test/run-drun/pass-self.mo b/test/run-drun/pass-self.mo index d7655d92f13..147e7da9abd 100644 --- a/test/run-drun/pass-self.mo +++ b/test/run-drun/pass-self.mo @@ -4,13 +4,10 @@ actor /*class () =*/ Self { public func method() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; func caller(_callee : shared () -> async ()) { }; - debugPrint "BEFORE!"; + debugPrint "Before!"; ignore principalOfActor Self; caller(Self.method); caller(method); debugPrint (debug_show(principalOfActor Self)); debugPrint "So far so good!"; - - caller(method1); - public func method1() : async () { }; } From c14f3b1e79e407959b838935beb5396872ca310e Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 16:01:29 +0200 Subject: [PATCH 21/67] go back to error --- src/mo_frontend/definedness.ml | 2 +- test/fail/ok/access-self-prematurely.tc.ok | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index a75ac98eab6..c6281602b43 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -213,7 +213,7 @@ and group msgs ?(extern=None) (grp : group) : f = else (*assert eager;*) Diag.add_msg msgs - (Diag.warning_message + (Diag.error_message at "M0016" "definedness" diff --git a/test/fail/ok/access-self-prematurely.tc.ok b/test/fail/ok/access-self-prematurely.tc.ok index 548b3550dea..6a62a9abe2e 100644 --- a/test/fail/ok/access-self-prematurely.tc.ok +++ b/test/fail/ok/access-self-prematurely.tc.ok @@ -1 +1 @@ -access-self-prematurely.mo:4.5-4.20: warning [M0016], cannot use method1 before method1 has been defined +access-self-prematurely.mo:4.5-4.20: definedness error [M0016], cannot use method1 before method1 has been defined From 53d5f84281f61732b2105d3b8a3b3232bf59ca32 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 16:07:33 +0200 Subject: [PATCH 22/67] cleanup --- src/mo_frontend/definedness.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index c6281602b43..00a79ec9b31 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -210,7 +210,7 @@ and group msgs ?(extern=None) (grp : group) : f = defined after j *) if j < i then () (* all izz well *) - else (*assert eager;*) + else Diag.add_msg msgs (Diag.error_message From af3fb01bce88d0462310cf9aeba6908852dacf2b Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 16:09:23 +0200 Subject: [PATCH 23/67] missed --- test/fail/ok/access-self-prematurely.tc.ret.ok | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/fail/ok/access-self-prematurely.tc.ret.ok diff --git a/test/fail/ok/access-self-prematurely.tc.ret.ok b/test/fail/ok/access-self-prematurely.tc.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/fail/ok/access-self-prematurely.tc.ret.ok @@ -0,0 +1 @@ +Return code 1 From 744e3ee7b76436259f8cac7dccac9b17aac06040 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 2 Oct 2024 17:05:49 +0200 Subject: [PATCH 24/67] fix shadowing --- src/mo_interpreter/interpret.ml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 898ad4f8993..f5f0ff4293a 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -893,15 +893,20 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = let self' = V.Blob self in let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in - (* Define self_id when there is non-shadowing way to do it *) - (* FIXME: when non-shadow *) - let env' = match self_id with - | Some self -> adjoin_vals env' (declare_id self) - | _ -> env' in - Option.iter (fun id -> define_id env' id self') self_id; - let increments () = (* FIXME: shadowing? *) - let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in - env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) + (* Define self_id in inner scope if there is a non-shadowing way to do it *) + let env', increments = + if match self_id with | None -> false | Some self -> V.Env.mem self.it ve_in + then env', ignore (* would shadow *) + else begin + let env' = match self_id with + | Some self -> adjoin_vals env' (declare_id self) + | _ -> env' in + Option.iter (fun id -> define_id env' id self') self_id; + let increments () = + let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in + env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) in + env', increments + end in interpret_dec_fields env' ~increments dec_fields ve_ex (fun obj -> From 63c5779714d616178d8bc9f03e4e8be4eff0e558 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 7 Oct 2024 11:26:50 +0200 Subject: [PATCH 25/67] simplify this --- src/mo_frontend/definedness.ml | 71 +++++++++++++++++----------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index 00a79ec9b31..1b980f0a46c 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -84,55 +84,54 @@ let rec exp msgs e : f = match e.it with (* Or anything that is occurring in a call (as this may call a closure): *) | CallE (e1, ts, e2) -> eagerify (exps msgs [e1; e2]) (* And break, return, throw can be thought of as calling a continuation: *) - | BreakE (i, e) -> eagerify (exp msgs e) - | RetE e -> eagerify (exp msgs e) + | BreakE (_, e) + | RetE e | ThrowE e -> eagerify (exp msgs e) (* Uses are delayed by function expressions *) | FuncE (_, sp, tp, p, t, _, e) -> - delayify ((exp msgs e /// pat msgs p) /// shared_pat msgs sp) + delayify ((exp msgs e /// pat msgs p) /// shared_pat msgs sp) + | ObjBlockE (s, (self_id_opt, _), dfs) -> + group msgs ~extern:self_id_opt (dec_fields msgs dfs) (* The rest remaining cases just collect the uses of subexpressions: *) | LitE _ | ActorUrlE _ | PrimE _ | ImportE _ -> M.empty - | UnE (_, uo, e) -> exp msgs e - | BinE (_, e1, bo, e2)-> exps msgs [e1; e2] - | RelE (_, e1, ro, e2)-> exps msgs [e1; e2] - | ShowE (_, e) -> exp msgs e - | ToCandidE es -> exps msgs es - | FromCandidE e -> exp msgs e - | TupE es -> exps msgs es - | ProjE (e, i) -> exp msgs e - | ObjBlockE (s, (self_id_opt, _), dfs) -> - (* For actors, this may be too permissive; to be revised when we work on actors again *) - group msgs ~extern:self_id_opt (dec_fields msgs dfs) | ObjE (bases, efs) -> exps msgs bases ++ exp_fields msgs efs - | DotE (e, i) -> exp msgs e - | AssignE (e1, e2) -> exps msgs [e1; e2] - | ArrayE (m, es) -> exps msgs es - | IdxE (e1, e2) -> exps msgs [e1; e2] + | TupE es + | ArrayE (_, es) + | ToCandidE es -> exps msgs es | BlockE ds -> group msgs (decs msgs ds) - | NotE e -> exp msgs e - | AndE (e1, e2) -> exps msgs [e1; e2] - | OrE (e1, e2) -> exps msgs [e1; e2] - | ImpliesE (e1, e2) -> exps msgs [e1; e2] - | OldE e -> exp msgs e | IfE (e1, e2, e3) -> exps msgs [e1; e2; e3] - | SwitchE (e, cs) -> exp msgs e ++ cases msgs cs + | SwitchE (e, cs) | TryE (e, cs, None) -> exp msgs e ++ cases msgs cs | TryE (e, cs, Some f)-> exps msgs [e; f] ++ cases msgs cs - | WhileE (e1, e2) -> exps msgs [e1; e2] | LoopE (e1, None) -> exp msgs e1 - | LoopE (e1, Some e2) -> exps msgs [e1; e2] + | LoopE (e1, Some e2) + | WhileE (e1, e2) + | AssignE (e1, e2) + | IdxE (e1, e2) + | BinE (_, e1, _, e2) + | RelE (_, e1, _, e2) + | AndE (e1, e2) + | OrE (e1, e2) + | ImpliesE (e1, e2) -> exps msgs [e1; e2] | ForE (p, e1, e2) -> exp msgs e1 ++ (exp msgs e2 /// pat msgs p) - | LabelE (i, t, e) -> exp msgs e - | DebugE e -> exp msgs e - | AsyncE (_, _, e) -> exp msgs e - | AwaitE (_, e) -> exp msgs e - | AssertE (_, e) -> exp msgs e - | AnnotE (e, t) -> exp msgs e - | OptE e -> exp msgs e - | DoOptE e -> exp msgs e - | BangE e -> exp msgs e - | TagE (_, e) -> exp msgs e + | UnE (_, _, e) + | ShowE (_, e) + | FromCandidE e + | DotE (e, _) + | ProjE (e, _) + | NotE e + | OldE e + | LabelE (_, _, e) + | DebugE e + | AsyncE (_, _, e) + | AwaitE (_, e) + | AssertE (_, e) + | AnnotE (e, _) + | OptE e + | DoOptE e + | BangE e + | TagE (_, e) | IgnoreE e -> exp msgs e and exps msgs es : f = unions (exp msgs) es From 88c4b4025b00f9e8c4692abd1b3eb0506bf79afe Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 12:39:45 +0200 Subject: [PATCH 26/67] delay method lookup by pairing --- src/mo_interpreter/interpret.ml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index f5f0ff4293a..3ed1cdadb7a 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -508,10 +508,12 @@ and interpret_exp_mut env exp (k : V.value V.cont) = match v1 with | V.Obj fs -> k (find id.it fs) - | V.Blob aid when T.sub exp1.note.note_typ (T.Obj (T.Actor, [])) -> + | V.Blob aid as actor when T.sub exp1.note.note_typ (T.Obj (T.Actor, [])) -> begin match V.Env.find_opt aid !(env.actor_env) with (* not quite correct: On the platform, you can invoke and get a reject *) - | None -> trap exp.at "Unknown actor \"%s\"" aid + | None -> + (* method not defined yet, just pair them up *) + k (V.Tup [actor; V.Text id.it]) | Some actor_value -> let fs = V.as_obj actor_value in match V.Env.find_opt id.it fs with @@ -572,7 +574,13 @@ and interpret_exp_mut env exp (k : V.value V.cont) = in k v' | CallE (exp1, typs, exp2) -> interpret_exp env exp1 (fun v1 -> - interpret_exp env exp2 (fun v2 -> + let v1 = begin match v1 with + | V.Tup [V.Blob aid; V.Text id] -> + let methods = V.Env.find aid !(env.actor_env) in + V.Env.find id (V.as_obj methods) + | _ -> v1 + end in + interpret_exp env exp2 (fun v2 -> let call_conv, f = V.as_func v1 in check_call_conv exp1 call_conv; check_call_conv_arg env exp v2 call_conv; @@ -908,7 +916,7 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = env', increments end in - interpret_dec_fields env' ~increments dec_fields ve_ex + interpret_dec_fields env' dec_fields ve_ex (fun obj -> (env.actor_env := V.Env.add self obj !(env.actor_env); k self')) From d14834a86f0578af91bf9a3270dde97661858fd3 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 12:43:40 +0200 Subject: [PATCH 27/67] simplify --- src/mo_interpreter/interpret.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 3ed1cdadb7a..a2059a64a56 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -576,8 +576,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = interpret_exp env exp1 (fun v1 -> let v1 = begin match v1 with | V.Tup [V.Blob aid; V.Text id] -> - let methods = V.Env.find aid !(env.actor_env) in - V.Env.find id (V.as_obj methods) + V.Env.(find aid !(env.actor_env) |> V.as_obj |> find id) | _ -> v1 end in interpret_exp env exp2 (fun v2 -> From c7ffd49d5e8fc6649dda8ea823999f9ba23191ae Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 13:00:47 +0200 Subject: [PATCH 28/67] add test to check that reference to (as of yet) undefined public methods can still be taken --- test/run-drun/incomplete-self-reference.mo | 9 +++++++++ test/run-drun/ok/incomplete-self-reference.diff-ir.ok | 5 +++++ test/run-drun/ok/incomplete-self-reference.diff-low.ok | 5 +++++ test/run-drun/ok/incomplete-self-reference.drun-run.ok | 4 ++++ test/run-drun/ok/incomplete-self-reference.run-ir.ok | 1 + test/run-drun/ok/incomplete-self-reference.run-low.ok | 1 + test/run-drun/ok/incomplete-self-reference.run.ok | 1 + 7 files changed, 26 insertions(+) create mode 100644 test/run-drun/incomplete-self-reference.mo create mode 100644 test/run-drun/ok/incomplete-self-reference.diff-ir.ok create mode 100644 test/run-drun/ok/incomplete-self-reference.diff-low.ok create mode 100644 test/run-drun/ok/incomplete-self-reference.drun-run.ok create mode 100644 test/run-drun/ok/incomplete-self-reference.run-ir.ok create mode 100644 test/run-drun/ok/incomplete-self-reference.run-low.ok create mode 100644 test/run-drun/ok/incomplete-self-reference.run.ok diff --git a/test/run-drun/incomplete-self-reference.mo b/test/run-drun/incomplete-self-reference.mo new file mode 100644 index 00000000000..267a9376e74 --- /dev/null +++ b/test/run-drun/incomplete-self-reference.mo @@ -0,0 +1,9 @@ +import { debugPrint } = "mo:⛔"; + +actor Self { + var stored : shared () -> async () = Self.method; + public func method() : async () { debugPrint "Hey!" }; + public func go() : async () { await stored() }; +}; + +Self.go(); //OR-CALL ingress go "DIDL\x00\x00" diff --git a/test/run-drun/ok/incomplete-self-reference.diff-ir.ok b/test/run-drun/ok/incomplete-self-reference.diff-ir.ok new file mode 100644 index 00000000000..263ad4c98e5 --- /dev/null +++ b/test/run-drun/ok/incomplete-self-reference.diff-ir.ok @@ -0,0 +1,5 @@ +--- incomplete-self-reference.run ++++ incomplete-self-reference.run-ir +@@ -1 +1 @@ +-Hey! ++incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/incomplete-self-reference.diff-low.ok b/test/run-drun/ok/incomplete-self-reference.diff-low.ok new file mode 100644 index 00000000000..3f0319de918 --- /dev/null +++ b/test/run-drun/ok/incomplete-self-reference.diff-low.ok @@ -0,0 +1,5 @@ +--- incomplete-self-reference.run ++++ incomplete-self-reference.run-low +@@ -1 +1 @@ +-Hey! ++incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/incomplete-self-reference.drun-run.ok b/test/run-drun/ok/incomplete-self-reference.drun-run.ok new file mode 100644 index 00000000000..bef445760af --- /dev/null +++ b/test/run-drun/ok/incomplete-self-reference.drun-run.ok @@ -0,0 +1,4 @@ +ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 +ingress Completed: Reply: 0x4449444c0000 +debug.print: Hey! +ingress Completed: Reply: 0x4449444c0000 diff --git a/test/run-drun/ok/incomplete-self-reference.run-ir.ok b/test/run-drun/ok/incomplete-self-reference.run-ir.ok new file mode 100644 index 00000000000..97152c4a52d --- /dev/null +++ b/test/run-drun/ok/incomplete-self-reference.run-ir.ok @@ -0,0 +1 @@ +incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/incomplete-self-reference.run-low.ok b/test/run-drun/ok/incomplete-self-reference.run-low.ok new file mode 100644 index 00000000000..97152c4a52d --- /dev/null +++ b/test/run-drun/ok/incomplete-self-reference.run-low.ok @@ -0,0 +1 @@ +incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/incomplete-self-reference.run.ok b/test/run-drun/ok/incomplete-self-reference.run.ok new file mode 100644 index 00000000000..4c5477a837a --- /dev/null +++ b/test/run-drun/ok/incomplete-self-reference.run.ok @@ -0,0 +1 @@ +Hey! From d9d5b2b5656c48f15a92fc0efcd1ef553cee72f9 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 13:24:24 +0200 Subject: [PATCH 29/67] Update access-self-prematurely.mo this is now legal: see `run-run/incomplete-self-reference.mo` --- test/fail/access-self-prematurely.mo | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fail/access-self-prematurely.mo b/test/fail/access-self-prematurely.mo index 718228d4511..0d815ac0933 100644 --- a/test/fail/access-self-prematurely.mo +++ b/test/fail/access-self-prematurely.mo @@ -1,6 +1,5 @@ actor /*class () =*/ Self { func caller(_callee : shared () -> async ()) { }; - caller(Self.method1); // FIXME: should be error too caller(method1); public func method1() : async () { }; } From a8946e71f35f10792b67ec124c65bdf5cff544b8 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 13:26:09 +0200 Subject: [PATCH 30/67] accept --- test/fail/ok/access-self-prematurely.tc.ok | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fail/ok/access-self-prematurely.tc.ok b/test/fail/ok/access-self-prematurely.tc.ok index 6a62a9abe2e..d6e4d28afbc 100644 --- a/test/fail/ok/access-self-prematurely.tc.ok +++ b/test/fail/ok/access-self-prematurely.tc.ok @@ -1 +1 @@ -access-self-prematurely.mo:4.5-4.20: definedness error [M0016], cannot use method1 before method1 has been defined +access-self-prematurely.mo:3.5-3.20: definedness error [M0016], cannot use method1 before method1 has been defined From 3afe689a71f2d71898dadd1c7e140d55fa7092f8 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 15:47:45 +0200 Subject: [PATCH 31/67] tweak --- src/mo_interpreter/interpret.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index a2059a64a56..7aea8110605 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -510,10 +510,9 @@ and interpret_exp_mut env exp (k : V.value V.cont) = k (find id.it fs) | V.Blob aid as actor when T.sub exp1.note.note_typ (T.Obj (T.Actor, [])) -> begin match V.Env.find_opt aid !(env.actor_env) with - (* not quite correct: On the platform, you can invoke and get a reject *) | None -> (* method not defined yet, just pair them up *) - k (V.Tup [actor; V.Text id.it]) + k V.(Tup [actor; Text id.it]) | Some actor_value -> let fs = V.as_obj actor_value in match V.Env.find_opt id.it fs with From 69290a698908ebaff37abed8a86e7a5710959026 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 16:06:52 +0200 Subject: [PATCH 32/67] WIP --- src/ir_interpreter/interpret_ir.ml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 6b365068165..939ce6c15a9 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -307,6 +307,9 @@ and interpret_exp_mut env exp (k : V.value V.cont) = ) | LitE lit -> k (interpret_lit env lit) + | PrimE (ActorDotPrim n, [{ it = VarE (_, actor); _ }]) when actor = "Self" && not(Lib.Promise.is_fulfilled (find actor env.vals)) -> + (* method not defined yet, just pair them up *) + k V.(Tup [Blob (env.self); Text n]) | PrimE (p, es) -> interpret_exps env es [] (fun vs -> match p, vs with @@ -337,8 +340,9 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | ActorDotPrim n, [v1] -> let id = V.as_blob v1 in begin match V.Env.find_opt id !(env.actor_env) with - (* not quite correct: On the platform, you can invoke and get a reject *) - | None -> trap exp.at "Unknown actor \"%s\"" id + | None -> + (* method not defined yet, just pair them up *) + k (assert false;V.Tup [v1; V.Text n]) | Some actor_value -> let fs = V.as_obj actor_value in match V.Env.find_opt n fs with @@ -446,6 +450,14 @@ and interpret_exp_mut env exp (k : V.value V.cont) = let reject = Option.get env.rejects in let e = V.Tup [V.Variant ("canister_reject", V.unit); v1] in Scheduler.queue (fun () -> reject e) + | ICCallPrim, V.[Tup [Blob aid; Text id]; v2; kv; rv; cv] -> + let v1 = V.Env.(find aid !(env.actor_env) |> V.as_obj |> find id) in + let call_conv, f = V.as_func v1 in + check_call_conv (List.hd es) call_conv; + check_call_conv_arg env exp v2 call_conv; + last_region := exp.at; (* in case the following throws *) + let vc = context env in + f (V.Tup[vc; kv; rv; cv]) v2 k | ICCallPrim, [v1; v2; kv; rv; cv] -> let call_conv, f = V.as_func v1 in check_call_conv (List.hd es) call_conv; @@ -575,9 +587,7 @@ and interpret_actor env ds fs k = let env0 = {env with self} in let ve = declare_decs ds V.Env.empty in let env' = adjoin_vals env0 ve in - let increments () = - env'.actor_env := V.Env.add self (defined_fields env' fs) !(env'.actor_env) in - interpret_decs env' ~increments ds (fun _ -> + interpret_decs env' ds (fun _ -> let obj = interpret_fields env' fs in env.actor_env := V.Env.add self obj !(env.actor_env); k (V.Blob self) From b1cd79c49dda4e9c34ec4b7cb33a29b5e0d4c488 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 16:07:40 +0200 Subject: [PATCH 33/67] tweak --- src/mo_interpreter/interpret.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 7aea8110605..e3683702b10 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -574,7 +574,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | CallE (exp1, typs, exp2) -> interpret_exp env exp1 (fun v1 -> let v1 = begin match v1 with - | V.Tup [V.Blob aid; V.Text id] -> + | V.Tup V.[Blob aid; Text id] -> V.Env.(find aid !(env.actor_env) |> V.as_obj |> find id) | _ -> v1 end in From d2e0f1cf49e2e20c617c4600308be665a6bd57da Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 16:07:40 +0200 Subject: [PATCH 34/67] accept --- test/run-drun/incomplete-self-reference.mo | 6 +- .../ok/incomplete-self-reference.diff-ir.ok | 87 ++++++++++++++++++- .../ok/incomplete-self-reference.diff-low.ok | 5 -- .../ok/incomplete-self-reference.run-ir.ok | 85 +++++++++++++++++- .../ok/incomplete-self-reference.run-low.ok | 2 +- 5 files changed, 175 insertions(+), 10 deletions(-) delete mode 100644 test/run-drun/ok/incomplete-self-reference.diff-low.ok diff --git a/test/run-drun/incomplete-self-reference.mo b/test/run-drun/incomplete-self-reference.mo index 267a9376e74..0040fbcef39 100644 --- a/test/run-drun/incomplete-self-reference.mo +++ b/test/run-drun/incomplete-self-reference.mo @@ -3,7 +3,11 @@ import { debugPrint } = "mo:⛔"; actor Self { var stored : shared () -> async () = Self.method; public func method() : async () { debugPrint "Hey!" }; - public func go() : async () { await stored() }; + public func go() : async () { + //assert stored == method; + //assert stored == Self.method; + await stored() + }; }; Self.go(); //OR-CALL ingress go "DIDL\x00\x00" diff --git a/test/run-drun/ok/incomplete-self-reference.diff-ir.ok b/test/run-drun/ok/incomplete-self-reference.diff-ir.ok index 263ad4c98e5..fb4e4ad2256 100644 --- a/test/run-drun/ok/incomplete-self-reference.diff-ir.ok +++ b/test/run-drun/ok/incomplete-self-reference.diff-ir.ok @@ -1,5 +1,88 @@ --- incomplete-self-reference.run +++ incomplete-self-reference.run-ir -@@ -1 +1 @@ +@@ -1 +1,84 @@ -Hey! -+incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition ++incomplete-self-reference.mo:9.21-9.23: internal error, Invalid_argument("Value.as_func") ++ ++Last environment: ++$__motoko_runtime_information = ++$__motoko_stable_var_info = ++$getState/0 = ++$state/0 = null ++@ManagementCanister = {} ++@add_cycles = ++@blob_size = ++@blob_vals = ++@call_error = ++@call_raw = ++@call_succeeded = ++@cancelTimer = ++@cleanup = ++@create_actor_helper = ++@cycles = 0 ++@digits_dec = ++@digits_hex = ++@equal_array = ++@getSystemRefund = ++@ic00 = "" ++@immut_array_get = ++@immut_array_keys = ++@immut_array_size = ++@immut_array_vals = ++@install_actor_helper = ++@int16ToInt = ++@int32ToInt = ++@int64ToInt = ++@int8ToInt = ++@lastTimerId = 0 ++@left_pad = ++@mut_array_get = ++@mut_array_keys = ++@mut_array_put = ++@mut_array_size = ++@mut_array_vals = ++@nat16ToNat = ++@nat32ToNat = ++@nat64ToNat = ++@nat8ToNat = ++@new_async = ++@nextExpiration = ++@prune = ++@refund = 0 ++@reset_cycles = ++@reset_refund = ++@setTimer = ++@set_global_timer = ++@text_chars = ++@text_has_parens = ++@text_needs_parens = ++@text_of_Blob = ++@text_of_Bool = ++@text_of_Char = ++@text_of_Float = ++@text_of_Int = ++@text_of_Int16 = ++@text_of_Int32 = ++@text_of_Int64 = ++@text_of_Int8 = ++@text_of_Nat = ++@text_of_Nat16 = ++@text_of_Nat32 = ++@text_of_Nat64 = ++@text_of_Nat8 = ++@text_of_Text = ++@text_of_array = ++@text_of_array_mut = ++@text_of_num = ++@text_of_option = ++@text_of_variant = ++@text_size = ++@timer_helper = ++@timers = null ++Self = "\49\44\3A\31" ++debugPrint = ++file$@prim = {Array_init = ; Array_tabulate = ; Ret = ; Types = {}; abs = ; arccos = ; arcsin = ; arctan = ; arctan2 = ; arrayMutToBlob = ; arrayToBlob = ; blobCompare = ; blobOfPrincipal = ; blobToArray = ; blobToArrayMut = ; btstInt16 = ; btstInt32 = ; btstInt64 = ; btstInt8 = ; btstNat16 = ; btstNat32 = ; btstNat64 = ; btstNat8 = ; call_raw = ; cancelTimer = ; canisterVersion = ; charIsAlphabetic = ; charIsLowercase = ; charIsUppercase = ; charIsWhitespace = ; charToLower = ; charToNat32 = ; charToText = ; charToUpper = ; clzInt16 = ; clzInt32 = ; clzInt64 = ; clzInt8 = ; clzNat16 = ; clzNat32 = ; clzNat64 = ; clzNat8 = ; cos = ; createActor = ; ctzInt16 = ; ctzInt32 = ; ctzInt64 = ; ctzInt8 = ; ctzNat16 = ; ctzNat32 = ; ctzNat64 = ; ctzNat8 = ; cyclesAccept = ; cyclesAdd = ; cyclesAvailable = ; cyclesBalance = ; cyclesBurn = ; cyclesRefunded = ; debugPrint = ; debugPrintChar = ; debugPrintInt = ; debugPrintNat = ; decodeUtf8 = ; encodeUtf8 = ; error = ; errorCode = ; errorMessage = ; exists = ; exp = ; floatAbs = ; floatCeil = ; floatCopySign = ; floatFloor = ; floatMax = ; floatMin = ; floatNearest = ; floatSqrt = ; floatToFormattedText = ; floatToInt = ; floatToInt64 = ; floatToText = ; floatTrunc = ; forall = ; getCandidLimits = ; getCertificate = ; hashBlob = ; idlHash = ; int16ToInt = ; int16ToInt32 = ; int16ToInt8 = ; int16ToNat16 = ; int32ToInt = ; int32ToInt16 = ; int32ToInt64 = ; int32ToNat32 = ; int64ToFloat = ; int64ToInt = ; int64ToInt32 = ; int64ToNat64 = ; int8ToInt = ; int8ToInt16 = ; int8ToNat8 = ; intToFloat = ; intToInt16 = ; intToInt16Wrap = ; intToInt32 = ; intToInt32Wrap = ; intToInt64 = ; intToInt64Wrap = ; intToInt8 = ; intToInt8Wrap = ; intToNat16Wrap = ; intToNat32Wrap = ; intToNat64Wrap = ; intToNat8Wrap = ; isController = ; log = ; nat16ToInt16 = ; nat16ToNat = ; nat16ToNat32 = ; nat16ToNat8 = ; nat32ToChar = ; nat32ToInt32 = ; nat32ToNat = ; nat32ToNat16 = ; nat32ToNat64 = ; nat64ToInt64 = ; nat64ToNat = ; nat64ToNat32 = ; nat8ToInt8 = ; nat8ToNat = ; nat8ToNat16 = ; natToNat16 = ; natToNat32 = ; natToNat64 = ; natToNat8 = ; performanceCounter = ; popcntInt16 = ; popcntInt32 = ; popcntInt64 = ; popcntInt8 = ; popcntNat16 = ; popcntNat32 = ; popcntNat64 = ; popcntNat8 = ; principalOfActor = ; principalOfBlob = ; regionGrow = ; regionId = ; regionLoadBlob = ; regionLoadFloat = ; regionLoadInt16 = ; regionLoadInt32 = ; regionLoadInt64 = ; regionLoadInt8 = ; regionLoadNat16 = ; regionLoadNat32 = ; regionLoadNat64 = ; regionLoadNat8 = ; regionNew = ; regionSize = ; regionStoreBlob = ; regionStoreFloat = ; regionStoreInt16 = ; regionStoreInt32 = ; regionStoreInt64 = ; regionStoreInt8 = ; regionStoreNat16 = ; regionStoreNat32 = ; regionStoreNat64 = ; regionStoreNat8 = ; rts_callback_table_count = ; rts_callback_table_size = ; rts_collector_instructions = ; rts_heap_size = ; rts_logical_stable_memory_size = ; rts_max_live_size = ; rts_max_stack_size = ; rts_memory_size = ; rts_mutator_instructions = ; rts_reclaimed = ; rts_stable_memory_size = ; rts_total_allocation = ; rts_upgrade_instructions = ; rts_version = ; setCandidLimits = ; setCertifiedData = ; setTimer = ; shiftLeft = ; shiftRight = ; sin = ; stableMemoryGrow = ; stableMemoryLoadBlob = ; stableMemoryLoadFloat = ; stableMemoryLoadInt16 = ; stableMemoryLoadInt32 = ; stableMemoryLoadInt64 = ; stableMemoryLoadInt8 = ; stableMemoryLoadNat16 = ; stableMemoryLoadNat32 = ; stableMemoryLoadNat64 = ; stableMemoryLoadNat8 = ; stableMemorySize = ; stableMemoryStoreBlob = ; stableMemoryStoreFloat = ; stableMemoryStoreInt16 = ; stableMemoryStoreInt32 = ; stableMemoryStoreInt64 = ; stableMemoryStoreInt8 = ; stableMemoryStoreNat16 = ; stableMemoryStoreNat32 = ; stableMemoryStoreNat64 = ; stableMemoryStoreNat8 = ; stableVarQuery = ; tan = ; textCompare = ; textLowercase = ; textUppercase = ; time = ; trap = } ++go = ++method = ++stored = ("\49\44\3A\31", "method") ++ diff --git a/test/run-drun/ok/incomplete-self-reference.diff-low.ok b/test/run-drun/ok/incomplete-self-reference.diff-low.ok deleted file mode 100644 index 3f0319de918..00000000000 --- a/test/run-drun/ok/incomplete-self-reference.diff-low.ok +++ /dev/null @@ -1,5 +0,0 @@ ---- incomplete-self-reference.run -+++ incomplete-self-reference.run-low -@@ -1 +1 @@ --Hey! -+incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition diff --git a/test/run-drun/ok/incomplete-self-reference.run-ir.ok b/test/run-drun/ok/incomplete-self-reference.run-ir.ok index 97152c4a52d..c60476960a6 100644 --- a/test/run-drun/ok/incomplete-self-reference.run-ir.ok +++ b/test/run-drun/ok/incomplete-self-reference.run-ir.ok @@ -1 +1,84 @@ -incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition +incomplete-self-reference.mo:9.21-9.23: internal error, Invalid_argument("Value.as_func") + +Last environment: +$__motoko_runtime_information = +$__motoko_stable_var_info = +$getState/0 = +$state/0 = null +@ManagementCanister = {} +@add_cycles = +@blob_size = +@blob_vals = +@call_error = +@call_raw = +@call_succeeded = +@cancelTimer = +@cleanup = +@create_actor_helper = +@cycles = 0 +@digits_dec = +@digits_hex = +@equal_array = +@getSystemRefund = +@ic00 = "" +@immut_array_get = +@immut_array_keys = +@immut_array_size = +@immut_array_vals = +@install_actor_helper = +@int16ToInt = +@int32ToInt = +@int64ToInt = +@int8ToInt = +@lastTimerId = 0 +@left_pad = +@mut_array_get = +@mut_array_keys = +@mut_array_put = +@mut_array_size = +@mut_array_vals = +@nat16ToNat = +@nat32ToNat = +@nat64ToNat = +@nat8ToNat = +@new_async = +@nextExpiration = +@prune = +@refund = 0 +@reset_cycles = +@reset_refund = +@setTimer = +@set_global_timer = +@text_chars = +@text_has_parens = +@text_needs_parens = +@text_of_Blob = +@text_of_Bool = +@text_of_Char = +@text_of_Float = +@text_of_Int = +@text_of_Int16 = +@text_of_Int32 = +@text_of_Int64 = +@text_of_Int8 = +@text_of_Nat = +@text_of_Nat16 = +@text_of_Nat32 = +@text_of_Nat64 = +@text_of_Nat8 = +@text_of_Text = +@text_of_array = +@text_of_array_mut = +@text_of_num = +@text_of_option = +@text_of_variant = +@text_size = +@timer_helper = +@timers = null +Self = "\49\44\3A\31" +debugPrint = +file$@prim = {Array_init = ; Array_tabulate = ; Ret = ; Types = {}; abs = ; arccos = ; arcsin = ; arctan = ; arctan2 = ; arrayMutToBlob = ; arrayToBlob = ; blobCompare = ; blobOfPrincipal = ; blobToArray = ; blobToArrayMut = ; btstInt16 = ; btstInt32 = ; btstInt64 = ; btstInt8 = ; btstNat16 = ; btstNat32 = ; btstNat64 = ; btstNat8 = ; call_raw = ; cancelTimer = ; canisterVersion = ; charIsAlphabetic = ; charIsLowercase = ; charIsUppercase = ; charIsWhitespace = ; charToLower = ; charToNat32 = ; charToText = ; charToUpper = ; clzInt16 = ; clzInt32 = ; clzInt64 = ; clzInt8 = ; clzNat16 = ; clzNat32 = ; clzNat64 = ; clzNat8 = ; cos = ; createActor = ; ctzInt16 = ; ctzInt32 = ; ctzInt64 = ; ctzInt8 = ; ctzNat16 = ; ctzNat32 = ; ctzNat64 = ; ctzNat8 = ; cyclesAccept = ; cyclesAdd = ; cyclesAvailable = ; cyclesBalance = ; cyclesBurn = ; cyclesRefunded = ; debugPrint = ; debugPrintChar = ; debugPrintInt = ; debugPrintNat = ; decodeUtf8 = ; encodeUtf8 = ; error = ; errorCode = ; errorMessage = ; exists = ; exp = ; floatAbs = ; floatCeil = ; floatCopySign = ; floatFloor = ; floatMax = ; floatMin = ; floatNearest = ; floatSqrt = ; floatToFormattedText = ; floatToInt = ; floatToInt64 = ; floatToText = ; floatTrunc = ; forall = ; getCandidLimits = ; getCertificate = ; hashBlob = ; idlHash = ; int16ToInt = ; int16ToInt32 = ; int16ToInt8 = ; int16ToNat16 = ; int32ToInt = ; int32ToInt16 = ; int32ToInt64 = ; int32ToNat32 = ; int64ToFloat = ; int64ToInt = ; int64ToInt32 = ; int64ToNat64 = ; int8ToInt = ; int8ToInt16 = ; int8ToNat8 = ; intToFloat = ; intToInt16 = ; intToInt16Wrap = ; intToInt32 = ; intToInt32Wrap = ; intToInt64 = ; intToInt64Wrap = ; intToInt8 = ; intToInt8Wrap = ; intToNat16Wrap = ; intToNat32Wrap = ; intToNat64Wrap = ; intToNat8Wrap = ; isController = ; log = ; nat16ToInt16 = ; nat16ToNat = ; nat16ToNat32 = ; nat16ToNat8 = ; nat32ToChar = ; nat32ToInt32 = ; nat32ToNat = ; nat32ToNat16 = ; nat32ToNat64 = ; nat64ToInt64 = ; nat64ToNat = ; nat64ToNat32 = ; nat8ToInt8 = ; nat8ToNat = ; nat8ToNat16 = ; natToNat16 = ; natToNat32 = ; natToNat64 = ; natToNat8 = ; performanceCounter = ; popcntInt16 = ; popcntInt32 = ; popcntInt64 = ; popcntInt8 = ; popcntNat16 = ; popcntNat32 = ; popcntNat64 = ; popcntNat8 = ; principalOfActor = ; principalOfBlob = ; regionGrow = ; regionId = ; regionLoadBlob = ; regionLoadFloat = ; regionLoadInt16 = ; regionLoadInt32 = ; regionLoadInt64 = ; regionLoadInt8 = ; regionLoadNat16 = ; regionLoadNat32 = ; regionLoadNat64 = ; regionLoadNat8 = ; regionNew = ; regionSize = ; regionStoreBlob = ; regionStoreFloat = ; regionStoreInt16 = ; regionStoreInt32 = ; regionStoreInt64 = ; regionStoreInt8 = ; regionStoreNat16 = ; regionStoreNat32 = ; regionStoreNat64 = ; regionStoreNat8 = ; rts_callback_table_count = ; rts_callback_table_size = ; rts_collector_instructions = ; rts_heap_size = ; rts_logical_stable_memory_size = ; rts_max_live_size = ; rts_max_stack_size = ; rts_memory_size = ; rts_mutator_instructions = ; rts_reclaimed = ; rts_stable_memory_size = ; rts_total_allocation = ; rts_upgrade_instructions = ; rts_version = ; setCandidLimits = ; setCertifiedData = ; setTimer = ; shiftLeft = ; shiftRight = ; sin = ; stableMemoryGrow = ; stableMemoryLoadBlob = ; stableMemoryLoadFloat = ; stableMemoryLoadInt16 = ; stableMemoryLoadInt32 = ; stableMemoryLoadInt64 = ; stableMemoryLoadInt8 = ; stableMemoryLoadNat16 = ; stableMemoryLoadNat32 = ; stableMemoryLoadNat64 = ; stableMemoryLoadNat8 = ; stableMemorySize = ; stableMemoryStoreBlob = ; stableMemoryStoreFloat = ; stableMemoryStoreInt16 = ; stableMemoryStoreInt32 = ; stableMemoryStoreInt64 = ; stableMemoryStoreInt8 = ; stableMemoryStoreNat16 = ; stableMemoryStoreNat32 = ; stableMemoryStoreNat64 = ; stableMemoryStoreNat8 = ; stableVarQuery = ; tan = ; textCompare = ; textLowercase = ; textUppercase = ; time = ; trap = } +go = +method = +stored = ("\49\44\3A\31", "method") + diff --git a/test/run-drun/ok/incomplete-self-reference.run-low.ok b/test/run-drun/ok/incomplete-self-reference.run-low.ok index 97152c4a52d..4c5477a837a 100644 --- a/test/run-drun/ok/incomplete-self-reference.run-low.ok +++ b/test/run-drun/ok/incomplete-self-reference.run-low.ok @@ -1 +1 @@ -incomplete-self-reference.mo:4.42-4.46: execution error, accessing identifier before its definition +Hey! From 431900aac976d02269c784be3910ce66c891bc71 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 17:12:26 +0200 Subject: [PATCH 35/67] progress --- src/ir_interpreter/interpret_ir.ml | 6 ++++-- test/run-drun/ok/incomplete-self-reference.diff-low.ok | 6 ++++++ test/run-drun/ok/incomplete-self-reference.run-low.ok | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/run-drun/ok/incomplete-self-reference.diff-low.ok diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 939ce6c15a9..fb1863d6a18 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -307,7 +307,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = ) | LitE lit -> k (interpret_lit env lit) - | PrimE (ActorDotPrim n, [{ it = VarE (_, actor); _ }]) when actor = "Self" && not(Lib.Promise.is_fulfilled (find actor env.vals)) -> + | PrimE (ActorDotPrim n, [{ it = VarE (_, actor); _ }]) when not(Lib.Promise.is_fulfilled (find actor env.vals)) -> (* method not defined yet, just pair them up *) k V.(Tup [Blob (env.self); Text n]) | PrimE (p, es) -> @@ -459,8 +459,10 @@ and interpret_exp_mut env exp (k : V.value V.cont) = let vc = context env in f (V.Tup[vc; kv; rv; cv]) v2 k | ICCallPrim, [v1; v2; kv; rv; cv] -> + Printf.eprintf "ICCallPrim0\n"; let call_conv, f = V.as_func v1 in - check_call_conv (List.hd es) call_conv; + Printf.eprintf "ICCallPrim1\n"; + check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; last_region := exp.at; (* in case the following throws *) let vc = context env in diff --git a/test/run-drun/ok/incomplete-self-reference.diff-low.ok b/test/run-drun/ok/incomplete-self-reference.diff-low.ok new file mode 100644 index 00000000000..04ff4de8418 --- /dev/null +++ b/test/run-drun/ok/incomplete-self-reference.diff-low.ok @@ -0,0 +1,6 @@ +--- incomplete-self-reference.run ++++ incomplete-self-reference.run-low +@@ -1 +1,3 @@ + Hey! ++ICCallPrim0 ++ICCallPrim1 diff --git a/test/run-drun/ok/incomplete-self-reference.run-low.ok b/test/run-drun/ok/incomplete-self-reference.run-low.ok index 4c5477a837a..339f2402347 100644 --- a/test/run-drun/ok/incomplete-self-reference.run-low.ok +++ b/test/run-drun/ok/incomplete-self-reference.run-low.ok @@ -1 +1,3 @@ Hey! +ICCallPrim0 +ICCallPrim1 From 0ae91a8f918b26433a537ff5d9627efb2bdd39d0 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 17:32:24 +0200 Subject: [PATCH 36/67] fix the plain IR-interpreter --- src/ir_interpreter/interpret_ir.ml | 7 +- .../ok/incomplete-self-reference.diff-ir.ok | 88 ------------------- .../ok/incomplete-self-reference.diff-low.ok | 6 -- .../ok/incomplete-self-reference.run-ir.ok | 85 +----------------- .../ok/incomplete-self-reference.run-low.ok | 2 - 5 files changed, 6 insertions(+), 182 deletions(-) delete mode 100644 test/run-drun/ok/incomplete-self-reference.diff-ir.ok delete mode 100644 test/run-drun/ok/incomplete-self-reference.diff-low.ok diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index fb1863d6a18..237bc72efaa 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -314,6 +314,11 @@ and interpret_exp_mut env exp (k : V.value V.cont) = interpret_exps env es [] (fun vs -> match p, vs with | CallPrim typs, [v1; v2] -> + let v1 = begin match v1 with + | V.Tup V.[Blob aid; Text id] -> + V.Env.(find aid !(env.actor_env) |> V.as_obj |> find id) + | _ -> v1 + end in let call_conv, f = V.as_func v1 in check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; @@ -459,9 +464,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = let vc = context env in f (V.Tup[vc; kv; rv; cv]) v2 k | ICCallPrim, [v1; v2; kv; rv; cv] -> - Printf.eprintf "ICCallPrim0\n"; let call_conv, f = V.as_func v1 in - Printf.eprintf "ICCallPrim1\n"; check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; last_region := exp.at; (* in case the following throws *) diff --git a/test/run-drun/ok/incomplete-self-reference.diff-ir.ok b/test/run-drun/ok/incomplete-self-reference.diff-ir.ok deleted file mode 100644 index fb4e4ad2256..00000000000 --- a/test/run-drun/ok/incomplete-self-reference.diff-ir.ok +++ /dev/null @@ -1,88 +0,0 @@ ---- incomplete-self-reference.run -+++ incomplete-self-reference.run-ir -@@ -1 +1,84 @@ --Hey! -+incomplete-self-reference.mo:9.21-9.23: internal error, Invalid_argument("Value.as_func") -+ -+Last environment: -+$__motoko_runtime_information = -+$__motoko_stable_var_info = -+$getState/0 = -+$state/0 = null -+@ManagementCanister = {} -+@add_cycles = -+@blob_size = -+@blob_vals = -+@call_error = -+@call_raw = -+@call_succeeded = -+@cancelTimer = -+@cleanup = -+@create_actor_helper = -+@cycles = 0 -+@digits_dec = -+@digits_hex = -+@equal_array = -+@getSystemRefund = -+@ic00 = "" -+@immut_array_get = -+@immut_array_keys = -+@immut_array_size = -+@immut_array_vals = -+@install_actor_helper = -+@int16ToInt = -+@int32ToInt = -+@int64ToInt = -+@int8ToInt = -+@lastTimerId = 0 -+@left_pad = -+@mut_array_get = -+@mut_array_keys = -+@mut_array_put = -+@mut_array_size = -+@mut_array_vals = -+@nat16ToNat = -+@nat32ToNat = -+@nat64ToNat = -+@nat8ToNat = -+@new_async = -+@nextExpiration = -+@prune = -+@refund = 0 -+@reset_cycles = -+@reset_refund = -+@setTimer = -+@set_global_timer = -+@text_chars = -+@text_has_parens = -+@text_needs_parens = -+@text_of_Blob = -+@text_of_Bool = -+@text_of_Char = -+@text_of_Float = -+@text_of_Int = -+@text_of_Int16 = -+@text_of_Int32 = -+@text_of_Int64 = -+@text_of_Int8 = -+@text_of_Nat = -+@text_of_Nat16 = -+@text_of_Nat32 = -+@text_of_Nat64 = -+@text_of_Nat8 = -+@text_of_Text = -+@text_of_array = -+@text_of_array_mut = -+@text_of_num = -+@text_of_option = -+@text_of_variant = -+@text_size = -+@timer_helper = -+@timers = null -+Self = "\49\44\3A\31" -+debugPrint = -+file$@prim = {Array_init = ; Array_tabulate = ; Ret = ; Types = {}; abs = ; arccos = ; arcsin = ; arctan = ; arctan2 = ; arrayMutToBlob = ; arrayToBlob = ; blobCompare = ; blobOfPrincipal = ; blobToArray = ; blobToArrayMut = ; btstInt16 = ; btstInt32 = ; btstInt64 = ; btstInt8 = ; btstNat16 = ; btstNat32 = ; btstNat64 = ; btstNat8 = ; call_raw = ; cancelTimer = ; canisterVersion = ; charIsAlphabetic = ; charIsLowercase = ; charIsUppercase = ; charIsWhitespace = ; charToLower = ; charToNat32 = ; charToText = ; charToUpper = ; clzInt16 = ; clzInt32 = ; clzInt64 = ; clzInt8 = ; clzNat16 = ; clzNat32 = ; clzNat64 = ; clzNat8 = ; cos = ; createActor = ; ctzInt16 = ; ctzInt32 = ; ctzInt64 = ; ctzInt8 = ; ctzNat16 = ; ctzNat32 = ; ctzNat64 = ; ctzNat8 = ; cyclesAccept = ; cyclesAdd = ; cyclesAvailable = ; cyclesBalance = ; cyclesBurn = ; cyclesRefunded = ; debugPrint = ; debugPrintChar = ; debugPrintInt = ; debugPrintNat = ; decodeUtf8 = ; encodeUtf8 = ; error = ; errorCode = ; errorMessage = ; exists = ; exp = ; floatAbs = ; floatCeil = ; floatCopySign = ; floatFloor = ; floatMax = ; floatMin = ; floatNearest = ; floatSqrt = ; floatToFormattedText = ; floatToInt = ; floatToInt64 = ; floatToText = ; floatTrunc = ; forall = ; getCandidLimits = ; getCertificate = ; hashBlob = ; idlHash = ; int16ToInt = ; int16ToInt32 = ; int16ToInt8 = ; int16ToNat16 = ; int32ToInt = ; int32ToInt16 = ; int32ToInt64 = ; int32ToNat32 = ; int64ToFloat = ; int64ToInt = ; int64ToInt32 = ; int64ToNat64 = ; int8ToInt = ; int8ToInt16 = ; int8ToNat8 = ; intToFloat = ; intToInt16 = ; intToInt16Wrap = ; intToInt32 = ; intToInt32Wrap = ; intToInt64 = ; intToInt64Wrap = ; intToInt8 = ; intToInt8Wrap = ; intToNat16Wrap = ; intToNat32Wrap = ; intToNat64Wrap = ; intToNat8Wrap = ; isController = ; log = ; nat16ToInt16 = ; nat16ToNat = ; nat16ToNat32 = ; nat16ToNat8 = ; nat32ToChar = ; nat32ToInt32 = ; nat32ToNat = ; nat32ToNat16 = ; nat32ToNat64 = ; nat64ToInt64 = ; nat64ToNat = ; nat64ToNat32 = ; nat8ToInt8 = ; nat8ToNat = ; nat8ToNat16 = ; natToNat16 = ; natToNat32 = ; natToNat64 = ; natToNat8 = ; performanceCounter = ; popcntInt16 = ; popcntInt32 = ; popcntInt64 = ; popcntInt8 = ; popcntNat16 = ; popcntNat32 = ; popcntNat64 = ; popcntNat8 = ; principalOfActor = ; principalOfBlob = ; regionGrow = ; regionId = ; regionLoadBlob = ; regionLoadFloat = ; regionLoadInt16 = ; regionLoadInt32 = ; regionLoadInt64 = ; regionLoadInt8 = ; regionLoadNat16 = ; regionLoadNat32 = ; regionLoadNat64 = ; regionLoadNat8 = ; regionNew = ; regionSize = ; regionStoreBlob = ; regionStoreFloat = ; regionStoreInt16 = ; regionStoreInt32 = ; regionStoreInt64 = ; regionStoreInt8 = ; regionStoreNat16 = ; regionStoreNat32 = ; regionStoreNat64 = ; regionStoreNat8 = ; rts_callback_table_count = ; rts_callback_table_size = ; rts_collector_instructions = ; rts_heap_size = ; rts_logical_stable_memory_size = ; rts_max_live_size = ; rts_max_stack_size = ; rts_memory_size = ; rts_mutator_instructions = ; rts_reclaimed = ; rts_stable_memory_size = ; rts_total_allocation = ; rts_upgrade_instructions = ; rts_version = ; setCandidLimits = ; setCertifiedData = ; setTimer = ; shiftLeft = ; shiftRight = ; sin = ; stableMemoryGrow = ; stableMemoryLoadBlob = ; stableMemoryLoadFloat = ; stableMemoryLoadInt16 = ; stableMemoryLoadInt32 = ; stableMemoryLoadInt64 = ; stableMemoryLoadInt8 = ; stableMemoryLoadNat16 = ; stableMemoryLoadNat32 = ; stableMemoryLoadNat64 = ; stableMemoryLoadNat8 = ; stableMemorySize = ; stableMemoryStoreBlob = ; stableMemoryStoreFloat = ; stableMemoryStoreInt16 = ; stableMemoryStoreInt32 = ; stableMemoryStoreInt64 = ; stableMemoryStoreInt8 = ; stableMemoryStoreNat16 = ; stableMemoryStoreNat32 = ; stableMemoryStoreNat64 = ; stableMemoryStoreNat8 = ; stableVarQuery = ; tan = ; textCompare = ; textLowercase = ; textUppercase = ; time = ; trap = } -+go = -+method = -+stored = ("\49\44\3A\31", "method") -+ diff --git a/test/run-drun/ok/incomplete-self-reference.diff-low.ok b/test/run-drun/ok/incomplete-self-reference.diff-low.ok deleted file mode 100644 index 04ff4de8418..00000000000 --- a/test/run-drun/ok/incomplete-self-reference.diff-low.ok +++ /dev/null @@ -1,6 +0,0 @@ ---- incomplete-self-reference.run -+++ incomplete-self-reference.run-low -@@ -1 +1,3 @@ - Hey! -+ICCallPrim0 -+ICCallPrim1 diff --git a/test/run-drun/ok/incomplete-self-reference.run-ir.ok b/test/run-drun/ok/incomplete-self-reference.run-ir.ok index c60476960a6..4c5477a837a 100644 --- a/test/run-drun/ok/incomplete-self-reference.run-ir.ok +++ b/test/run-drun/ok/incomplete-self-reference.run-ir.ok @@ -1,84 +1 @@ -incomplete-self-reference.mo:9.21-9.23: internal error, Invalid_argument("Value.as_func") - -Last environment: -$__motoko_runtime_information = -$__motoko_stable_var_info = -$getState/0 = -$state/0 = null -@ManagementCanister = {} -@add_cycles = -@blob_size = -@blob_vals = -@call_error = -@call_raw = -@call_succeeded = -@cancelTimer = -@cleanup = -@create_actor_helper = -@cycles = 0 -@digits_dec = -@digits_hex = -@equal_array = -@getSystemRefund = -@ic00 = "" -@immut_array_get = -@immut_array_keys = -@immut_array_size = -@immut_array_vals = -@install_actor_helper = -@int16ToInt = -@int32ToInt = -@int64ToInt = -@int8ToInt = -@lastTimerId = 0 -@left_pad = -@mut_array_get = -@mut_array_keys = -@mut_array_put = -@mut_array_size = -@mut_array_vals = -@nat16ToNat = -@nat32ToNat = -@nat64ToNat = -@nat8ToNat = -@new_async = -@nextExpiration = -@prune = -@refund = 0 -@reset_cycles = -@reset_refund = -@setTimer = -@set_global_timer = -@text_chars = -@text_has_parens = -@text_needs_parens = -@text_of_Blob = -@text_of_Bool = -@text_of_Char = -@text_of_Float = -@text_of_Int = -@text_of_Int16 = -@text_of_Int32 = -@text_of_Int64 = -@text_of_Int8 = -@text_of_Nat = -@text_of_Nat16 = -@text_of_Nat32 = -@text_of_Nat64 = -@text_of_Nat8 = -@text_of_Text = -@text_of_array = -@text_of_array_mut = -@text_of_num = -@text_of_option = -@text_of_variant = -@text_size = -@timer_helper = -@timers = null -Self = "\49\44\3A\31" -debugPrint = -file$@prim = {Array_init = ; Array_tabulate = ; Ret = ; Types = {}; abs = ; arccos = ; arcsin = ; arctan = ; arctan2 = ; arrayMutToBlob = ; arrayToBlob = ; blobCompare = ; blobOfPrincipal = ; blobToArray = ; blobToArrayMut = ; btstInt16 = ; btstInt32 = ; btstInt64 = ; btstInt8 = ; btstNat16 = ; btstNat32 = ; btstNat64 = ; btstNat8 = ; call_raw = ; cancelTimer = ; canisterVersion = ; charIsAlphabetic = ; charIsLowercase = ; charIsUppercase = ; charIsWhitespace = ; charToLower = ; charToNat32 = ; charToText = ; charToUpper = ; clzInt16 = ; clzInt32 = ; clzInt64 = ; clzInt8 = ; clzNat16 = ; clzNat32 = ; clzNat64 = ; clzNat8 = ; cos = ; createActor = ; ctzInt16 = ; ctzInt32 = ; ctzInt64 = ; ctzInt8 = ; ctzNat16 = ; ctzNat32 = ; ctzNat64 = ; ctzNat8 = ; cyclesAccept = ; cyclesAdd = ; cyclesAvailable = ; cyclesBalance = ; cyclesBurn = ; cyclesRefunded = ; debugPrint = ; debugPrintChar = ; debugPrintInt = ; debugPrintNat = ; decodeUtf8 = ; encodeUtf8 = ; error = ; errorCode = ; errorMessage = ; exists = ; exp = ; floatAbs = ; floatCeil = ; floatCopySign = ; floatFloor = ; floatMax = ; floatMin = ; floatNearest = ; floatSqrt = ; floatToFormattedText = ; floatToInt = ; floatToInt64 = ; floatToText = ; floatTrunc = ; forall = ; getCandidLimits = ; getCertificate = ; hashBlob = ; idlHash = ; int16ToInt = ; int16ToInt32 = ; int16ToInt8 = ; int16ToNat16 = ; int32ToInt = ; int32ToInt16 = ; int32ToInt64 = ; int32ToNat32 = ; int64ToFloat = ; int64ToInt = ; int64ToInt32 = ; int64ToNat64 = ; int8ToInt = ; int8ToInt16 = ; int8ToNat8 = ; intToFloat = ; intToInt16 = ; intToInt16Wrap = ; intToInt32 = ; intToInt32Wrap = ; intToInt64 = ; intToInt64Wrap = ; intToInt8 = ; intToInt8Wrap = ; intToNat16Wrap = ; intToNat32Wrap = ; intToNat64Wrap = ; intToNat8Wrap = ; isController = ; log = ; nat16ToInt16 = ; nat16ToNat = ; nat16ToNat32 = ; nat16ToNat8 = ; nat32ToChar = ; nat32ToInt32 = ; nat32ToNat = ; nat32ToNat16 = ; nat32ToNat64 = ; nat64ToInt64 = ; nat64ToNat = ; nat64ToNat32 = ; nat8ToInt8 = ; nat8ToNat = ; nat8ToNat16 = ; natToNat16 = ; natToNat32 = ; natToNat64 = ; natToNat8 = ; performanceCounter = ; popcntInt16 = ; popcntInt32 = ; popcntInt64 = ; popcntInt8 = ; popcntNat16 = ; popcntNat32 = ; popcntNat64 = ; popcntNat8 = ; principalOfActor = ; principalOfBlob = ; regionGrow = ; regionId = ; regionLoadBlob = ; regionLoadFloat = ; regionLoadInt16 = ; regionLoadInt32 = ; regionLoadInt64 = ; regionLoadInt8 = ; regionLoadNat16 = ; regionLoadNat32 = ; regionLoadNat64 = ; regionLoadNat8 = ; regionNew = ; regionSize = ; regionStoreBlob = ; regionStoreFloat = ; regionStoreInt16 = ; regionStoreInt32 = ; regionStoreInt64 = ; regionStoreInt8 = ; regionStoreNat16 = ; regionStoreNat32 = ; regionStoreNat64 = ; regionStoreNat8 = ; rts_callback_table_count = ; rts_callback_table_size = ; rts_collector_instructions = ; rts_heap_size = ; rts_logical_stable_memory_size = ; rts_max_live_size = ; rts_max_stack_size = ; rts_memory_size = ; rts_mutator_instructions = ; rts_reclaimed = ; rts_stable_memory_size = ; rts_total_allocation = ; rts_upgrade_instructions = ; rts_version = ; setCandidLimits = ; setCertifiedData = ; setTimer = ; shiftLeft = ; shiftRight = ; sin = ; stableMemoryGrow = ; stableMemoryLoadBlob = ; stableMemoryLoadFloat = ; stableMemoryLoadInt16 = ; stableMemoryLoadInt32 = ; stableMemoryLoadInt64 = ; stableMemoryLoadInt8 = ; stableMemoryLoadNat16 = ; stableMemoryLoadNat32 = ; stableMemoryLoadNat64 = ; stableMemoryLoadNat8 = ; stableMemorySize = ; stableMemoryStoreBlob = ; stableMemoryStoreFloat = ; stableMemoryStoreInt16 = ; stableMemoryStoreInt32 = ; stableMemoryStoreInt64 = ; stableMemoryStoreInt8 = ; stableMemoryStoreNat16 = ; stableMemoryStoreNat32 = ; stableMemoryStoreNat64 = ; stableMemoryStoreNat8 = ; stableVarQuery = ; tan = ; textCompare = ; textLowercase = ; textUppercase = ; time = ; trap = } -go = -method = -stored = ("\49\44\3A\31", "method") - +Hey! diff --git a/test/run-drun/ok/incomplete-self-reference.run-low.ok b/test/run-drun/ok/incomplete-self-reference.run-low.ok index 339f2402347..4c5477a837a 100644 --- a/test/run-drun/ok/incomplete-self-reference.run-low.ok +++ b/test/run-drun/ok/incomplete-self-reference.run-low.ok @@ -1,3 +1 @@ Hey! -ICCallPrim0 -ICCallPrim1 From f605a4516c058a08b6bdd6264fc82b223b60207f Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 21:38:33 +0200 Subject: [PATCH 37/67] remove warnings --- src/ir_interpreter/interpret_ir.ml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 237bc72efaa..da540b02789 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -347,7 +347,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = begin match V.Env.find_opt id !(env.actor_env) with | None -> (* method not defined yet, just pair them up *) - k (assert false;V.Tup [v1; V.Text n]) + k (assert (1 = 2);V.Tup [v1; V.Text n]) | Some actor_value -> let fs = V.as_obj actor_value in match V.Env.find_opt n fs with @@ -621,17 +621,6 @@ and interpret_lexp env lexp (k : (V.value ref) V.cont) = ) ) -and defined_fields env fs = - let ve = - List.fold_left - (fun ve (f : field) -> - match V.Env.find_opt f.it.var env.vals with - | Some binding when Lib.Promise.is_fulfilled binding - -> V.Env.disjoint_add f.it.name (Lib.Promise.value binding) ve - | _ -> ve - ) V.Env.empty fs in - V.Obj ve - and interpret_fields env fs = let ve = List.fold_left From 879fc73437d4ec2b89b17815dce6be377cbf3446 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 8 Oct 2024 22:49:38 +0200 Subject: [PATCH 38/67] fix --- src/ir_interpreter/interpret_ir.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index da540b02789..5b870eb6361 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -308,7 +308,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | LitE lit -> k (interpret_lit env lit) | PrimE (ActorDotPrim n, [{ it = VarE (_, actor); _ }]) when not(Lib.Promise.is_fulfilled (find actor env.vals)) -> - (* method not defined yet, just pair them up *) + (* actor not defined yet, just pair them up *) k V.(Tup [Blob (env.self); Text n]) | PrimE (p, es) -> interpret_exps env es [] (fun vs -> @@ -347,7 +347,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = begin match V.Env.find_opt id !(env.actor_env) with | None -> (* method not defined yet, just pair them up *) - k (assert (1 = 2);V.Tup [v1; V.Text n]) + k V.(Tup [v1; Text n]) | Some actor_value -> let fs = V.as_obj actor_value in match V.Env.find_opt n fs with From df56bd94c1c3d74e1417ab57c9f3f6d58502bfff Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 12:25:39 +0200 Subject: [PATCH 39/67] simplify --- src/mo_interpreter/interpret.ml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index e3683702b10..50bec4af02c 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -900,18 +900,15 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in (* Define self_id in inner scope if there is a non-shadowing way to do it *) - let env', increments = + let env' = if match self_id with | None -> false | Some self -> V.Env.mem self.it ve_in - then env', ignore (* would shadow *) + then env' (* would shadow *) else begin let env' = match self_id with | Some self -> adjoin_vals env' (declare_id self) | _ -> env' in Option.iter (fun id -> define_id env' id self') self_id; - let increments () = - let fulfilled = V.Env.filter (fun _ -> Lib.Promise.is_fulfilled) ve_ex in - env.actor_env := V.Env.add self V.(Obj (Env.map Lib.Promise.value fulfilled)) !(env.actor_env) in - env', increments + env' end in interpret_dec_fields env' dec_fields ve_ex @@ -932,13 +929,13 @@ and declare_dec_fields dec_fields ve_ex ve_in : val_env * val_env = let ve_in' = V.Env.adjoin ve_in ve' in declare_dec_fields dec_fields' ve_ex' ve_in' -and interpret_dec_fields env ?(increments=ignore) dec_fields ve (k : V.value V.cont) = +and interpret_dec_fields env dec_fields ve (k : V.value V.cont) = match dec_fields with | [] -> let obj = V.Obj (V.Env.map Lib.Promise.value ve) in k obj | {it = {dec; _}; _}::dec_fields' -> - interpret_dec env dec (fun _v -> increments (); interpret_dec_fields env ~increments dec_fields' ve k) + interpret_dec env dec (fun _v -> interpret_dec_fields env dec_fields' ve k) (* Blocks and Declarations *) From a0e613b68a5c3b4e3d8c8ee7212cd25f6fdfa057 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 12:27:02 +0200 Subject: [PATCH 40/67] simplify --- src/ir_interpreter/interpret_ir.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 5b870eb6361..114049db472 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -817,10 +817,10 @@ and interpret_dec env dec k = k () ) -and interpret_decs env ?(increments=ignore) decs (k : unit V.cont) = +and interpret_decs env decs (k : unit V.cont) = match decs with | [] -> k () - | d::ds -> interpret_dec env d (fun () -> increments (); interpret_decs env ~increments ds k) + | d::ds -> interpret_dec env d (fun () -> interpret_decs env ds k) and interpret_func env at sort x args f c v (k : V.value V.cont) = if env.flags.trace then trace "%s%s" x (string_of_arg env v); From 88023fca27375ee6f7e27f7e244d8e1913859004 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 12:35:14 +0200 Subject: [PATCH 41/67] Update src/ir_interpreter/interpret_ir.ml Co-authored-by: Claudio Russo --- src/ir_interpreter/interpret_ir.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 114049db472..7d7ff93285b 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -465,7 +465,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = f (V.Tup[vc; kv; rv; cv]) v2 k | ICCallPrim, [v1; v2; kv; rv; cv] -> let call_conv, f = V.as_func v1 in - check_call_conv (List.hd es) call_conv; + check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; last_region := exp.at; (* in case the following throws *) let vc = context env in From 76d3d1a641d7f1b62500110a3db2f3d935baa944 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 13:47:50 +0200 Subject: [PATCH 42/67] simplify --- src/ir_interpreter/interpret_ir.ml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 7d7ff93285b..d0d6a6792b9 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -343,17 +343,8 @@ and interpret_exp_mut env exp (k : V.value V.cont) = let fs = V.as_obj v1 in k (try find n fs with _ -> assert false) | ActorDotPrim n, [v1] -> - let id = V.as_blob v1 in - begin match V.Env.find_opt id !(env.actor_env) with - | None -> - (* method not defined yet, just pair them up *) - k V.(Tup [v1; Text n]) - | Some actor_value -> - let fs = V.as_obj actor_value in - match V.Env.find_opt n fs with - | None -> trap exp.at "Actor \"%s\" has no method \"%s\"" id n - | Some field_value -> k field_value - end + (* delay error handling to the point when the method gets applied *) + k V.(Tup [v1; Text n]) | ArrayPrim (mut, _), vs -> let vs' = match mut with From 54bb508e48a3b5ee9322040f5d191ef749dc57b7 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 15:12:52 +0200 Subject: [PATCH 43/67] simplify for `DotE` and leave actor/method checking to application this is review feedback --- src/mo_interpreter/interpret.ml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 50bec4af02c..154004b0804 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -503,22 +503,13 @@ and interpret_exp_mut env exp (k : V.value V.cont) = interpret_exps env exp_bases [] (fun objs -> fields (merges (strip objs))) | TagE (i, exp1) -> interpret_exp env exp1 (fun v1 -> k (V.Variant (i.it, v1))) + | DotE (exp1, id) when T.(sub exp1.note.note_typ (Obj (Actor, []))) -> + interpret_exp env exp1 (fun v1 -> k V.(Tup [v1; Text id.it])) | DotE (exp1, id) -> interpret_exp env exp1 (fun v1 -> match v1 with | V.Obj fs -> k (find id.it fs) - | V.Blob aid as actor when T.sub exp1.note.note_typ (T.Obj (T.Actor, [])) -> - begin match V.Env.find_opt aid !(env.actor_env) with - | None -> - (* method not defined yet, just pair them up *) - k V.(Tup [actor; Text id.it]) - | Some actor_value -> - let fs = V.as_obj actor_value in - match V.Env.find_opt id.it fs with - | None -> trap exp.at "Actor \"%s\" has no method \"%s\"" aid id.it - | Some field_value -> k field_value - end | V.Array vs -> let f = match id.it with | "size" -> array_size From 6ce2cebd8dd4020426d8f7552895af5ab24d054b Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 16:36:05 +0200 Subject: [PATCH 44/67] some comparisons work already --- test/run-drun/incomplete-self-reference.mo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/run-drun/incomplete-self-reference.mo b/test/run-drun/incomplete-self-reference.mo index 0040fbcef39..7a083870bbe 100644 --- a/test/run-drun/incomplete-self-reference.mo +++ b/test/run-drun/incomplete-self-reference.mo @@ -4,6 +4,10 @@ actor Self { var stored : shared () -> async () = Self.method; public func method() : async () { debugPrint "Hey!" }; public func go() : async () { + assert stored == stored; + assert go != stored; + //assert Self.method == Self.method; + //assert Self.go != Self.method; //assert stored == method; //assert stored == Self.method; await stored() From 83cca50e455818e5d4d9d796ed0e7b465d1f2359 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 16:44:54 +0200 Subject: [PATCH 45/67] WIP: eagerly define in outer scope --- src/mo_interpreter/interpret.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 154004b0804..b86dcdaf011 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -890,8 +890,10 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = let self' = V.Blob self in let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in + (* Define self_id eagerly *) + Option.iter (fun id -> define_id env' id self') self_id; (* Define self_id in inner scope if there is a non-shadowing way to do it *) - let env' = + (*let env' = if match self_id with | None -> false | Some self -> V.Env.mem self.it ve_in then env' (* would shadow *) else begin @@ -901,7 +903,7 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = Option.iter (fun id -> define_id env' id self') self_id; env' end - in + in*) interpret_dec_fields env' dec_fields ve_ex (fun obj -> (env.actor_env := V.Env.add self obj !(env.actor_env); @@ -976,9 +978,7 @@ and interpret_dec env dec (k : V.value V.cont) = let f = interpret_func env id.it shared_pat pat (fun env' k' -> if obj_sort.it <> T.Actor then let env'' = adjoin_vals env' (declare_id id') in - interpret_obj env'' obj_sort.it None dec_fields (fun v' -> - define_id env'' id' v'; - k' v') + interpret_obj env'' obj_sort.it None dec_fields k' else async env' Source.no_region (fun k'' r -> From 58a5aae5773613b9f53e434573ebe84efa82545b Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 19:09:46 +0200 Subject: [PATCH 46/67] WIP: salvage the situation for now --- src/mo_interpreter/interpret.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index b86dcdaf011..274ae3f81bc 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -783,7 +783,10 @@ and define_id env id v = define_id' env id.it v and define_id' env id v = - Lib.Promise.fulfill (find id env.vals) v + let b = find id env.vals in + if Lib.Promise.(is_fulfilled b && value b = v) + then () + else Lib.Promise.fulfill (find id env.vals) v and define_pat env pat v = match match_pat pat v with From 0e09b5942edfa681c14554c4d10c4b97e6380ed6 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 19:17:47 +0200 Subject: [PATCH 47/67] revert --- src/mo_interpreter/interpret.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 274ae3f81bc..77c5ce59236 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -933,6 +933,7 @@ and interpret_dec_fields env dec_fields ve (k : V.value V.cont) = | {it = {dec; _}; _}::dec_fields' -> interpret_dec env dec (fun _v -> interpret_dec_fields env dec_fields' ve k) + (* Blocks and Declarations *) and interpret_block env decs ro (k : V.value V.cont) = From 9da4dde330ed98daa01b75eae5bfcfd1d9aaa1de Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 20:25:39 +0200 Subject: [PATCH 48/67] intro and use `lookup_actor` to fetch actor and its method from the environment --- src/mo_interpreter/interpret.ml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 77c5ce59236..cfd0c053491 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -83,6 +83,15 @@ let find id env = let dom = V.Env.keys env in trap no_region "unbound identifier %s in domain %s" id (String.concat " " dom) +let lookup_actor env at aid id = + match V.Env.find_opt aid !(env.actor_env) with + | None -> trap at "Unknown actor \"%s\"" aid + | Some actor_value -> + let fs = V.as_obj actor_value in + match V.Env.find_opt id fs with + | None -> trap at "Actor \"%s\" has no method \"%s\"" aid id + | Some field_value -> field_value + (* Tracing *) let trace_depth = ref 0 @@ -565,8 +574,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | CallE (exp1, typs, exp2) -> interpret_exp env exp1 (fun v1 -> let v1 = begin match v1 with - | V.Tup V.[Blob aid; Text id] -> - V.Env.(find aid !(env.actor_env) |> V.as_obj |> find id) + | V.Tup V.[Blob aid; Text id] -> lookup_actor env exp1.at aid id | _ -> v1 end in interpret_exp env exp2 (fun v2 -> From a883087161bbd1b201799de1c575b9aa9d9f64c5 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 21:34:44 +0200 Subject: [PATCH 49/67] fix update the right `env` --- src/mo_interpreter/interpret.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index cfd0c053491..cf095376028 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -899,10 +899,10 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = | T.Actor -> let self = V.fresh_id() in let self' = V.Blob self in + Option.iter (fun id -> define_id env id self') self_id; let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in (* Define self_id eagerly *) - Option.iter (fun id -> define_id env' id self') self_id; (* Define self_id in inner scope if there is a non-shadowing way to do it *) (*let env' = if match self_id with | None -> false | Some self -> V.Env.mem self.it ve_in From b4f1410a8633c932f51d4b24218cae18dcd881fe Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 10 Oct 2024 21:37:24 +0200 Subject: [PATCH 50/67] cleanup --- src/mo_interpreter/interpret.ml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index cf095376028..4580d8a24ef 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -899,22 +899,10 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = | T.Actor -> let self = V.fresh_id() in let self' = V.Blob self in + (* Define self_id eagerly *) Option.iter (fun id -> define_id env id self') self_id; let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in let env' = adjoin_vals { env with self } ve_in in - (* Define self_id eagerly *) - (* Define self_id in inner scope if there is a non-shadowing way to do it *) - (*let env' = - if match self_id with | None -> false | Some self -> V.Env.mem self.it ve_in - then env' (* would shadow *) - else begin - let env' = match self_id with - | Some self -> adjoin_vals env' (declare_id self) - | _ -> env' in - Option.iter (fun id -> define_id env' id self') self_id; - env' - end - in*) interpret_dec_fields env' dec_fields ve_ex (fun obj -> (env.actor_env := V.Env.add self obj !(env.actor_env); From 21e1429ab06a464cfa32383c506d845dec1e0ca3 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 14:15:02 +0200 Subject: [PATCH 51/67] fix: oops, changed the wrong part --- src/mo_interpreter/interpret.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 4580d8a24ef..e1851f4d6ce 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -978,7 +978,9 @@ and interpret_dec env dec (k : V.value V.cont) = let f = interpret_func env id.it shared_pat pat (fun env' k' -> if obj_sort.it <> T.Actor then let env'' = adjoin_vals env' (declare_id id') in - interpret_obj env'' obj_sort.it None dec_fields k' + interpret_obj env'' obj_sort.it None dec_fields (fun v' -> + define_id env'' id' v'; + k' v') else async env' Source.no_region (fun k'' r -> @@ -988,9 +990,7 @@ and interpret_dec env dec (k : V.value V.cont) = rets = Some k''; throws = Some r } in - interpret_obj env''' obj_sort.it (Some id') dec_fields (fun v' -> - define_id env''' id' v'; - k'' v')) + interpret_obj env''' obj_sort.it (Some id') dec_fields k'') k') in let v = V.Func (CC.call_conv_of_typ dec.note.note_typ, f) in From bead5c9b2c706ebaf9c60d3c08715e7d1e660ed4 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 17:47:18 +0200 Subject: [PATCH 52/67] fix shared method comparison when both sides are external view -> structurally compare tuples when both internal -> physical equality (as before) when mixed -> fail for now --- src/mo_values/operator.ml | 11 ++++++++--- test/run-drun/incomplete-self-reference.mo | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/mo_values/operator.ml b/src/mo_values/operator.ml index 414989d9e53..e870dc8a139 100644 --- a/src/mo_values/operator.ml +++ b/src/mo_values/operator.ml @@ -185,7 +185,7 @@ let structural_equality t = let v1 = as_array v1 in let v2 = as_array v2 in Bool ( - Array.length v1 == Array.length v2 && + Array.length v1 = Array.length v2 && Lib.Array.for_all2 (fun x y -> as_bool (eq_elem x y)) v1 v2 ) | T.Opt t -> ( @@ -235,8 +235,13 @@ let structural_equality t = else go (List.find (fun f -> f.T.lab = l1) fs).T.typ v1 v2 | T.Func (s, c, tbs, ts1, ts2) -> - assert (T.is_shared_sort s); - fun v1 v2 -> Bool (v1 == v2) (* HACK *) + assert (T.is_shared_sort s); + fun v1 v2 -> match v1, v2 with + | (Tup [Blob al; Text ml] as v1), (Tup [Blob ar; Text mr] as v2) -> Bool (v1 = v2) (* public methods *) + | Func _, Tup [Blob _; Text _] + | Tup [Blob _; Text _], Func _ -> assert false; + | (Func _ as v1), (Func _ as v2) -> Bool (v1 == v2) (* both internal, HACK *) + | _ -> failwith "illegal shared function" in go t diff --git a/test/run-drun/incomplete-self-reference.mo b/test/run-drun/incomplete-self-reference.mo index 7a083870bbe..138d3c07e5d 100644 --- a/test/run-drun/incomplete-self-reference.mo +++ b/test/run-drun/incomplete-self-reference.mo @@ -5,11 +5,11 @@ actor Self { public func method() : async () { debugPrint "Hey!" }; public func go() : async () { assert stored == stored; - assert go != stored; - //assert Self.method == Self.method; - //assert Self.go != Self.method; + //assert go != stored; + assert Self.method == Self.method; + assert Self.go != Self.method; //assert stored == method; - //assert stored == Self.method; + assert stored == Self.method; await stored() }; }; From 2eb4457a7166f31c92e2045a9d950f359077da37 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 17:51:54 +0200 Subject: [PATCH 53/67] simplify --- src/mo_values/operator.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mo_values/operator.ml b/src/mo_values/operator.ml index e870dc8a139..bf22cbb7abd 100644 --- a/src/mo_values/operator.ml +++ b/src/mo_values/operator.ml @@ -237,10 +237,10 @@ let structural_equality t = | T.Func (s, c, tbs, ts1, ts2) -> assert (T.is_shared_sort s); fun v1 v2 -> match v1, v2 with - | (Tup [Blob al; Text ml] as v1), (Tup [Blob ar; Text mr] as v2) -> Bool (v1 = v2) (* public methods *) + | Tup [Blob _; Text _], Tup [Blob _; Text _] -> Bool (v1 = v2) (* public methods *) | Func _, Tup [Blob _; Text _] - | Tup [Blob _; Text _], Func _ -> assert false; - | (Func _ as v1), (Func _ as v2) -> Bool (v1 == v2) (* both internal, HACK *) + | Tup [Blob _; Text _], Func _ -> assert false; (* mixed, cannot determine equality *) + | Func _, Func _ -> Bool (v1 == v2) (* both internal, HACK *) | _ -> failwith "illegal shared function" in go t From 7e74d0ce921fbcff1b2abf1f8582e6b37b2d1c0f Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 19:20:38 +0200 Subject: [PATCH 54/67] this needs some more work --- test/run-drun/ok/pass-class-self.tc.ok | 1 + test/run-drun/ok/pass-class-self.tc.ret.ok | 1 + test/run-drun/pass-class-self.mo | 13 +++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 test/run-drun/ok/pass-class-self.tc.ok create mode 100644 test/run-drun/ok/pass-class-self.tc.ret.ok create mode 100644 test/run-drun/pass-class-self.mo diff --git a/test/run-drun/ok/pass-class-self.tc.ok b/test/run-drun/ok/pass-class-self.tc.ok new file mode 100644 index 00000000000..514d4fcd93a --- /dev/null +++ b/test/run-drun/ok/pass-class-self.tc.ok @@ -0,0 +1 @@ +pass-class-self.mo:10.5-10.19: definedness error [M0016], cannot use method before Self has been defined diff --git a/test/run-drun/ok/pass-class-self.tc.ret.ok b/test/run-drun/ok/pass-class-self.tc.ret.ok new file mode 100644 index 00000000000..69becfa16f9 --- /dev/null +++ b/test/run-drun/ok/pass-class-self.tc.ret.ok @@ -0,0 +1 @@ +Return code 1 diff --git a/test/run-drun/pass-class-self.mo b/test/run-drun/pass-class-self.mo new file mode 100644 index 00000000000..fce4b1c6fa9 --- /dev/null +++ b/test/run-drun/pass-class-self.mo @@ -0,0 +1,13 @@ +import { debugPrint; principalOfActor } = "mo:⛔"; + +actor class C() = Self { + public func method() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; + func caller(_callee : shared () -> async ()) { }; + + debugPrint "Before!"; + //ignore principalOfActor Self; + //caller(Self.method); + caller(method); + //debugPrint (debug_show(principalOfActor Self)); + //debugPrint "So far so good!"; +} From d566c6558e2bcfd4f9c55f8642856c938f0ce6aa Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 19:46:22 +0200 Subject: [PATCH 55/67] repair `actor class` --- src/mo_frontend/definedness.ml | 7 +++++-- test/run-drun/ok/pass-class-self.diff-ir.ok | 4 ++++ test/run-drun/ok/pass-class-self.diff-low.ok | 4 ++++ test/run-drun/ok/pass-class-self.drun-run.ok | 3 +++ test/run-drun/ok/pass-class-self.run-ir.ok | 1 + test/run-drun/ok/pass-class-self.run-low.ok | 1 + test/run-drun/ok/pass-class-self.tc.ok | 1 - test/run-drun/ok/pass-class-self.tc.ret.ok | 1 - test/run-drun/pass-class-self.mo | 4 ++-- 9 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 test/run-drun/ok/pass-class-self.diff-ir.ok create mode 100644 test/run-drun/ok/pass-class-self.diff-low.ok create mode 100644 test/run-drun/ok/pass-class-self.drun-run.ok create mode 100644 test/run-drun/ok/pass-class-self.run-ir.ok create mode 100644 test/run-drun/ok/pass-class-self.run-low.ok delete mode 100644 test/run-drun/ok/pass-class-self.tc.ok delete mode 100644 test/run-drun/ok/pass-class-self.tc.ret.ok diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index 1b980f0a46c..b94f210a39f 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -177,12 +177,15 @@ and dec msgs d = match d.it with | VarD (i, e) -> (M.empty, S.singleton i.it) +++ exp msgs e | TypD (i, tp, t) -> (M.empty, S.empty) | ClassD (csp, i, tp, p, t, s, i', dfs) -> + let extern = if s.it = Type.Actor then Some i' else None in (M.empty, S.singleton i.it) +++ delayify ( - group msgs (dec_fields msgs dfs @ class_self d.at i') /// pat msgs p /// shared_pat msgs csp + group msgs ~extern (dec_fields msgs dfs @ class_self d.at i' s.it) /// pat msgs p /// shared_pat msgs csp ) (* The class self binding is treated as defined at the very end of the group *) -and class_self at i : group = [(at, S.singleton i.it, S.empty, S.empty)] +and class_self at i : Type.obj_sort -> group = function + | Type.Actor -> [] + | _ -> [(at, S.singleton i.it, S.empty, S.empty)] and decs msgs decs : group = (* Annotate the declarations with the analysis results *) diff --git a/test/run-drun/ok/pass-class-self.diff-ir.ok b/test/run-drun/ok/pass-class-self.diff-ir.ok new file mode 100644 index 00000000000..28c1f98e185 --- /dev/null +++ b/test/run-drun/ok/pass-class-self.diff-ir.ok @@ -0,0 +1,4 @@ +--- pass-class-self.run ++++ pass-class-self.run-ir +@@ -0,0 +1 @@ ++Before! diff --git a/test/run-drun/ok/pass-class-self.diff-low.ok b/test/run-drun/ok/pass-class-self.diff-low.ok new file mode 100644 index 00000000000..b3d286b58c7 --- /dev/null +++ b/test/run-drun/ok/pass-class-self.diff-low.ok @@ -0,0 +1,4 @@ +--- pass-class-self.run ++++ pass-class-self.run-low +@@ -0,0 +1 @@ ++Before! diff --git a/test/run-drun/ok/pass-class-self.drun-run.ok b/test/run-drun/ok/pass-class-self.drun-run.ok new file mode 100644 index 00000000000..2995727c5e0 --- /dev/null +++ b/test/run-drun/ok/pass-class-self.drun-run.ok @@ -0,0 +1,3 @@ +ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 +debug.print: Before! +ingress Completed: Reply: 0x4449444c0000 diff --git a/test/run-drun/ok/pass-class-self.run-ir.ok b/test/run-drun/ok/pass-class-self.run-ir.ok new file mode 100644 index 00000000000..fda743ffda9 --- /dev/null +++ b/test/run-drun/ok/pass-class-self.run-ir.ok @@ -0,0 +1 @@ +Before! diff --git a/test/run-drun/ok/pass-class-self.run-low.ok b/test/run-drun/ok/pass-class-self.run-low.ok new file mode 100644 index 00000000000..fda743ffda9 --- /dev/null +++ b/test/run-drun/ok/pass-class-self.run-low.ok @@ -0,0 +1 @@ +Before! diff --git a/test/run-drun/ok/pass-class-self.tc.ok b/test/run-drun/ok/pass-class-self.tc.ok deleted file mode 100644 index 514d4fcd93a..00000000000 --- a/test/run-drun/ok/pass-class-self.tc.ok +++ /dev/null @@ -1 +0,0 @@ -pass-class-self.mo:10.5-10.19: definedness error [M0016], cannot use method before Self has been defined diff --git a/test/run-drun/ok/pass-class-self.tc.ret.ok b/test/run-drun/ok/pass-class-self.tc.ret.ok deleted file mode 100644 index 69becfa16f9..00000000000 --- a/test/run-drun/ok/pass-class-self.tc.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 1 diff --git a/test/run-drun/pass-class-self.mo b/test/run-drun/pass-class-self.mo index fce4b1c6fa9..94b3717c58a 100644 --- a/test/run-drun/pass-class-self.mo +++ b/test/run-drun/pass-class-self.mo @@ -5,8 +5,8 @@ actor class C() = Self { func caller(_callee : shared () -> async ()) { }; debugPrint "Before!"; - //ignore principalOfActor Self; - //caller(Self.method); + ignore principalOfActor Self; + caller(Self.method); caller(method); //debugPrint (debug_show(principalOfActor Self)); //debugPrint "So far so good!"; From 454621fddbe91da0b29d56585e237665796a3ff3 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 19:48:23 +0200 Subject: [PATCH 56/67] cleanup --- test/run-drun/pass-self.mo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-drun/pass-self.mo b/test/run-drun/pass-self.mo index 147e7da9abd..3387d021215 100644 --- a/test/run-drun/pass-self.mo +++ b/test/run-drun/pass-self.mo @@ -1,6 +1,6 @@ import { debugPrint; principalOfActor } = "mo:⛔"; -actor /*class () =*/ Self { +actor Self { public func method() : async () { debugPrint "YESS!"; ignore principalOfActor Self }; func caller(_callee : shared () -> async ()) { }; From 9b3897e458a5d4ca162a3e976ee7d78c4c657ca5 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 19:49:49 +0200 Subject: [PATCH 57/67] remove --- test/fail/access-self-prematurely.mo | 5 ----- test/fail/ok/access-self-prematurely.tc.ok | 1 - test/fail/ok/access-self-prematurely.tc.ret.ok | 1 - 3 files changed, 7 deletions(-) delete mode 100644 test/fail/access-self-prematurely.mo delete mode 100644 test/fail/ok/access-self-prematurely.tc.ok delete mode 100644 test/fail/ok/access-self-prematurely.tc.ret.ok diff --git a/test/fail/access-self-prematurely.mo b/test/fail/access-self-prematurely.mo deleted file mode 100644 index 0d815ac0933..00000000000 --- a/test/fail/access-self-prematurely.mo +++ /dev/null @@ -1,5 +0,0 @@ -actor /*class () =*/ Self { - func caller(_callee : shared () -> async ()) { }; - caller(method1); - public func method1() : async () { }; -} diff --git a/test/fail/ok/access-self-prematurely.tc.ok b/test/fail/ok/access-self-prematurely.tc.ok deleted file mode 100644 index d6e4d28afbc..00000000000 --- a/test/fail/ok/access-self-prematurely.tc.ok +++ /dev/null @@ -1 +0,0 @@ -access-self-prematurely.mo:3.5-3.20: definedness error [M0016], cannot use method1 before method1 has been defined diff --git a/test/fail/ok/access-self-prematurely.tc.ret.ok b/test/fail/ok/access-self-prematurely.tc.ret.ok deleted file mode 100644 index 69becfa16f9..00000000000 --- a/test/fail/ok/access-self-prematurely.tc.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 1 From e6b499372822f609a86d51c7702a8cf2b83eff86 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 20:12:57 +0200 Subject: [PATCH 58/67] use `lookup_actor` in IR-interpreter too --- src/ir_interpreter/interpret_ir.ml | 23 +++++++++++++++++------ src/mo_interpreter/interpret.ml | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index d0d6a6792b9..45812d3adfd 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -71,6 +71,15 @@ let find id env = with Not_found -> trap no_region "unbound identifier %s" id +let lookup_actor env at aid id = + match V.Env.find_opt aid !(env.actor_env) with + | None -> trap at "Unknown actor \"%s\"" aid + | Some actor_value -> + let fs = V.as_obj actor_value in + match V.Env.find_opt id fs with + | None -> trap at "Actor \"%s\" has no method \"%s\"" aid id + | Some field_value -> field_value + (* Tracing *) let trace_depth = ref 0 @@ -313,12 +322,14 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | PrimE (p, es) -> interpret_exps env es [] (fun vs -> match p, vs with + | CallPrim typs, [V.(Tup [Blob aid; Text id]); v2] -> + let v1 = lookup_actor env exp.at aid id in + let call_conv, f = V.as_func v1 in + check_call_conv (List.hd es) call_conv; + check_call_conv_arg env exp v2 call_conv; + last_region := exp.at; (* in case the following throws *) + f (context env) v2 k | CallPrim typs, [v1; v2] -> - let v1 = begin match v1 with - | V.Tup V.[Blob aid; Text id] -> - V.Env.(find aid !(env.actor_env) |> V.as_obj |> find id) - | _ -> v1 - end in let call_conv, f = V.as_func v1 in check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; @@ -447,7 +458,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = let e = V.Tup [V.Variant ("canister_reject", V.unit); v1] in Scheduler.queue (fun () -> reject e) | ICCallPrim, V.[Tup [Blob aid; Text id]; v2; kv; rv; cv] -> - let v1 = V.Env.(find aid !(env.actor_env) |> V.as_obj |> find id) in + let v1 = lookup_actor env exp.at aid id in let call_conv, f = V.as_func v1 in check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index e1851f4d6ce..a132c3b2861 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -574,7 +574,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | CallE (exp1, typs, exp2) -> interpret_exp env exp1 (fun v1 -> let v1 = begin match v1 with - | V.Tup V.[Blob aid; Text id] -> lookup_actor env exp1.at aid id + | V.(Tup [Blob aid; Text id]) -> lookup_actor env exp1.at aid id | _ -> v1 end in interpret_exp env exp2 (fun v2 -> From afbb127e6bab6bac65c02cdab75639beedfcb596 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 20:15:07 +0200 Subject: [PATCH 59/67] simplify --- src/ir_interpreter/interpret_ir.ml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index 45812d3adfd..eb519f4ab0d 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -322,14 +322,10 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | PrimE (p, es) -> interpret_exps env es [] (fun vs -> match p, vs with - | CallPrim typs, [V.(Tup [Blob aid; Text id]); v2] -> - let v1 = lookup_actor env exp.at aid id in - let call_conv, f = V.as_func v1 in - check_call_conv (List.hd es) call_conv; - check_call_conv_arg env exp v2 call_conv; - last_region := exp.at; (* in case the following throws *) - f (context env) v2 k | CallPrim typs, [v1; v2] -> + let v1 = match v1 with + | V.(Tup [Blob aid; Text id]) -> lookup_actor env exp.at aid id + | _ -> v1 in let call_conv, f = V.as_func v1 in check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; From 548c8320c66e1fe24a344999a3037483ea09d3c1 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 20:16:17 +0200 Subject: [PATCH 60/67] indent --- src/ir_interpreter/interpret_ir.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index eb519f4ab0d..dbe2fd33836 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -335,7 +335,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = k (try Operator.unop op ot v1 with Invalid_argument s -> trap exp.at "%s" s) | BinPrim (ot, op), [v1; v2] -> k (try Operator.binop op ot v1 v2 with _ -> - trap exp.at "arithmetic overflow") + trap exp.at "arithmetic overflow") | RelPrim (ot, op), [v1; v2] -> k (Operator.relop op ot v1 v2) | TupPrim, exps -> From 414f14d105abb6af963f1828d4989d08eb76a715 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 11 Oct 2024 21:05:59 +0200 Subject: [PATCH 61/67] heed Claudio's advice, and create an intermediary environment this is also how `ClassD` is done --- src/mo_interpreter/interpret.ml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index a132c3b2861..6fd3b86afa8 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -791,10 +791,7 @@ and define_id env id v = define_id' env id.it v and define_id' env id v = - let b = find id env.vals in - if Lib.Promise.(is_fulfilled b && value b = v) - then () - else Lib.Promise.fulfill (find id env.vals) v + Lib.Promise.fulfill (find id env.vals) v and define_pat env pat v = match match_pat pat v with @@ -900,10 +897,13 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = let self = V.fresh_id() in let self' = V.Blob self in (* Define self_id eagerly *) - Option.iter (fun id -> define_id env id self') self_id; + let env' = match self_id with + | Some id -> adjoin_vals env (declare_id id) + | None -> env in + Option.iter (fun id -> define_id env' id self') self_id; let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in - let env' = adjoin_vals { env with self } ve_in in - interpret_dec_fields env' dec_fields ve_ex + let env'' = adjoin_vals { env' with self } ve_in in + interpret_dec_fields env'' dec_fields ve_ex (fun obj -> (env.actor_env := V.Env.add self obj !(env.actor_env); k self')) From 4459be72c18b318642a511e534c7e46e4f75f971 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 14 Oct 2024 11:19:47 +0200 Subject: [PATCH 62/67] pretty-print the actor name too resolves a FIXME --- src/mo_def/arrange.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mo_def/arrange.ml b/src/mo_def/arrange.ml index 382b077092e..12cb3fecb10 100644 --- a/src/mo_def/arrange.ml +++ b/src/mo_def/arrange.ml @@ -69,7 +69,13 @@ module Make (Cfg : Config) = struct | FromCandidE e -> "FromCandidE" $$ [exp e] | TupE es -> "TupE" $$ exps es | ProjE (e, i) -> "ProjE" $$ [exp e; Atom (string_of_int i)] - | ObjBlockE (s, (_FIXME ,t), dfs) -> "ObjBlockE" $$ [obj_sort s; match t with None -> Atom "_" | Some t -> typ t] @ List.map dec_field dfs + | ObjBlockE (s, nt, dfs) -> "ObjBlockE" $$ [obj_sort s; + match nt with + | None, None -> Atom "_" + | None, Some t -> typ t + | Some id, Some t -> id.it $$ [Atom ":"; typ t] + | Some id, None -> Atom id.it + ] @ List.map dec_field dfs | ObjE ([], efs) -> "ObjE" $$ List.map exp_field efs | ObjE (bases, efs) -> "ObjE" $$ exps bases @ [Atom "with"] @ List.map exp_field efs | DotE (e, x) -> "DotE" $$ [exp e; id x] From aa0e7d5ffa7733408d9acb8cc571bbff4fc74026 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 14 Oct 2024 11:28:44 +0200 Subject: [PATCH 63/67] the name is irrelevant for typing resolves a FIXME --- src/mo_frontend/typing.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_frontend/typing.ml b/src/mo_frontend/typing.ml index 9e7a13a1e15..9001eb6bf47 100644 --- a/src/mo_frontend/typing.ml +++ b/src/mo_frontend/typing.ml @@ -1382,7 +1382,7 @@ and infer_exp'' env exp : T.typ = in let t = infer_obj env' obj_sort.it dec_fields exp.at in begin match env.pre, typ_opt with - | false, (_FIXME, Some typ) -> + | false, (_, Some typ) -> let t' = check_typ env' typ in if not (T.sub t t') then local_error env exp.at "M0192" From 6abf6185a7bf583e6f10ab72afce4f0649959ab4 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 14 Oct 2024 11:32:19 +0200 Subject: [PATCH 64/67] fix #4731 this was a obvious omission --- src/mo_frontend/definedness.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mo_frontend/definedness.ml b/src/mo_frontend/definedness.ml index b94f210a39f..fffe2221df5 100644 --- a/src/mo_frontend/definedness.ml +++ b/src/mo_frontend/definedness.ml @@ -93,7 +93,7 @@ let rec exp msgs e : f = match e.it with | ObjBlockE (s, (self_id_opt, _), dfs) -> group msgs ~extern:self_id_opt (dec_fields msgs dfs) (* The rest remaining cases just collect the uses of subexpressions: *) - | LitE _ | ActorUrlE _ + | LitE _ | PrimE _ | ImportE _ -> M.empty | ObjE (bases, efs) -> exps msgs bases ++ exp_fields msgs efs | TupE es @@ -132,6 +132,7 @@ let rec exp msgs e : f = match e.it with | DoOptE e | BangE e | TagE (_, e) + | ActorUrlE e | IgnoreE e -> exp msgs e and exps msgs es : f = unions (exp msgs) es From fd53c8441b09b6a3947f5f499430f317de7aae53 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 15 Oct 2024 21:33:20 +0200 Subject: [PATCH 65/67] Update src/mo_interpreter/interpret.ml Co-authored-by: Claudio Russo --- src/mo_interpreter/interpret.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 6fd3b86afa8..0164d0b641e 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -577,7 +577,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | V.(Tup [Blob aid; Text id]) -> lookup_actor env exp1.at aid id | _ -> v1 end in - interpret_exp env exp2 (fun v2 -> + interpret_exp env exp2 (fun v2 -> let call_conv, f = V.as_func v1 in check_call_conv exp1 call_conv; check_call_conv_arg env exp v2 call_conv; From de19de5746239a77355a1eb44fe8b9a10e5e52f3 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 16 Oct 2024 09:42:20 +0200 Subject: [PATCH 66/67] clean up --- src/ir_interpreter/interpret_ir.ml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/ir_interpreter/interpret_ir.ml b/src/ir_interpreter/interpret_ir.ml index dbe2fd33836..e62d8949123 100644 --- a/src/ir_interpreter/interpret_ir.ml +++ b/src/ir_interpreter/interpret_ir.ml @@ -453,15 +453,10 @@ and interpret_exp_mut env exp (k : V.value V.cont) = let reject = Option.get env.rejects in let e = V.Tup [V.Variant ("canister_reject", V.unit); v1] in Scheduler.queue (fun () -> reject e) - | ICCallPrim, V.[Tup [Blob aid; Text id]; v2; kv; rv; cv] -> - let v1 = lookup_actor env exp.at aid id in - let call_conv, f = V.as_func v1 in - check_call_conv (List.hd es) call_conv; - check_call_conv_arg env exp v2 call_conv; - last_region := exp.at; (* in case the following throws *) - let vc = context env in - f (V.Tup[vc; kv; rv; cv]) v2 k | ICCallPrim, [v1; v2; kv; rv; cv] -> + let v1 = match v1 with + | V.(Tup [Blob aid; Text id]) -> lookup_actor env exp.at aid id + | _ -> v1 in let call_conv, f = V.as_func v1 in check_call_conv (List.hd es) call_conv; check_call_conv_arg env exp v2 call_conv; From b6d40bd80eb5f2c3943215ae5c0ae6297b153c3b Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Wed, 16 Oct 2024 11:04:23 +0200 Subject: [PATCH 67/67] Update pass-class-self.mo --- test/run-drun/pass-class-self.mo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-drun/pass-class-self.mo b/test/run-drun/pass-class-self.mo index 94b3717c58a..4777aabb58b 100644 --- a/test/run-drun/pass-class-self.mo +++ b/test/run-drun/pass-class-self.mo @@ -8,6 +8,6 @@ actor class C() = Self { ignore principalOfActor Self; caller(Self.method); caller(method); - //debugPrint (debug_show(principalOfActor Self)); + //debugPrint (debug_show(principalOfActor Self)); // See #4733 //debugPrint "So far so good!"; }