From d3fbf39b55e0c6509c03252ef8d326ffeee4b239 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Fri, 31 Jan 2025 15:14:03 -0700 Subject: [PATCH 01/23] Add '.values()' alias for '.vals()' --- src/lowering/desugar.ml | 12 ++++++------ src/mo_frontend/typing.ml | 2 ++ src/mo_interpreter/interpret.ml | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lowering/desugar.ml b/src/lowering/desugar.ml index 7049a6d8a6c..c159b9f1270 100644 --- a/src/lowering/desugar.ml +++ b/src/lowering/desugar.ml @@ -233,7 +233,7 @@ and exp' at note = function | S.LoopE (e1, None) -> I.LoopE (exp e1) | S.LoopE (e1, Some e2) -> (loopWhileE (exp e1) (exp e2)).it | S.ForE (p, {it=S.CallE ({it=S.DotE (arr, proj); _}, _, e1); _}, e2) - when T.is_array arr.note.S.note_typ && (proj.it = "vals" || proj.it = "keys") + when T.is_array arr.note.S.note_typ && (proj.it = "vals" || proj.it = "values" || proj.it = "keys") -> (transform_for_to_while p arr proj e1 e2).it | S.ForE (p, e1, e2) -> (forE (pat p) (exp e1) (exp e2)).it | S.DebugE e -> if !Mo_config.Flags.release_mode then (unitE ()).it else (exp e).it @@ -278,7 +278,7 @@ and lexp' = function | _ -> raise (Invalid_argument ("Unexpected expression as lvalue")) and transform_for_to_while p arr_exp proj e1 e2 = - (* for (p in (arr_exp : [_]).proj(e1)) e2 when proj in {"keys", "vals"} + (* for (p in (arr_exp : [_]).proj(e1)) e2 when proj in {"keys", "vals", "values"} ~~> let arr = arr_exp ; let last = arr.size(e1) : Int - 1 ; @@ -298,7 +298,7 @@ and transform_for_to_while p arr_exp proj e1 e2 = let arrv = fresh_var "arr" arr_typ in let indx = fresh_var "indx" T.(Mut nat) in let indexing_exp = match proj.it with - | "vals" -> primE I.DerefArrayOffset [varE arrv; varE indx] + | "vals" | "values" -> primE I.DerefArrayOffset [varE arrv; varE indx] | "keys" -> varE indx | _ -> assert false in let last = fresh_var "last" T.int in @@ -748,8 +748,8 @@ and array_dotE array_ty proj e = | true, "put" -> call "@mut_array_put" [T.nat; varA] [] | true, "keys" -> call "@mut_array_keys" [] [T.iter_obj T.nat] | false, "keys" -> call "@immut_array_keys" [] [T.iter_obj T.nat] - | true, "vals" -> call "@mut_array_vals" [] [T.iter_obj varA] - | false, "vals" -> call "@immut_array_vals" [] [T.iter_obj varA] + | true, ("vals" | "values") -> call "@mut_array_vals" [] [T.iter_obj varA] + | false, ("vals" | "values") -> call "@immut_array_vals" [] [T.iter_obj varA] | _, _ -> assert false and blob_dotE proj e = @@ -759,7 +759,7 @@ and blob_dotE proj e = callE (varE f) [] e in match proj with | "size" -> call "@blob_size" [] [T.nat] - | "vals" -> call "@blob_vals" [] [T.iter_obj T.(Prim Nat8)] + | "vals" | "values" -> call "@blob_vals" [] [T.iter_obj T.(Prim Nat8)] | _ -> assert false and text_dotE proj e = diff --git a/src/mo_frontend/typing.ml b/src/mo_frontend/typing.ml index eb0c2c36051..a5a4b648b0a 100644 --- a/src/mo_frontend/typing.ml +++ b/src/mo_frontend/typing.ml @@ -1165,6 +1165,7 @@ let array_obj t = {lab = "size"; typ = Func (Local, Returns, [], [], [Prim Nat]); src = empty_src}; {lab = "keys"; typ = Func (Local, Returns, [], [], [iter_obj (Prim Nat)]); src = empty_src}; {lab = "vals"; typ = Func (Local, Returns, [], [], [iter_obj t]); src = empty_src}; + {lab = "values"; typ = Func (Local, Returns, [], [], [iter_obj t]); src = empty_src}; ] in let mut t = immut t @ [ {lab = "put"; typ = Func (Local, Returns, [], [Prim Nat; t], []); src = empty_src} ] in @@ -1175,6 +1176,7 @@ let blob_obj () = let open T in Object, [ {lab = "vals"; typ = Func (Local, Returns, [], [], [iter_obj (Prim Nat8)]); src = empty_src}; + {lab = "values"; typ = Func (Local, Returns, [], [], [iter_obj (Prim Nat8)]); src = empty_src}; {lab = "size"; typ = Func (Local, Returns, [], [], [Prim Nat]); src = empty_src}; ] diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index ec3a30736cb..2259f736a99 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -525,7 +525,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | "get" -> array_get | "put" -> array_put | "keys" -> array_keys - | "vals" -> array_vals + | "vals" | "values" -> array_vals | s -> assert false in k (f vs exp.at) | V.Text s -> @@ -537,7 +537,7 @@ and interpret_exp_mut env exp (k : V.value V.cont) = | V.Blob b when T.sub exp1.note.note_typ (T.blob)-> let f = match id.it with | "size" -> blob_size - | "vals" -> blob_vals + | "vals" | "values" -> blob_vals | s -> assert false in k (f b exp.at) | _ -> assert false From 1109948385deb2dec40191a2cd7fad764994852f Mon Sep 17 00:00:00 2001 From: rvanasa Date: Fri, 31 Jan 2025 15:17:07 -0700 Subject: [PATCH 02/23] Update style guide --- doc/md/reference/style.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/md/reference/style.md b/doc/md/reference/style.md index 38ec8a46a10..805c683e4c4 100644 --- a/doc/md/reference/style.md +++ b/doc/md/reference/style.md @@ -87,7 +87,7 @@ To increase readability and uniformity of Motoko source code, the style guide pr ``` motoko no-repl if (f()) A else B; - for (x in xs.vals()) { ... }; + for (x in xs.values()) { ... }; switch (compare(x, y)) { case (#less) { A }; case (_) { B }; @@ -624,7 +624,7 @@ Rationale: `g[1]` in particular will be misparsed as an indexing operation. ``` motoko no-repl func foreach(xs : [X], f : X -> ()) { - for (x in xs.vals()) { f(x) } + for (x in xs.values()) { f(x) } } ``` @@ -792,7 +792,7 @@ Rationale: `g[1]` in particular will be misparsed as an indexing operation. ``` motoko no-repl for (i in Iter.range(1, 10)) { ... }; - for (x in array.vals()) { ... }; + for (x in array.values()) { ... }; ``` Rationale: For loops are less error-prone and easier to read. From d7539083896df04263a11ad799cb3debda6613c5 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Fri, 31 Jan 2025 15:27:02 -0700 Subject: [PATCH 03/23] Update documentation and examples --- design/WhitePaper.md | 2 +- design/scoped-await.md | 2 +- doc/attic/overview.md | 8 ++++---- doc/md/examples/CardShuffle.mo | 2 +- doc/md/examples/CounterWithCompositeQuery.mo | 2 +- doc/md/examples/StableRegistry.mo | 2 +- doc/md/examples/WeatherActor.mo | 2 +- doc/md/reference/language-manual.md | 4 ++-- doc/md/writing-motoko/arguments.md | 2 +- doc/md/writing-motoko/candid.md | 2 +- doc/md/writing-motoko/control-flow.md | 2 +- doc/md/writing-motoko/sharing.md | 4 ++-- doc/overview-slides.md | 2 +- src/mo_values/value.ml | 2 +- src/mo_values/value.mli | 2 +- src/prelude/internals.mo | 8 ++++---- 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/design/WhitePaper.md b/design/WhitePaper.md index 695018dbf7d..76eb775db49 100644 --- a/design/WhitePaper.md +++ b/design/WhitePaper.md @@ -300,7 +300,7 @@ This extension is easy to implement for type definitions, but much more involved On the plus side, the same mechanism can then be used to express any abstractions over shared types. For example, it would be possible to use equality over generic types: ``` func contained(x : A, ys : [A]) : Bool { - for (y in ys.vals()) { if (x == y) return true }; + for (y in ys.values()) { if (x == y) return true }; return false; } ``` diff --git a/design/scoped-await.md b/design/scoped-await.md index d4773c30213..ce4fc906eaf 100644 --- a/design/scoped-await.md +++ b/design/scoped-await.md @@ -269,7 +269,7 @@ Assuming the following requests: for (i in os.keys()) { os[i] := ? (Ack()); }; - for (o in os.vals()) { + for (o in os.values()) { switch o { case (? a) await a; case null (assert false); diff --git a/doc/attic/overview.md b/doc/attic/overview.md index 628a65882fa..936314632af 100644 --- a/doc/attic/overview.md +++ b/doc/attic/overview.md @@ -370,7 +370,7 @@ assert(days[1] == "Tue"); // days[7] will trap (fixed size) -for (d in days.vals()) { Debug.print(d) }; +for (d in days.values()) { Debug.print(d) }; ``` ## Arrays (mutable) @@ -623,7 +623,7 @@ actor Broadcast { public func send(t : Text) : async Nat { var sum = 0; - for (a in r.vals()) { + for (a in r.values()) { sum += await a.recv(t); }; return sum; @@ -650,7 +650,7 @@ if the result is an `Error`, `throw`s the error. ``` motoko no-repl public func send(t : Text) : async Nat { var sum = 0; - for (a in r.vals()) { + for (a in r.values()) { sum += await a.recv(t); // may return Nat or `throw` error }; return sum; @@ -670,7 +670,7 @@ A bad implementation of `send`: var sum = 0; // shared state! public func send(t : Text) : async Nat { sum := 0; - for (a in r.vals()) { + for (a in r.values()) { sum += await a.recv(t); }; return sum; diff --git a/doc/md/examples/CardShuffle.mo b/doc/md/examples/CardShuffle.mo index 0cd3c227c0e..84819c71b89 100644 --- a/doc/md/examples/CardShuffle.mo +++ b/doc/md/examples/CardShuffle.mo @@ -63,7 +63,7 @@ persistent actor { public query func show() : async Text { let ?cards = deck else throw Error.reject("shuffle in progress"); var t = ""; - for (card in cards.vals()) { + for (card in cards.values()) { t #= Char.toText(card); }; t; diff --git a/doc/md/examples/CounterWithCompositeQuery.mo b/doc/md/examples/CounterWithCompositeQuery.mo index fadde91dda1..df64ddba831 100644 --- a/doc/md/examples/CounterWithCompositeQuery.mo +++ b/doc/md/examples/CounterWithCompositeQuery.mo @@ -10,7 +10,7 @@ persistent actor class Counter () { public shared composite query func sum(counters : [Counter]) : async Nat { var sum = 0; - for (counter in counters.vals()) { + for (counter in counters.values()) { sum += await counter.peek(); }; sum diff --git a/doc/md/examples/StableRegistry.mo b/doc/md/examples/StableRegistry.mo index 602c8d6900f..3ce56fcf3d9 100644 --- a/doc/md/examples/StableRegistry.mo +++ b/doc/md/examples/StableRegistry.mo @@ -7,7 +7,7 @@ persistent actor Registry { var entries : [(Text, Nat)] = []; // implicitly `stable` transient let map = Map.fromIter( - entries.vals(), 10, Text.equal, Text.hash); + entries.values(), 10, Text.equal, Text.hash); public func register(name : Text) : async () { switch (map.get(name)) { diff --git a/doc/md/examples/WeatherActor.mo b/doc/md/examples/WeatherActor.mo index ea8c9091f76..f1c5a75a3c6 100644 --- a/doc/md/examples/WeatherActor.mo +++ b/doc/md/examples/WeatherActor.mo @@ -5,7 +5,7 @@ persistent actor { public func averageTemperature() : Float { var sum = 0.0; var count = 0.0; - for (value in temperatures.vals()) { + for (value in temperatures.values()) { sum += value; count += 1; }; diff --git a/doc/md/reference/language-manual.md b/doc/md/reference/language-manual.md index 7c4d392eb94..aa8defc8cc4 100644 --- a/doc/md/reference/language-manual.md +++ b/doc/md/reference/language-manual.md @@ -713,7 +713,7 @@ The corresponding module in the base library provides conversion functions: ### Type [`Blob`](../base/Blob.md) -The type [`Blob`](../base/Blob.md) of category O (Ordered) represents binary blobs or sequences of bytes. Function `b.size` returns the number of characters in [`Blob`](../base/Blob.md) value `b`. Operations on blob values include sequential iteration over bytes via function `b.vals` as in `for (v : Nat8 in b.vals()) { …​ v …​ }`. +The type [`Blob`](../base/Blob.md) of category O (Ordered) represents binary blobs or sequences of bytes. Function `b.size()` returns the number of characters in [`Blob`](../base/Blob.md) value `b`. Operations on blob values include sequential iteration over bytes via function `b.values()` as in `for (v : Nat8 in b.values()) { …​ v …​ }`. ### Type [`Principal`](../base/Principal.md) @@ -2360,7 +2360,7 @@ In particular, the `for` loop will trap if evaluation of `` traps; as soon :::note -Although general purpose, `for` loops are commonly used to consume iterators produced by [special member access](#special-member-access) to, for example, loop over the indices (`a.keys()`) or values (`a.vals()`) of some array, `a`. +Although general purpose, `for` loops are commonly used to consume iterators produced by [special member access](#special-member-access) to, for example, loop over the indices (`a.keys()`) or values (`a.values()`) of some array, `a`. ::: diff --git a/doc/md/writing-motoko/arguments.md b/doc/md/writing-motoko/arguments.md index 0a463092ec6..7f6b684624e 100644 --- a/doc/md/writing-motoko/arguments.md +++ b/doc/md/writing-motoko/arguments.md @@ -41,7 +41,7 @@ persistent actor { public func location_pretty(cities : [Text]) : async Text { var str = "Hello from "; - for (city in cities.vals()) { + for (city in cities.values()) { str := str # city # ", "; }; return str # "bon voyage!"; diff --git a/doc/md/writing-motoko/candid.md b/doc/md/writing-motoko/candid.md index 26473c11247..096b38bc0b7 100644 --- a/doc/md/writing-motoko/candid.md +++ b/doc/md/writing-motoko/candid.md @@ -91,7 +91,7 @@ persistent actor This { public func concat(ts : [Text]) : async Text { var r = ""; - for (t in ts.vals()) { r #= t }; + for (t in ts.values()) { r #= t }; r }; diff --git a/doc/md/writing-motoko/control-flow.md b/doc/md/writing-motoko/control-flow.md index db5e0912a6f..d46c9fb5db5 100644 --- a/doc/md/writing-motoko/control-flow.md +++ b/doc/md/writing-motoko/control-flow.md @@ -133,7 +133,7 @@ let carsInStock = [ ("Audi", 2020, 34.900) ]; var inventory : { var value : Float } = { var value = 0.0 }; -for ((model, year, price) in carsInStock.vals()) { +for ((model, year, price) in carsInStock.values()) { inventory.value += price; }; inventory diff --git a/doc/md/writing-motoko/sharing.md b/doc/md/writing-motoko/sharing.md index 4a9f1791946..2592f238712 100644 --- a/doc/md/writing-motoko/sharing.md +++ b/doc/md/writing-motoko/sharing.md @@ -52,7 +52,7 @@ persistent actor Publisher { }; public func publish() { - for (sub in subs.vals()) { + for (sub in subs.values()) { sub.notify(); }; }; @@ -167,7 +167,7 @@ persistent actor Publisher { }; public func publish() { - for (sub in subs.vals()) { + for (sub in subs.values()) { sub.callback(); }; }; diff --git a/doc/overview-slides.md b/doc/overview-slides.md index a11d1a1bcfa..14201b952fe 100644 --- a/doc/overview-slides.md +++ b/doc/overview-slides.md @@ -252,7 +252,7 @@ let days = ["Monday", "Tuesday", … ]; assert(days.len() == 7); assert(days[1] == "Tuesday"); // days[7] will trap (fixed size) -for (d in days.vals()) { Debug.print(d) }; +for (d in days.values()) { Debug.print(d) }; ``` ## Arrays (mutable) diff --git a/src/mo_values/value.ml b/src/mo_values/value.ml index c21d255e6a4..c14f79d5254 100644 --- a/src/mo_values/value.ml +++ b/src/mo_values/value.ml @@ -58,7 +58,7 @@ and value = | Async of async | Comp of comp | Mut of value ref - | Iter of value Seq.t ref (* internal to {b.vals(), t.chars()} iterator *) + | Iter of value Seq.t ref (* internal to {b.values(), t.chars()} iterator *) and res = Ok of value | Error of value and async = {result : res Lib.Promise.t ; mutable waiters : (value cont * value cont) list} diff --git a/src/mo_values/value.mli b/src/mo_values/value.mli index 8da635962b4..25d0a575bdf 100644 --- a/src/mo_values/value.mli +++ b/src/mo_values/value.mli @@ -49,7 +49,7 @@ and value = | Async of async | Comp of comp | Mut of value ref - | Iter of value Seq.t ref (* internal to {b.vals(), t.chars()} iterator *) + | Iter of value Seq.t ref (* internal to {b.values(), t.chars()} iterator *) and res = Ok of value | Error of value and async = {result : res Lib.Promise.t ; mutable waiters : (value cont * value cont) list} diff --git a/src/prelude/internals.mo b/src/prelude/internals.mo index 713b7544ddb..4e66c81ce54 100644 --- a/src/prelude/internals.mo +++ b/src/prelude/internals.mo @@ -198,7 +198,7 @@ func @text_of_Char(c : Char) : Text { func @text_of_Blob(blob : Blob) : Text { var t = "\""; - for (b in blob.vals()) { + for (b in blob.values()) { // Could do more clever escaping, e.g. leave ascii and utf8 in place t #= "\\" # @left_pad(2, "0", @text_of_num(@nat8ToNat b, 16, 0, @digits_hex)); }; @@ -243,7 +243,7 @@ func @text_of_variant(l : Text, f : T -> Text, x : T) : Text { func @text_of_array(f : T -> Text, xs : [T]) : Text { var text = "["; var first = true; - for (x in xs.vals()) { + for (x in xs.values()) { if first { first := false; } else { @@ -257,7 +257,7 @@ func @text_of_array(f : T -> Text, xs : [T]) : Text { func @text_of_array_mut(f : T -> Text, xs : [var T]) : Text { var text = "[var"; var first = true; - for (x in xs.vals()) { + for (x in xs.values()) { if first { first := false; text #= " "; @@ -612,7 +612,7 @@ func @timer_helper() : async () { ignore (prim "global_timer_set" : Nat64 -> Nat64) exp; if (exp == 0) @timers := null; - for (o in thunks.vals()) { + for (o in thunks.values()) { switch o { case (?thunk) ignore thunk(); case _ return From 38433d2117eeb91801f29dfe1f8b6c3dd90eb5cd Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 12:15:55 -0700 Subject: [PATCH 04/23] Update tests --- test/fail/objpat-infer.mo | 2 +- test/perf/assetstorage/Array.mo | 12 +-- test/perf/assetstorage/Blob.mo | 4 +- test/perf/assetstorage/Buffer.mo | 2 +- test/perf/assetstorage/Hash.mo | 2 +- test/perf/assetstorage/Int.mo | 2 +- test/perf/assetstorage/Iter.mo | 2 +- test/perf/dao/dao-types.mo | 4 +- test/perf/qr.mo | 2 +- test/perf/qr/array.mo | 6 +- test/perf/qr/hash.mo | 2 +- test/perf/qr/iter.mo | 2 +- test/perf/reversi.mo | 12 +-- test/perf/sha256/Array.mo | 10 +- test/perf/sha256/Buffer.mo | 2 +- test/perf/sha256/Hash.mo | 2 +- test/run-drun/actor-class-cycles.mo | 2 +- test/run-drun/actor-reference-bad.mo | 2 +- test/run-drun/async-bang.mo | 20 ++++ test/run-drun/basic-cycles.mo | 2 +- test/run-drun/caller.mo | 2 +- test/run-drun/gc-random-test/buffer.mo | 6 +- .../run-drun/gc-random-test/gc-random-test.mo | 2 +- test/run-drun/gc-random-test/hash-set.mo | 6 +- test/run-drun/gc.mo | 9 ++ test/run-drun/general_await.mo | 6 ++ test/run-drun/general_await_implicit.mo | 6 ++ test/run-drun/idl-spacebomb.mo | 9 ++ test/run-drun/issue-2047.mo | 2 +- test/run-drun/optimise-for-array-eff.mo | 10 +- test/run-drun/runtime-info.mo | 2 +- test/run-drun/stabilize-blob-iter/version0.mo | 2 +- test/run-drun/stable-exp.mo | 72 ++++++------- test/run-drun/stable-log.mo | 4 +- test/run/array-gen.mo | 3 + test/run/array-iter-max.mo | 2 +- test/run/array.mo | 20 ++++ test/run/bang.mo | 18 ++++ test/run/blobs.mo | 2 +- test/run/issue-3497.mo | 4 +- test/run/iter-no-alloc.mo | 1 + test/run/iter-null.mo | 2 +- test/run/mut-array-iter-max.mo | 13 ++- test/run/object-extend.mo | 2 +- test/run/optimise-for-array-classical.mo | 87 ++++++++++++++- test/run/optimise-for-array-enhanced.mo | 102 ++++++++++++++++++ test/run/stable-log.mo | 4 +- test/run/switch-trap.mo | 2 +- test/viper/label-break-continue.mo | 2 +- 49 files changed, 389 insertions(+), 107 deletions(-) diff --git a/test/fail/objpat-infer.mo b/test/fail/objpat-infer.mo index 439c47cd9c9..a26dcb2669f 100644 --- a/test/fail/objpat-infer.mo +++ b/test/fail/objpat-infer.mo @@ -6,7 +6,7 @@ ignore (switch (object {}) { case {a} 42 }); // checks -for ({} in [object {}].vals()) { Prim.debugPrint "hey" }; +for ({} in [object {}].values()) { Prim.debugPrint "hey" }; // infers diff --git a/test/perf/assetstorage/Array.mo b/test/perf/assetstorage/Array.mo index e3a4cc2aaad..52e42b2453f 100644 --- a/test/perf/assetstorage/Array.mo +++ b/test/perf/assetstorage/Array.mo @@ -49,7 +49,7 @@ module { /// Output array contains each array-value if and only if the predicate is true; ordering retained. public func filter(xs : [A], f : A -> Bool) : [A] { let ys : Buffer.Buffer = Buffer.Buffer(xs.size()); - for (x in xs.vals()) { + for (x in xs.values()) { if (f(x)) { ys.add(x); }; @@ -59,7 +59,7 @@ module { /// Output array contains each transformed optional value; ordering retained. public func mapFilter(xs : [A], f : A -> ?B) : [B] { let ys : Buffer.Buffer = Buffer.Buffer(xs.size()); - for (x in xs.vals()) { + for (x in xs.values()) { switch (f(x)) { case null {}; case (?y) { ys.add(y) }; @@ -91,7 +91,7 @@ module { }; /// Returns optional first value for which predicate is true public func find(xs : [A], f : A -> Bool) : ?A { - for (x in xs.vals()) { + for (x in xs.values()) { if (f(x)) { return ?x; } @@ -163,9 +163,9 @@ module { public func make(x: A) : [A] { [x]; }; - /// Returns `xs.vals()`. - public func vals(xs : [A]) : I.Iter { - xs.vals() + /// Returns `xs.values()`. + public func values(xs : [A]) : I.Iter { + xs.values() }; /// Returns `xs.keys()`. public func keys(xs : [A]) : I.Iter { diff --git a/test/perf/assetstorage/Blob.mo b/test/perf/assetstorage/Blob.mo index 3f0794af05c..129e45a0793 100644 --- a/test/perf/assetstorage/Blob.mo +++ b/test/perf/assetstorage/Blob.mo @@ -15,7 +15,7 @@ /// /// * You can create a `Blob` literal from a `Text` literal, provided the context expects an expression of type `Blob`. /// * `b.size() : Nat` returns the number of bytes in the blob `b`; -/// * `b.vals() : Iter.Iter` returns an iterator to enumerate the bytes of the blob `b`. +/// * `b.values() : Iter.Iter` returns an iterator to enumerate the bytes of the blob `b`. /// /// For example: /// ```motoko include=import @@ -25,7 +25,7 @@ /// let blob = "\00\00\00\ff" : Blob; // blob literals, where each byte is delimited by a back-slash and represented in hex /// let blob2 = "charsもあり" : Blob; // you can also use characters in the literals /// let numBytes = blob.size(); // => 4 (returns the number of bytes in the Blob) -/// for (byte : Nat8 in blob.vals()) { // iterator over the Blob +/// for (byte : Nat8 in blob.values()) { // iterator over the Blob /// Debug.print(Nat8.toText(byte)) /// } /// ``` diff --git a/test/perf/assetstorage/Buffer.mo b/test/perf/assetstorage/Buffer.mo index bd2967918a4..3cdee290eaf 100644 --- a/test/perf/assetstorage/Buffer.mo +++ b/test/perf/assetstorage/Buffer.mo @@ -67,7 +67,7 @@ public class Buffer (initCapacity : Nat) { /// Adds all elements in buffer `b` to this buffer. public func append(b : Buffer) { - let i = b.vals(); + let i = b.values(); loop { switch (i.next()) { case null return; diff --git a/test/perf/assetstorage/Hash.mo b/test/perf/assetstorage/Hash.mo index 2345363d22f..f5fbb2db0df 100644 --- a/test/perf/assetstorage/Hash.mo +++ b/test/perf/assetstorage/Hash.mo @@ -61,7 +61,7 @@ module { // should this really be public? public func hashNat8(key : [Hash]) : Hash { var hash = Prim.natToNat32(0); - for (natOfKey in key.vals()) { + for (natOfKey in key.values()) { hash := hash +% natOfKey; hash := hash +% hash << 10; hash := hash ^ (hash >> 6); diff --git a/test/perf/assetstorage/Int.mo b/test/perf/assetstorage/Int.mo index d2b41db6377..fbaeaaa1629 100644 --- a/test/perf/assetstorage/Int.mo +++ b/test/perf/assetstorage/Int.mo @@ -91,7 +91,7 @@ module { // this is a local copy of deprecated Hash.hashNat8 (redefined to suppress the warning) private func hashNat8(key : [Nat32]) : Hash.Hash { var hash : Nat32 = 0; - for (natOfKey in key.vals()) { + for (natOfKey in key.values()) { hash := hash +% natOfKey; hash := hash +% hash << 10; hash := hash ^ (hash >> 6) diff --git a/test/perf/assetstorage/Iter.mo b/test/perf/assetstorage/Iter.mo index bc7a5c848eb..8afed06e4eb 100644 --- a/test/perf/assetstorage/Iter.mo +++ b/test/perf/assetstorage/Iter.mo @@ -152,7 +152,7 @@ module { /// Like [`fromArray`](#value.fromArray) but for Lists. public func fromList(xs : List.List) : Iter { - List.toArray(xs).vals(); + List.toArray(xs).values(); }; /// Consumes an iterator and collects its produced elements in an Array. diff --git a/test/perf/dao/dao-types.mo b/test/perf/dao/dao-types.mo index b52c9d647fc..64a897356f5 100644 --- a/test/perf/dao/dao-types.mo +++ b/test/perf/dao/dao-types.mo @@ -68,14 +68,14 @@ module { public func account_key(t: Principal) : Trie.Key = { key = t; hash = Principal.hash t }; public func accounts_fromArray(arr: [Account]) : Trie.Trie { var s = Trie.empty(); - for (account in arr.vals()) { + for (account in arr.values()) { s := Trie.put(s, account_key(account.owner), Principal.equal, account.tokens).0; }; s }; public func proposals_fromArray(arr: [Proposal]) : Trie.Trie { var s = Trie.empty(); - for (proposal in arr.vals()) { + for (proposal in arr.values()) { s := Trie.put(s, proposal_key(proposal.id), Nat.equal, proposal).0; }; s diff --git a/test/perf/qr.mo b/test/perf/qr.mo index 3aedd3cc7e1..79a9ba5ffab 100644 --- a/test/perf/qr.mo +++ b/test/perf/qr.mo @@ -82,7 +82,7 @@ actor QR { (#Version 1, #Q, #Alphanumeric, "HELLO WORLD"), (#Version 2, #M, #Alphanumeric, "HTTPS://SDK.DFINITY.ORG"), ]; - for ((version, level, mode, text) in tests.vals()) { + for ((version, level, mode, text) in tests.values()) { let result = await QR.encode(version, level, mode, text); Prelude.printLn(switch result { case (?matrix) "\n" # (await QR.show(matrix)); diff --git a/test/perf/qr/array.mo b/test/perf/qr/array.mo index 050d455c1cf..d7494217c4e 100644 --- a/test/perf/qr/array.mo +++ b/test/perf/qr/array.mo @@ -38,7 +38,7 @@ module { public func apply(fs : [A -> B], xs : [A]) : [B] { var ys : [B] = []; - for (f in fs.vals()) { + for (f in fs.values()) { ys := append(ys, map(f, xs)); }; ys; @@ -60,7 +60,7 @@ module { public func filter(f : A -> Bool, xs : [A]) : [A] { var ys : [A] = []; - for (x in xs.vals()) { + for (x in xs.values()) { if (f(x)) { ys := append(ys, [x]); }; @@ -91,7 +91,7 @@ module { }; public func find(f : A -> Bool, xs : [A]) : ?A { - for (x in xs.vals()) { + for (x in xs.values()) { if (f(x)) { return ?x; } diff --git a/test/perf/qr/hash.mo b/test/perf/qr/hash.mo index 86cc6a0c181..a05028ac46c 100644 --- a/test/perf/qr/hash.mo +++ b/test/perf/qr/hash.mo @@ -97,7 +97,7 @@ module { */ public let hashNat8s : [Hash] -> Hash = func(key) { var hash = Prim.natToNat32(0); - for (natOfKey in key.vals()) { + for (natOfKey in key.values()) { hash := hash +% natOfKey; hash := hash +% hash << 10; hash := hash ^ (hash >> 6); diff --git a/test/perf/qr/iter.mo b/test/perf/qr/iter.mo index a8195000c68..16a4f260ee2 100644 --- a/test/perf/qr/iter.mo +++ b/test/perf/qr/iter.mo @@ -73,7 +73,7 @@ module { }; public func fromList(xs : List.List) : Iter { - List.toArray(xs).vals(); + List.toArray(xs).values(); }; public func toArray(xs : Iter) : [A] { diff --git a/test/perf/reversi.mo b/test/perf/reversi.mo index 38de2d9f04b..ac4084f4bae 100644 --- a/test/perf/reversi.mo +++ b/test/perf/reversi.mo @@ -163,8 +163,8 @@ actor { for (i in range(0, N-1)) { for (j in range(0, N-1)) { if (board[i * N + j] == empty) { - for (p in [-1, 0, 1].vals()) { - for (q in [-1, 0, 1].vals()) { + for (p in [-1, 0, 1].values()) { + for (q in [-1, 0, 1].values()) { if (not(p == 0 and q == 0)) { if (exists(board, opponent(color), i, j, p, q) and eventually(board, color, i, j, p, q)) { @@ -184,8 +184,8 @@ actor { // given position is a valid move before this call. flexible func set_and_flip(board: Board, color: Color, i: Nat, j: Nat) { board[i * N + j] := color; - for (p in [-1, 0, 1].vals()) { - for (q in [-1, 0, 1].vals()) { + for (p in [-1, 0, 1].values()) { + for (q in [-1, 0, 1].values()) { if (not(p == 0 and q == 0)) { if (exists(board, opponent(color), i, j, p, q) and eventually(board, color, i, j, p, q)) { @@ -198,7 +198,7 @@ actor { // Check if the given board is empty. flexible func is_empty(board: Board) : Bool { - for (c in board.vals()) { + for (c in board.values()) { if (c != empty){ return false; } @@ -211,7 +211,7 @@ actor { flexible func score(board: Board) : (Nat, Nat) { var wc = 0; var bc = 0; - for (c in board.vals()) { + for (c in board.values()) { if (c == white) { wc += 1; } diff --git a/test/perf/sha256/Array.mo b/test/perf/sha256/Array.mo index 6291a535606..a2097d796cc 100644 --- a/test/perf/sha256/Array.mo +++ b/test/perf/sha256/Array.mo @@ -120,7 +120,7 @@ module { /// Output array contains each array-value if and only if the predicate is true; ordering retained. public func filter(xs : [A], f : A -> Bool) : [A] { let ys : Buffer.Buffer = Buffer.Buffer(xs.size()); - for (x in xs.vals()) { + for (x in xs.values()) { if (f(x)) { ys.add(x); }; @@ -130,7 +130,7 @@ module { /// Output array contains each transformed optional value; ordering retained. public func mapFilter(xs : [A], f : A -> ?B) : [B] { let ys : Buffer.Buffer = Buffer.Buffer(xs.size()); - for (x in xs.vals()) { + for (x in xs.values()) { switch (f(x)) { case null {}; case (?y) { ys.add(y) }; @@ -162,7 +162,7 @@ module { }; /// Returns optional first value for which predicate is true public func find(xs : [A], f : A -> Bool) : ?A { - for (x in xs.vals()) { + for (x in xs.values()) { if (f(x)) { return ?x; } @@ -237,9 +237,9 @@ module { public func make(x: A) : [A] { [x]; }; - /// Returns `xs.vals()`. + /// Returns `xs.values()`. public func vals(xs : [A]) : I.Iter { - xs.vals() + xs.values() }; /// Returns `xs.keys()`. public func keys(xs : [A]) : I.Iter { diff --git a/test/perf/sha256/Buffer.mo b/test/perf/sha256/Buffer.mo index d3005a6074f..d9c969cb378 100644 --- a/test/perf/sha256/Buffer.mo +++ b/test/perf/sha256/Buffer.mo @@ -60,7 +60,7 @@ module { /// Adds all elements in buffer `b` to this buffer. public func append(b : Buffer) { - let i = b.vals(); + let i = b.values(); loop { switch (i.next()) { case null return; diff --git a/test/perf/sha256/Hash.mo b/test/perf/sha256/Hash.mo index 2c90428d740..00937b777cb 100644 --- a/test/perf/sha256/Hash.mo +++ b/test/perf/sha256/Hash.mo @@ -67,7 +67,7 @@ module { /// @deprecated This function may be removed or changed in future. public func hashNat8(key : [Hash]) : Hash { var hash : Nat32 = 0; - for (natOfKey in key.vals()) { + for (natOfKey in key.values()) { hash := hash +% natOfKey; hash := hash +% hash << 10; hash := hash ^ (hash >> 6); diff --git a/test/run-drun/actor-class-cycles.mo b/test/run-drun/actor-class-cycles.mo index 06c85db266c..8f2bba3f325 100644 --- a/test/run-drun/actor-class-cycles.mo +++ b/test/run-drun/actor-class-cycles.mo @@ -15,7 +15,7 @@ actor a { if (Cycles.balance() == 0) await Cycles.provisional_top_up_actor(a, 100_000_000_000_000); Prim.debugPrint(debug_show({ balance = round(Cycles.balance()) })); - for (i in [1, 2, 3].vals()) { + for (i in [1, 2, 3].values()) { Prim.debugPrint(debug_show({ iteration = i })); Prim.debugPrint(debug_show({ balance = round(Cycles.balance()) })); let c = await { diff --git a/test/run-drun/actor-reference-bad.mo b/test/run-drun/actor-reference-bad.mo index 2391667f43e..cf53683ecda 100644 --- a/test/run-drun/actor-reference-bad.mo +++ b/test/run-drun/actor-reference-bad.mo @@ -14,7 +14,7 @@ actor a { "5h74t-uga73-7nadi", // wrong checksum ]; - for (t in tests.vals()) { + for (t in tests.values()) { Prim.debugPrint(debug_show t # ":"); try (await async ignore (actor(t) : actor {})) catch (e) Prim.debugPrint(Prim.errorMessage(e)) diff --git a/test/run-drun/async-bang.mo b/test/run-drun/async-bang.mo index 1e514438cb1..37c3b373cfa 100644 --- a/test/run-drun/async-bang.mo +++ b/test/run-drun/async-bang.mo @@ -36,6 +36,16 @@ actor a { print(o3); assert (o3 == ? 6); + let o3Values = do ? { + var sum = 0; + await async {}; + for(o in [?1, ?2, ?3].values()) { + sum += o! + }; + sum + }; + assert (o3Values == o3); + let o4 = do ? { var sum = 0; await async {}; @@ -47,6 +57,16 @@ actor a { print o4; assert (o4 == null); + let o4Values = do ? { + var sum = 0; + await async {}; + for(o in [?1, ?2, null].values()) { + sum += o! + }; + sum + }; + assert (o4Values == o4); + /* nesting */ let o5 = do ? { diff --git a/test/run-drun/basic-cycles.mo b/test/run-drun/basic-cycles.mo index 73cfd970224..fdc4f4450b6 100644 --- a/test/run-drun/basic-cycles.mo +++ b/test/run-drun/basic-cycles.mo @@ -69,7 +69,7 @@ actor a { public func iter() : async () { - for (amount in tests.vals()) { + for (amount in tests.values()) { Prim.debugPrint(debug_show {balance = balance()}); if (balance() < amount) { await provisional_top_up_actor(a, amount - balance()); diff --git a/test/run-drun/caller.mo b/test/run-drun/caller.mo index 9c889306a59..018d5f5ab32 100644 --- a/test/run-drun/caller.mo +++ b/test/run-drun/caller.mo @@ -48,7 +48,7 @@ actor a { }; public shared query({caller}) func c11() : async ?Nat8 { - (Prim.blobOfPrincipal caller).vals().next(); + (Prim.blobOfPrincipal caller).values().next(); }; }; diff --git a/test/run-drun/gc-random-test/buffer.mo b/test/run-drun/gc-random-test/buffer.mo index a29c1d2641d..27e83e963b8 100644 --- a/test/run-drun/gc-random-test/buffer.mo +++ b/test/run-drun/gc-random-test/buffer.mo @@ -157,7 +157,7 @@ module { /// buffer.add(12); /// /// var sum = 0; - /// for (element in buffer.vals()) { + /// for (element in buffer.values()) { /// sum += element; /// }; /// sum // => 33 @@ -166,7 +166,7 @@ module { /// Runtime: O(1) /// /// Space: O(1) - public func vals() : { next : () -> ?X } = object { + public func values() : { next : () -> ?X } = object { // FIXME either handle modification to underlying list // or explicitly warn users in documentation var nextIndex = 0; @@ -201,7 +201,7 @@ module { /// /// *Runtime and space assumes that `equal` runs in O(1) time and space. public func contains(buffer : Buffer, element : X, equal : (X, X) -> Bool) : Bool { - for (current in buffer.vals()) { + for (current in buffer.values()) { if (equal(current, element)) { return true; }; diff --git a/test/run-drun/gc-random-test/gc-random-test.mo b/test/run-drun/gc-random-test/gc-random-test.mo index d9c7171c27a..3a7bbff9a1b 100644 --- a/test/run-drun/gc-random-test/gc-random-test.mo +++ b/test/run-drun/gc-random-test/gc-random-test.mo @@ -57,7 +57,7 @@ module { return; }; let references = currentType.readReferences(current); - for (next in references.vals()) { + for (next in references.values()) { pending.push(next); }; }; diff --git a/test/run-drun/gc-random-test/hash-set.mo b/test/run-drun/gc-random-test/hash-set.mo index 9310c4ed142..112205aa028 100644 --- a/test/run-drun/gc-random-test/hash-set.mo +++ b/test/run-drun/gc-random-test/hash-set.mo @@ -46,12 +46,12 @@ module { public func values() : Iter { let combined = Buffer.Buffer(0); - for (collisionList in table.vals()) { - for (value in collisionList.vals()) { + for (collisionList in table.values()) { + for (value in collisionList.values()) { combined.add(value); }; }; - combined.vals(); + combined.values(); }; }; }; diff --git a/test/run-drun/gc.mo b/test/run-drun/gc.mo index 12c4307308c..b7fae883e12 100644 --- a/test/run-drun/gc.mo +++ b/test/run-drun/gc.mo @@ -5,6 +5,9 @@ actor { let blob = "\00\01\02\03" : Blob; for (b in blob.vals()) { await async {}; + }; + for (b in blob.values()) { + await async {}; Prim.debugPrint(debug_show b); }; }; @@ -21,6 +24,9 @@ actor { let is = ["0","1","2"]; for (i in is.vals()) { await async {}; + }; + for (i in is.values()) { + await async {}; Prim.debugPrint(debug_show i); }; }; @@ -30,6 +36,9 @@ actor { let is = [var "0","1","2"]; for (i in is.vals()) { await async {}; + }; + for (i in is.values()) { + await async {}; Prim.debugPrint(debug_show i); }; }; diff --git a/test/run-drun/general_await.mo b/test/run-drun/general_await.mo index d81e80e2917..f37cb1c2062 100644 --- a/test/run-drun/general_await.mo +++ b/test/run-drun/general_await.mo @@ -40,6 +40,12 @@ actor Await { case null (assert false); }; }; + for (o in os.values()) { + switch o { + case (? a) await a; + case null (assert false); + }; + }; }; // Dynamic parallel waiting (with results) diff --git a/test/run-drun/general_await_implicit.mo b/test/run-drun/general_await_implicit.mo index 6194907187d..5229e793523 100644 --- a/test/run-drun/general_await_implicit.mo +++ b/test/run-drun/general_await_implicit.mo @@ -39,6 +39,12 @@ actor Await { case null (assert false); }; }; + for (o in os.values()) { + switch o { + case (? a) await a; + case null (assert false); + }; + }; }; // Dynamic parallel waiting (with results) diff --git a/test/run-drun/idl-spacebomb.mo b/test/run-drun/idl-spacebomb.mo index 997f414a743..3fd74c052bf 100644 --- a/test/run-drun/idl-spacebomb.mo +++ b/test/run-drun/idl-spacebomb.mo @@ -121,6 +121,15 @@ actor this { catch e { debugPrint(errorMessage(e)); } + }; + for (blob in blobs.values()) { + debugPrint (debug_show { function = m; hex = toHex blob}); + try { + ignore await call_raw(p, m, blob); + } + catch e { + debugPrint(errorMessage(e)); + } } }; diff --git a/test/run-drun/issue-2047.mo b/test/run-drun/issue-2047.mo index ac17c3af6ec..cf1cd56610b 100644 --- a/test/run-drun/issue-2047.mo +++ b/test/run-drun/issue-2047.mo @@ -2,7 +2,7 @@ actor a { let fooArr /* : [None] */ = []; ignore (fooArr : [Any]); public func run() { - for (f in fooArr.vals()) { + for (f in fooArr.values()) { await f(); }; }; diff --git a/test/run-drun/optimise-for-array-eff.mo b/test/run-drun/optimise-for-array-eff.mo index d3f0e4a272e..eda45590a1d 100644 --- a/test/run-drun/optimise-for-array-eff.mo +++ b/test/run-drun/optimise-for-array-eff.mo @@ -2,17 +2,17 @@ import Prim "mo:⛔"; actor a { public func go() : async () { - for (check1 in (await async ["effect", "hello", "world"]).vals()) { Prim.debugPrint check1 }; + for (check1 in (await async ["effect", "hello", "world"]).values()) { Prim.debugPrint check1 }; - for (check2 in ["hello", "world", "effect"].vals()) { await async { Prim.debugPrint check2 } }; + for (check2 in ["hello", "world", "effect"].values()) { await async { Prim.debugPrint check2 } }; let array = ["hello", "bound", "world"]; - for (check3 in (await async array).vals()) { Prim.debugPrint check3 }; + for (check3 in (await async array).values()) { Prim.debugPrint check3 }; - for (check4 in array.vals()) { await async { Prim.debugPrint check4 } }; + for (check4 in array.values()) { await async { Prim.debugPrint check4 } }; - for (_ in array.vals(await async ())) { } + for (_ in array.values(await async ())) { } } }; a.go(); //OR-CALL ingress go "DIDL\x00\x00" diff --git a/test/run-drun/runtime-info.mo b/test/run-drun/runtime-info.mo index eb139d8da83..39e08657d2d 100644 --- a/test/run-drun/runtime-info.mo +++ b/test/run-drun/runtime-info.mo @@ -10,7 +10,7 @@ actor Self { }; func validGC(strategy : Text) : Bool { - for (name in ["copying", "compacting", "generational", "incremental", "default"].vals()) { + for (name in ["copying", "compacting", "generational", "incremental", "default"].values()) { if (strategy == name # " force") { return true; }; diff --git a/test/run-drun/stabilize-blob-iter/version0.mo b/test/run-drun/stabilize-blob-iter/version0.mo index 68bcb70a02c..dd3aeae7dfe 100644 --- a/test/run-drun/stabilize-blob-iter/version0.mo +++ b/test/run-drun/stabilize-blob-iter/version0.mo @@ -3,7 +3,7 @@ import Prim "mo:prim"; actor { let temporary = 1; - let blobiter = ("hello" : Blob).vals(); + let blobiter = ("hello" : Blob).values(); stable let value : { stableField : Text; diff --git a/test/run-drun/stable-exp.mo b/test/run-drun/stable-exp.mo index b363771a089..718fa1f4759 100644 --- a/test/run-drun/stable-exp.mo +++ b/test/run-drun/stable-exp.mo @@ -23,56 +23,56 @@ actor { a[0] += 1; let v = a[0]; - for (a in a1.vals()) + for (a in a1.values()) { assert a[0] == v }; - for (a1 in a2.vals()) - for (a in a1.vals()) + for (a1 in a2.values()) + for (a in a1.values()) { assert a[0] == v }; - for (a2 in a3.vals()) - for (a1 in a2.vals()) - for (a in a1.vals()) + for (a2 in a3.values()) + for (a1 in a2.values()) + for (a in a1.values()) { assert a[0] == v }; - for (a3 in a4.vals()) - for (a2 in a3.vals()) - for (a1 in a2.vals()) - for (a in a1.vals()) + for (a3 in a4.values()) + for (a2 in a3.values()) + for (a1 in a2.values()) + for (a in a1.values()) { assert a[0] == v }; - for (a4 in a5.vals()) - for (a3 in a4.vals()) - for (a2 in a3.vals()) - for (a1 in a2.vals()) - for (a in a1.vals()) + for (a4 in a5.values()) + for (a3 in a4.values()) + for (a2 in a3.values()) + for (a1 in a2.values()) + for (a in a1.values()) { assert a[0] == v }; - for (a5 in a6.vals()) - for (a4 in a5.vals()) - for (a3 in a4.vals()) - for (a2 in a3.vals()) - for (a1 in a2.vals()) - for (a in a1.vals()) + for (a5 in a6.values()) + for (a4 in a5.values()) + for (a3 in a4.values()) + for (a2 in a3.values()) + for (a1 in a2.values()) + for (a in a1.values()) { assert a[0] == v }; - for (a6 in a7.vals()) - for (a5 in a6.vals()) - for (a4 in a5.vals()) - for (a3 in a4.vals()) - for (a2 in a3.vals()) - for (a1 in a2.vals()) - for (a in a1.vals()) + for (a6 in a7.values()) + for (a5 in a6.values()) + for (a4 in a5.values()) + for (a3 in a4.values()) + for (a2 in a3.values()) + for (a1 in a2.values()) + for (a in a1.values()) { assert a[0] == v }; - for (a7 in a8.vals()) - for (a6 in a7.vals()) - for (a5 in a6.vals()) - for (a4 in a5.vals()) - for (a3 in a4.vals()) - for (a2 in a3.vals()) - for (a1 in a2.vals()) - for (a in a1.vals()) + for (a7 in a8.values()) + for (a6 in a7.values()) + for (a5 in a6.values()) + for (a4 in a5.values()) + for (a3 in a4.values()) + for (a2 in a3.values()) + for (a1 in a2.values()) + for (a in a1.values()) { assert a[0] == v }; P.debugPrint("...upgraded"); diff --git a/test/run-drun/stable-log.mo b/test/run-drun/stable-log.mo index 852f76c1ed4..e88a28d139e 100644 --- a/test/run-drun/stable-log.mo +++ b/test/run-drun/stable-log.mo @@ -56,14 +56,14 @@ actor { public func readAll() : async () { let ts = await readLast(count); - for (t in ts.vals()) { + for (t in ts.values()) { Prim.debugPrint(t); }; }; public func readExtra() : async () { let ts = await readLast(2*count); - for (t in ts.vals()) { + for (t in ts.values()) { Prim.debugPrint(t); } } diff --git a/test/run/array-gen.mo b/test/run/array-gen.mo index 667bd59ebc5..3df3b7e05ac 100644 --- a/test/run/array-gen.mo +++ b/test/run/array-gen.mo @@ -6,6 +6,9 @@ assert (a.size() == 10); for (n in a.vals()) { assert(n == 42); }; +for (n in a.values()) { + assert(n == 42); +}; let b = Prim.Array_tabulate(10,func (x : Nat) : Nat = x); diff --git a/test/run/array-iter-max.mo b/test/run/array-iter-max.mo index 23646260319..4172d32d3c9 100644 --- a/test/run/array-iter-max.mo +++ b/test/run/array-iter-max.mo @@ -3,7 +3,7 @@ import Prim "mo:⛔"; let max_size = 2**29; // maximum array size let a = Prim.Array_tabulate(max_size,func i = i+1); var c = 0; -for (i in a.vals()) { +for (i in a.values()) { assert i == c+1; c += 1; } ; diff --git a/test/run/array.mo b/test/run/array.mo index 569fe4ae246..409b27ff0ea 100644 --- a/test/run/array.mo +++ b/test/run/array.mo @@ -56,6 +56,12 @@ assert (opt_eq(it2.next(), 2)); assert (opt_eq(it2.next(), 42)); switch (it2.next()) { case null {}; case _ {assert false} }; +var it3 = a.values(); +assert (opt_eq(it3.next(), 1)); +assert (opt_eq(it3.next(), 2)); +assert (opt_eq(it3.next(), 42)); +switch (it3.next()) { case null {}; case _ {assert false} }; + var i = 0; i := 0; @@ -72,6 +78,13 @@ for (n in a.vals()) { }; assert(i == a.size()); +i := 0; +for (n in a.values()) { + assert(n == a[i]); + i += 1; +}; +assert(i == a.size()); + i := 0; for (j in b.keys()) { assert(j == i); @@ -86,6 +99,13 @@ for (n in b.vals()) { }; assert(i == b.size()); +i := 0; +for (n in b.values()) { + assert(n == b[i]); + i += 1; +}; +assert(i == b.size()); + let heterogeneous : Any = [1, 2 : Int8, 3 : Nat16, false, true]; let homogeneous = [true, false, true]; diff --git a/test/run/bang.mo b/test/run/bang.mo index c902d91cb6f..662a687d8b0 100644 --- a/test/run/bang.mo +++ b/test/run/bang.mo @@ -28,7 +28,16 @@ let o3 = do ? { sum }; print(o3); + assert (o3 == ? 6); +let o3Values = do ? { + var sum = 0; + for(o in [?1, ?2, ?3].values()) { + sum += o! + }; + sum +}; +assert (o3Values == ? 6); let o4 = do ? { var sum = 0; @@ -40,6 +49,15 @@ let o4 = do ? { print o4; assert (o4 == null); +let o4Values = do ? { + var sum = 0; + for(o in [?1, ?2, null].values()) { + sum += o! + }; + sum +}; +assert (o4Values == null); + /* nesting */ let o5 = do ? { diff --git a/test/run/blobs.mo b/test/run/blobs.mo index 93c9a62d3d0..270c2396fd4 100644 --- a/test/run/blobs.mo +++ b/test/run/blobs.mo @@ -13,7 +13,7 @@ assert (("\00":Blob) < ("\01":Blob)); assert (("\00":Blob) <= ("\01":Blob)); do { -let i1 = ("\00\01☃":Blob).vals(); +let i1 = ("\00\01☃":Blob).values(); switch(i1.next()) { case (?b) { assert (b == (0:Nat8)); }; case null { assert false; }; diff --git a/test/run/issue-3497.mo b/test/run/issue-3497.mo index 63690fc51d4..06a55f7c212 100644 --- a/test/run/issue-3497.mo +++ b/test/run/issue-3497.mo @@ -3,7 +3,7 @@ import { debugPrint } = "mo:⛔"; do { let t = [var (0x00, 0x00)]; - for ((k, v) in t.vals()) { + for ((k, v) in t.values()) { debugPrint(debug_show(k, v)); } }; @@ -11,7 +11,7 @@ do { do { let t = [(0x01, 0x01)]; - for ((k, v) in t.vals()) { + for ((k, v) in t.values()) { debugPrint(debug_show(k, v)); } }; diff --git a/test/run/iter-no-alloc.mo b/test/run/iter-no-alloc.mo index b98dbc411f4..fac0c9d6e37 100644 --- a/test/run/iter-no-alloc.mo +++ b/test/run/iter-no-alloc.mo @@ -6,6 +6,7 @@ func iter(what : Text, xs : [A]) { let before = Prim.rts_heap_size(); for (_ in xs.keys()) {}; for (_ in xs.vals()) {}; + for (_ in xs.values()) {}; let after = Prim.rts_heap_size(); Prim.debugPrint("Allocation per iteration (" # what # "): " # debug_show ((after-before) / iters : Nat)); }; diff --git a/test/run/iter-null.mo b/test/run/iter-null.mo index 8402ed60ad0..49da6e94ca1 100644 --- a/test/run/iter-null.mo +++ b/test/run/iter-null.mo @@ -1,6 +1,6 @@ let a : [?Nat] = [null, ?1]; var x : ?Nat = ?0; -for (i in a.vals()) { x := i }; +for (i in a.values()) { x := i }; // This tests that the iterator does proceed past the null element switch x { diff --git a/test/run/mut-array-iter-max.mo b/test/run/mut-array-iter-max.mo index c3317a03d30..58b57e68a47 100644 --- a/test/run/mut-array-iter-max.mo +++ b/test/run/mut-array-iter-max.mo @@ -2,13 +2,16 @@ import Prim "mo:⛔"; // test we can iterate over vals and keys of largest mutable array let max_size = 2**29; // maximum array size let a = Prim.Array_init(max_size, 666); -var c = 0; +var c1 = 0; for (v in a.vals()) { + assert v == 666; c1 += 1; +}; +var c2 = 0; +for (v in a.values()) { assert v == 666; c += 1; -} -; -assert c == max_size; -Prim.debugPrint(debug_show c); +}; +assert c1 == c2; +Prim.debugPrint(debug_show c1); var d = 0; for (k in a.keys()) { assert k == d; d += 1; diff --git a/test/run/object-extend.mo b/test/run/object-extend.mo index b0c4c76dfa4..4fbef2553d0 100644 --- a/test/run/object-extend.mo +++ b/test/run/object-extend.mo @@ -65,4 +65,4 @@ func mux(a : A, b : B) : { a : Int; b : Cha // extending iterators let tb_ok : { next : () -> ?Char; bar : Nat } = { "Text base".chars() with bar = 42 }; -let ab_ok : { next : () -> ?Text; bar : Nat } = { ["Array base"].vals() with bar = 42 }; +let ab_ok : { next : () -> ?Text; bar : Nat } = { ["Array base"].values() with bar = 42 }; diff --git a/test/run/optimise-for-array-classical.mo b/test/run/optimise-for-array-classical.mo index 703071a5a9b..5a496ba054c 100644 --- a/test/run/optimise-for-array-classical.mo +++ b/test/run/optimise-for-array-classical.mo @@ -20,6 +20,20 @@ import Prim "mo:⛔"; // FHECK-NEXT: i32.add for (check0 in ["hello", "world"].vals()) { Prim.debugPrint check0 }; +// FHECK-NOT: call $@immut_array_size +// DON'TFHECK: i32.load offset=(5 or 9) +// FHECK: i32.load offset= +// FHECK: i32.const 2 +// FHECK: i32.shl +// FHECK: i32.lt_u +// FHECK: i32.add +// DON'TFHECK: i32.load offset=(9 or 13) +// FHECK: local.tee $check0 +// FHECK-NEXT: call $print_text +// FHECK: i32.const 4 +// FHECK-NEXT: i32.add +for (check0 in ["hello", "world"].values()) { Prim.debugPrint check0 }; + // FHECK-NOT: call $@mut_array_size // DON'TFHECK: i32.load offset=(5 or 9) @@ -34,6 +48,20 @@ for (check0 in ["hello", "world"].vals()) { Prim.debugPrint check0 }; // FHECK-NEXT: call $print_text for (check1 in [var "hello", "mutable", "world"].vals()) { Prim.debugPrint check1 }; + +// FHECK-NOT: call $@mut_array_size +// DON'TFHECK: i32.load offset=(5 or 9) +// FHECK: i32.load offset= +// FHECK: i32.const 2 +// FHECK-NEXT: i32.shl +// FHECK: i32.lt_u +// FHECK: i32.add +// DON'TFHECK: i32.load offset=(9 or 13) +// FHECK: i32.load offset= +// FHECK-NEXT: local.tee $check1 +// FHECK-NEXT: call $print_text +for (check1 in [var "hello", "mutable", "world"].values()) { Prim.debugPrint check1 }; + let array = [var "hello", "remutable", "world"]; array[1] := "mutable"; // FHECK-NOT: call $@immut_array_size @@ -46,7 +74,7 @@ array[1] := "mutable"; // DON'T-FHECK: local.set $check2 // `arr` being a `VarE` already (but we rebind anyway, otherwise we open a can of worms) // later when we have path compression for variables in the backend, we can bring this back -for (check2 in array.vals()) { Prim.debugPrint check2 }; +for (check2 in array.values()) { Prim.debugPrint check2 }; // FHECK-NOT: call $@immut_array_size // DON'TFHECK: i32.load offset=(5 or 9) @@ -61,6 +89,19 @@ for (check2 in array.vals()) { Prim.debugPrint check2 }; // interfering parentheses don't disturb us for (check3 in (((["hello", "immutable", "world"].vals())))) { Prim.debugPrint check3 }; +// FHECK-NOT: call $@immut_array_size +// DON'TFHECK: i32.load offset=(5 or 9) +// FHECK: i32.load offset= +// FHECK: i32.const 2 +// FHECK: i32.shl +// FHECK: i32.lt_u +// FHECK: i32.add +// DON'TFHECK: i32.load offset=(9 or 13) +// FHECK: i32.load offset= +// FHECK-NEXT: local.tee $check3 +// interfering parentheses don't disturb us +for (check3 in (((["hello", "immutable", "world"].values())))) { Prim.debugPrint check3 }; + // FHECK: i32.const 84 // FHECK: call $B_add @@ -77,6 +118,21 @@ if (c == c + 1) { for (check4 in (loop {}).vals()) { Prim.debugPrint check4 } }; +// FHECK: i32.const 84 +// FHECK: call $B_add +// FHECK-NEXT: call $B_eq +// FHECK-NEXT: if +// FHECK-NEXT: loop +// FHECK-NEXT: br 0 +// FHECK-NEXT: end +// FHECK-NEXT: unreachable +// FHECK-NEXT: else +// bottom iteration expression is treated fairly +var c = 42; +if (c == c + 1) { + for (check4 in (loop {}).values()) { Prim.debugPrint check4 } +}; + // FHECK: call $B_add // FHECK-NEXT: call $B_eq // FHECK-NEXT: if @@ -90,12 +146,31 @@ if (c == c + 1) { for (check5 in ((loop {}) : [Text]).vals()) { Prim.debugPrint check5 } }; +// FHECK: call $B_add +// FHECK-NEXT: call $B_eq +// FHECK-NEXT: if +// FHECK-NEXT: loop +// FHECK-NEXT: br 0 +// FHECK-NEXT: end +// FHECK-NEXT: unreachable +// FHECK-NEXT: else +// typed bottom iteration expression is treated fairly +if (c == c + 1) { + for (check5 in ((loop {}) : [Text]).values()) { Prim.debugPrint check5 } +}; + let check6 = [var "hello", "immutable", "world"]; check6[1] := "mutable"; // `check6` being a `VarE` already and iteration variable is named identically // this passes the IR type check, which demonstrates that no name capture happens for (check6 in check6.vals()) { ignore check6 }; +let check6Values = [var "hello", "immutable", "world"]; +check6Values[1] := "mutable"; +// `check6` being a `VarE` already and iteration variable is named identically +// this passes the IR type check, which demonstrates that no name capture happens +for (check6 in check6Values.values()) { ignore check6 }; + // DON'TFHECK: i32.load offset=(5 or 9) // FHECK: i32.load offset= // FHECK: i32.const 2 @@ -128,4 +203,14 @@ func f9(array : [A]) { // make sure that one-byte-sized elements still work var sum10 : Nat8 = 0; for (check10 in ([3, 5, 7, 11] : [Nat8]).vals()) { sum10 += check10 }; +assert sum10 == 26; + +// make sure that one-byte-sized elements still work +sum10 := 0; +for (check10 in ([3, 5, 7, 11] : [Nat8]).values()) { sum10 += check10 }; +assert sum10 == 26; + +// make sure that one-byte-sized elements still work +sum10 := 0; +for (check10 in ([3, 5, 7, 11] : [Nat8]).values()) { sum10 += check10 }; assert sum10 == 26 diff --git a/test/run/optimise-for-array-enhanced.mo b/test/run/optimise-for-array-enhanced.mo index e7ef94a27d8..14fdc462907 100644 --- a/test/run/optimise-for-array-enhanced.mo +++ b/test/run/optimise-for-array-enhanced.mo @@ -17,6 +17,19 @@ import Prim "mo:⛔"; // CHECK: i64.add for (check0 in ["hello", "world"].vals()) { Prim.debugPrint check0 }; +// CHECK-NOT: call $@immut_array_size +// DON'TCHECK: i64.load offset=17 +// CHECK: i64.load offset= +// CHECK: i64.const 2 +// CHECK: i64.shr_s +// CHECK-NEXT: i64.const 3 +// CHECK-NEXT: i64.shl +// CHECK-NEXT: i64.add +// CHECK: local.tee $check0 +// CHECK: i64.const 4 +// CHECK: i64.add +for (check0 in ["hello", "world"].values()) { Prim.debugPrint check0 }; + // CHECK-NOT: call $@mut_array_size // DON'TCHECK: i64.load offset=17 @@ -33,6 +46,21 @@ for (check0 in ["hello", "world"].vals()) { Prim.debugPrint check0 }; // CHECK: i64.add for (check1 in [var "hello", "mutable", "world"].vals()) { Prim.debugPrint check1 }; +// CHECK-NOT: call $@mut_array_size +// DON'TCHECK: i64.load offset=17 +// FIX-CHECK: i64.const 2 +// FIX-CHECK: i64.shr_s +// FIX-CHECK: i64.const 3 +// FIX-CHECK: i64.shl +// FIX-CHECK: i64.add +// DON'TCHECK: i64.load offset=25 +// CHECK: i64.load offset= +// CHECK: local.tee $check1 +// CHECK: call $print_ptr +// CHECK: i64.const 4 +// CHECK: i64.add +for (check1 in [var "hello", "mutable", "world"].values()) { Prim.debugPrint check1 }; + let array = [var "hello", "remutable", "world"]; array[1] := "mutable"; // FIX-CHECK-NOT: call $@immut_array_size @@ -47,6 +75,20 @@ array[1] := "mutable"; // later when we have path compression for variables in the backend, we can bring this back for (check2 in array.vals()) { Prim.debugPrint check2 }; +let arrayValues = [var "hello", "remutable", "world"]; +arrayValues[1] := "mutable"; +// FIX-CHECK-NOT: call $@immut_array_size +// DON'TCHECK: i64.load offset=17 +// FIX-CHECK: i64.load offset= +// FIX-CHECK: i64.const 2 +// FIX-CHECK: i64.shr_s +// DON'T-CHECK: i64.lt_u +// DON'T-CHECK: local.get $array +// DON'T-CHECK: local.set $check2 +// `arr` being a `VarE` already (but we rebind anyway, otherwise we open a can of worms) +// later when we have path compression for variables in the backend, we can bring this back +for (check2 in arrayValues.values()) { Prim.debugPrint check2 }; + // FIX-CHECK-NOT: call $@immut_array_size // DON'TCHECK: i64.load offset=17 // FIX-CHECK: i64.load offset= @@ -59,6 +101,18 @@ for (check2 in array.vals()) { Prim.debugPrint check2 }; // interfering parentheses don't disturb us for (check3 in (((["hello", "immutable", "world"].vals())))) { Prim.debugPrint check3 }; +// FIX-CHECK-NOT: call $@immut_array_size +// DON'TCHECK: i64.load offset=17 +// FIX-CHECK: i64.load offset= +// FIX-CHECK: i64.const 2 +// FIX-CHECK-NEXT: i64.shr_s +// FIX-CHECK: i64.lt_u +// FIX-CHECK: i64.add +// DON'TCHECK: i64.load offset=25 +// FIX-CHECK: local.tee $check3 +// interfering parentheses don't disturb us +for (check3 in (((["hello", "immutable", "world"].values())))) { Prim.debugPrint check3 }; + // FIX-CHECK: i64.const 170 // FIX-CHECK: call $B_add @@ -76,6 +130,22 @@ if (c == c + 1) { for (check4 in (loop {}).vals()) { Prim.debugPrint check4 } }; +// FIX-CHECK: i64.const 170 +// FIX-CHECK: call $B_add +// FIX-CHECK-NEXT: call $B_eq +// FIX-CHECK-NEXT: i32.wrap_i64 +// FIX-CHECK-NEXT: if +// FIX-CHECK-NEXT: loop +// FIX-CHECK-NEXT: br 0 +// FIX-CHECK-NEXT: end +// FIX-CHECK-NEXT: unreachable +// FIX-CHECK-NEXT: else +// bottom iteration expression is treated fairly +c := 42; +if (c == c + 1) { + for (check4 in (loop {}).values()) { Prim.debugPrint check4 } +}; + // FIX-CHECK: call $B_add // FIX-CHECK-NEXT: call $B_eq // FIX-CHECK-NEXT: i32.wrap_i64 @@ -90,12 +160,32 @@ if (c == c + 1) { for (check5 in ((loop {}) : [Text]).vals()) { Prim.debugPrint check5 } }; +// FIX-CHECK: call $B_add +// FIX-CHECK-NEXT: call $B_eq +// FIX-CHECK-NEXT: i32.wrap_i64 +// FIX-CHECK-NEXT: if +// FIX-CHECK-NEXT: loop +// FIX-CHECK-NEXT: br 0 +// FIX-CHECK-NEXT: end +// FIX-CHECK-NEXT: unreachable +// FIX-CHECK-NEXT: else +// typed bottom iteration expression is treated fairly +if (c == c + 1) { + for (check5 in ((loop {}) : [Text]).values()) { Prim.debugPrint check5 } +}; + let check6 = [var "hello", "immutable", "world"]; check6[1] := "mutable"; // `check6` being a `VarE` already and iteration variable is named identically // this passes the IR type check, which demonstrates that no name capture happens for (check6 in check6.vals()) { ignore check6 }; +let check6Values = [var "hello", "immutable", "world"]; +check6Values[1] := "mutable"; +// `check6` being a `VarE` already and iteration variable is named identically +// this passes the IR type check, which demonstrates that no name capture happens +for (check6 in check6Values.values()) { ignore check6 }; + // DON'TCHECK: i64.load offset=17 // FIX-CHECK: i64.load offset= // FIX-CHECK: i64.const 3 @@ -103,6 +193,13 @@ for (check6 in check6.vals()) { ignore check6 }; // argument to vals can have an effect too, expect it for (check7 in [].vals(Prim.debugPrint "want to see you")) { }; +// DON'TCHECK: i64.load offset=17 +// FIX-CHECK: i64.load offset= +// FIX-CHECK: i64.const 3 +// FIX-CHECK: i64.shl +// argument to vals can have an effect too, expect it +for (check7 in [].values(Prim.debugPrint "want to see you")) { }; + // FIX-CHECK: local.set $num8 // FIX-CHECK-NOT: call $@immut_array_size // CON'TFHECK: i64.load offset=17 @@ -128,4 +225,9 @@ func f9(array : [A]) { // make sure that one-byte-sized elements still work var sum10 : Nat8 = 0; for (check10 in ([3, 5, 7, 11] : [Nat8]).vals()) { sum10 += check10 }; +assert sum10 == 26; + +// make sure that one-byte-sized elements still work +sum10 := 0; +for (check10 in ([3, 5, 7, 11] : [Nat8]).values()) { sum10 += check10 }; assert sum10 == 26 diff --git a/test/run/stable-log.mo b/test/run/stable-log.mo index 0f5d92033cf..13c55a4d618 100644 --- a/test/run/stable-log.mo +++ b/test/run/stable-log.mo @@ -54,14 +54,14 @@ func populate() : () { func readAll() : () { let ts = readLast(count); - for (t in ts.vals()) { + for (t in ts.values()) { Prim.debugPrint(t); }; }; func readExtra() : () { let ts = readLast(2*count); - for (t in ts.vals()) { + for (t in ts.values()) { Prim.debugPrint(t); } }; diff --git a/test/run/switch-trap.mo b/test/run/switch-trap.mo index e45cdf8636d..c0f1b51cd38 100644 --- a/test/run/switch-trap.mo +++ b/test/run/switch-trap.mo @@ -1,7 +1,7 @@ import Prim "mo:⛔"; func byteFrom(seed : Blob) : Nat8 { - switch (seed.vals().next()) { + switch (seed.values().next()) { case (?w) { w }; case _ { Prim.trap "Random.byteFrom" } } diff --git a/test/viper/label-break-continue.mo b/test/viper/label-break-continue.mo index 31140f0d73a..8af9778bc5b 100644 --- a/test/viper/label-break-continue.mo +++ b/test/viper/label-break-continue.mo @@ -49,7 +49,7 @@ actor LabelBreakContinue { /* let range = [0, 1, 2, 3, 4, 5]; i := 0; - label for_loop for(j in range.vals()) { + label for_loop for(j in range.values()) { assert:loop:invariant (j == i); assert:loop:invariant (j < 3); i := i + 1; From db9e34473f6dc3f45d9dcb188474ffaec78d8819 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 13:17:08 -0700 Subject: [PATCH 05/23] Adjust tests --- test/run/mut-array-iter-max.mo | 2 +- test/run/ok/array.tc.ok | 4 ++-- test/run/ok/optimise-for-array-classical.tc.ok | 2 +- test/run/optimise-for-array-classical.mo | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/run/mut-array-iter-max.mo b/test/run/mut-array-iter-max.mo index 58b57e68a47..bd84f234978 100644 --- a/test/run/mut-array-iter-max.mo +++ b/test/run/mut-array-iter-max.mo @@ -8,7 +8,7 @@ for (v in a.vals()) { }; var c2 = 0; for (v in a.values()) { - assert v == 666; c += 1; + assert v == 666; c2 += 1; }; assert c1 == c2; Prim.debugPrint(debug_show c1); diff --git a/test/run/ok/array.tc.ok b/test/run/ok/array.tc.ok index 4fd41279006..ad8d94624a2 100644 --- a/test/run/ok/array.tc.ok +++ b/test/run/ok/array.tc.ok @@ -1,6 +1,6 @@ -array.mo:89.27-89.64: warning [M0074], this array has type +array.mo:109.27-89.64: warning [M0074], this array has type [Any] because elements have inconsistent types array.mo:2.5-2.7: warning [M0194], unused identifier aa (delete or rename to wildcard `_` or `_aa`) array.mo:15.5-15.7: warning [M0194], unused identifier bb (delete or rename to wildcard `_` or `_bb`) -array.mo:89.5-89.18: warning [M0194], unused identifier heterogeneous (delete or rename to wildcard `_` or `_heterogeneous`) +array.mo:109.5-89.18: warning [M0194], unused identifier heterogeneous (delete or rename to wildcard `_` or `_heterogeneous`) diff --git a/test/run/ok/optimise-for-array-classical.tc.ok b/test/run/ok/optimise-for-array-classical.tc.ok index 76302a414fd..7c03f18fa8f 100644 --- a/test/run/ok/optimise-for-array-classical.tc.ok +++ b/test/run/ok/optimise-for-array-classical.tc.ok @@ -1 +1 @@ -optimise-for-array-classical.mo:124.6-124.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) +optimise-for-array-classical.mo:131.5-131.6: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) diff --git a/test/run/optimise-for-array-classical.mo b/test/run/optimise-for-array-classical.mo index 5a496ba054c..04d395951c3 100644 --- a/test/run/optimise-for-array-classical.mo +++ b/test/run/optimise-for-array-classical.mo @@ -113,8 +113,8 @@ for (check3 in (((["hello", "immutable", "world"].values())))) { Prim.debugPrint // FHECK-NEXT: unreachable // FHECK-NEXT: else // bottom iteration expression is treated fairly -var c = 42; -if (c == c + 1) { +var c1 = 42; +if (c1 == c1 + 1) { for (check4 in (loop {}).vals()) { Prim.debugPrint check4 } }; @@ -128,8 +128,8 @@ if (c == c + 1) { // FHECK-NEXT: unreachable // FHECK-NEXT: else // bottom iteration expression is treated fairly -var c = 42; -if (c == c + 1) { +var c2 = 42; +if (c2 == c2 + 1) { for (check4 in (loop {}).values()) { Prim.debugPrint check4 } }; From 41c4412107fb31e7766ddcf570e5530c4cd1e90f Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 13:18:23 -0700 Subject: [PATCH 06/23] Update line numbers in test result --- test/run/ok/array.tc.ok | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run/ok/array.tc.ok b/test/run/ok/array.tc.ok index ad8d94624a2..c57b82bd6d6 100644 --- a/test/run/ok/array.tc.ok +++ b/test/run/ok/array.tc.ok @@ -1,6 +1,6 @@ -array.mo:109.27-89.64: warning [M0074], this array has type +array.mo:109.27-109.64: warning [M0074], this array has type [Any] because elements have inconsistent types array.mo:2.5-2.7: warning [M0194], unused identifier aa (delete or rename to wildcard `_` or `_aa`) array.mo:15.5-15.7: warning [M0194], unused identifier bb (delete or rename to wildcard `_` or `_bb`) -array.mo:109.5-89.18: warning [M0194], unused identifier heterogeneous (delete or rename to wildcard `_` or `_heterogeneous`) +array.mo:109.5-109.18: warning [M0194], unused identifier heterogeneous (delete or rename to wildcard `_` or `_heterogeneous`) From a6e2e95d5ac4391b95e6617c69331aa47db53b19 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 13:31:38 -0700 Subject: [PATCH 07/23] Fix --- test/run/optimise-for-array-classical.mo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run/optimise-for-array-classical.mo b/test/run/optimise-for-array-classical.mo index 04d395951c3..96b80c23aeb 100644 --- a/test/run/optimise-for-array-classical.mo +++ b/test/run/optimise-for-array-classical.mo @@ -142,7 +142,7 @@ if (c2 == c2 + 1) { // FHECK-NEXT: unreachable // FHECK-NEXT: else // typed bottom iteration expression is treated fairly -if (c == c + 1) { +if (c1 == c1 + 1) { for (check5 in ((loop {}) : [Text]).vals()) { Prim.debugPrint check5 } }; @@ -155,7 +155,7 @@ if (c == c + 1) { // FHECK-NEXT: unreachable // FHECK-NEXT: else // typed bottom iteration expression is treated fairly -if (c == c + 1) { +if (c2 == c2 + 1) { for (check5 in ((loop {}) : [Text]).values()) { Prim.debugPrint check5 } }; From 8b7a22c579ce4ca475c7176df7ab6f0b24124081 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 13:54:27 -0700 Subject: [PATCH 08/23] Update line number --- test/run/ok/optimise-for-array-classical.tc.ok | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run/ok/optimise-for-array-classical.tc.ok b/test/run/ok/optimise-for-array-classical.tc.ok index 7c03f18fa8f..182cd34c4d7 100644 --- a/test/run/ok/optimise-for-array-classical.tc.ok +++ b/test/run/ok/optimise-for-array-classical.tc.ok @@ -1 +1 @@ -optimise-for-array-classical.mo:131.5-131.6: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) +optimise-for-array-classical.mo:199.5-199.6: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) From 2f5c68882d4348edc6eba881271c24ccd91f92f8 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 14:01:44 -0700 Subject: [PATCH 09/23] Adjust column numbers --- test/run/ok/optimise-for-array-classical.tc.ok | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run/ok/optimise-for-array-classical.tc.ok b/test/run/ok/optimise-for-array-classical.tc.ok index 182cd34c4d7..a7cca5a5a04 100644 --- a/test/run/ok/optimise-for-array-classical.tc.ok +++ b/test/run/ok/optimise-for-array-classical.tc.ok @@ -1 +1 @@ -optimise-for-array-classical.mo:199.5-199.6: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) +optimise-for-array-classical.mo:199.6-199.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) From c8c687c4884cb307dc4e1fa3f01285a001e2e9cc Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 14:08:18 -0700 Subject: [PATCH 10/23] Update Buffer implementations --- test/perf/assetstorage/Buffer.mo | 2 +- test/perf/sha256/Array.mo | 2 +- test/perf/sha256/Buffer.mo | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/perf/assetstorage/Buffer.mo b/test/perf/assetstorage/Buffer.mo index 3cdee290eaf..5872615f90f 100644 --- a/test/perf/assetstorage/Buffer.mo +++ b/test/perf/assetstorage/Buffer.mo @@ -97,7 +97,7 @@ public class Buffer (initCapacity : Nat) { }; /// Returns an [Iter](Iter.html#type.Iter) over the elements of this buffer. - public func vals() : { next : () -> ?X } = object { + public func values() : { next : () -> ?X } = object { var pos = 0; public func next() : ?X { if (pos == count) { null } else { diff --git a/test/perf/sha256/Array.mo b/test/perf/sha256/Array.mo index a2097d796cc..15366b3333f 100644 --- a/test/perf/sha256/Array.mo +++ b/test/perf/sha256/Array.mo @@ -238,7 +238,7 @@ module { [x]; }; /// Returns `xs.values()`. - public func vals(xs : [A]) : I.Iter { + public func values(xs : [A]) : I.Iter { xs.values() }; /// Returns `xs.keys()`. diff --git a/test/perf/sha256/Buffer.mo b/test/perf/sha256/Buffer.mo index d9c969cb378..dfbef842079 100644 --- a/test/perf/sha256/Buffer.mo +++ b/test/perf/sha256/Buffer.mo @@ -90,7 +90,7 @@ module { }; /// Returns an `Iter` over the elements of this buffer. - public func vals() : { next : () -> ?X } = object { + public func values() : { next : () -> ?X } = object { var pos = 0; public func next() : ?X { if (pos == count) { null } else { From dcf129a749b034eb89863535fe5ea2940579b7e3 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Mon, 3 Feb 2025 14:50:38 -0700 Subject: [PATCH 11/23] Update test --- .../ok/optimise-for-array-classical.run.ok | 11 ++++++++++ .../run/ok/optimise-for-array-classical.tc.ok | 2 +- test/run/optimise-for-array-classical.mo | 20 ++++++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/test/run/ok/optimise-for-array-classical.run.ok b/test/run/ok/optimise-for-array-classical.run.ok index 7a4990793f9..dee14ae4b47 100644 --- a/test/run/ok/optimise-for-array-classical.run.ok +++ b/test/run/ok/optimise-for-array-classical.run.ok @@ -1,12 +1,23 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello +immutable +world +hello immutable world want to see you diff --git a/test/run/ok/optimise-for-array-classical.tc.ok b/test/run/ok/optimise-for-array-classical.tc.ok index a7cca5a5a04..519045809cd 100644 --- a/test/run/ok/optimise-for-array-classical.tc.ok +++ b/test/run/ok/optimise-for-array-classical.tc.ok @@ -1 +1 @@ -optimise-for-array-classical.mo:199.6-199.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) +optimise-for-array-classical.mo:213.6-213.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) diff --git a/test/run/optimise-for-array-classical.mo b/test/run/optimise-for-array-classical.mo index 96b80c23aeb..135a68896b6 100644 --- a/test/run/optimise-for-array-classical.mo +++ b/test/run/optimise-for-array-classical.mo @@ -62,8 +62,8 @@ for (check1 in [var "hello", "mutable", "world"].vals()) { Prim.debugPrint check // FHECK-NEXT: call $print_text for (check1 in [var "hello", "mutable", "world"].values()) { Prim.debugPrint check1 }; -let array = [var "hello", "remutable", "world"]; -array[1] := "mutable"; +let array = [var "hello", "unexpected", "world"]; +array[1] := "remutable"; // FHECK-NOT: call $@immut_array_size // DON'TFHECK: i32.load offset=(5 or 9) // FHECK: i32.load offset= @@ -74,7 +74,21 @@ array[1] := "mutable"; // DON'T-FHECK: local.set $check2 // `arr` being a `VarE` already (but we rebind anyway, otherwise we open a can of worms) // later when we have path compression for variables in the backend, we can bring this back -for (check2 in array.values()) { Prim.debugPrint check2 }; +for (check2 in array.vals()) { Prim.debugPrint check2 }; + +let arrayValues = [var "hello", "unexpected", "world"]; +arrayValues[1] := "remutable"; +// FHECK-NOT: call $@immut_array_size +// DON'TFHECK: i32.load offset=(5 or 9) +// FHECK: i32.load offset= +// FHECK: i32.const 2 +// FHECK: i32.shl +// DON'T-FHECK: i32.lt_u +// DON'T-FHECK: local.get $array +// DON'T-FHECK: local.set $check2 +// `arr` being a `VarE` already (but we rebind anyway, otherwise we open a can of worms) +// later when we have path compression for variables in the backend, we can bring this back +for (check2 in arrayValues.values()) { Prim.debugPrint check2 }; // FHECK-NOT: call $@immut_array_size // DON'TFHECK: i32.load offset=(5 or 9) From efd09b3e151680a9e1bc20a9d8d786de9e279c09 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 10:31:31 -0700 Subject: [PATCH 12/23] Update tests --- test/run-drun/idl-spacebomb.mo | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/run-drun/idl-spacebomb.mo b/test/run-drun/idl-spacebomb.mo index 3fd74c052bf..2ce73b582a8 100644 --- a/test/run-drun/idl-spacebomb.mo +++ b/test/run-drun/idl-spacebomb.mo @@ -113,15 +113,6 @@ actor this { func test(m : Text, blobs : [Blob]) : async* () { let p = principalOfActor(this); - for (blob in blobs.vals()) { - debugPrint (debug_show { function = m; hex = toHex blob}); - try { - ignore await call_raw(p, m, blob); - } - catch e { - debugPrint(errorMessage(e)); - } - }; for (blob in blobs.values()) { debugPrint (debug_show { function = m; hex = toHex blob}); try { From dbbc8f2d17ce7acbb0fcd77ad734ac21ae046c6c Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 14:26:56 -0700 Subject: [PATCH 13/23] Update more expected output files --- test/run/ok/optimise-for-array-classical.run-ir.ok | 11 +++++++++++ test/run/ok/optimise-for-array-classical.run-low.ok | 11 +++++++++++ test/run/ok/optimise-for-array-classical.wasm-run.ok | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/test/run/ok/optimise-for-array-classical.run-ir.ok b/test/run/ok/optimise-for-array-classical.run-ir.ok index 7a4990793f9..dee14ae4b47 100644 --- a/test/run/ok/optimise-for-array-classical.run-ir.ok +++ b/test/run/ok/optimise-for-array-classical.run-ir.ok @@ -1,12 +1,23 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello +immutable +world +hello immutable world want to see you diff --git a/test/run/ok/optimise-for-array-classical.run-low.ok b/test/run/ok/optimise-for-array-classical.run-low.ok index 7a4990793f9..dee14ae4b47 100644 --- a/test/run/ok/optimise-for-array-classical.run-low.ok +++ b/test/run/ok/optimise-for-array-classical.run-low.ok @@ -1,12 +1,23 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello +immutable +world +hello immutable world want to see you diff --git a/test/run/ok/optimise-for-array-classical.wasm-run.ok b/test/run/ok/optimise-for-array-classical.wasm-run.ok index 7a4990793f9..dee14ae4b47 100644 --- a/test/run/ok/optimise-for-array-classical.wasm-run.ok +++ b/test/run/ok/optimise-for-array-classical.wasm-run.ok @@ -1,12 +1,23 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello +immutable +world +hello immutable world want to see you From e6194cf2c22bbe86d38c40b3894b70a148fbdb83 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 14:57:22 -0700 Subject: [PATCH 14/23] Update line number --- test/run/ok/optimise-for-array-classical.tc.ok | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run/ok/optimise-for-array-classical.tc.ok b/test/run/ok/optimise-for-array-classical.tc.ok index 519045809cd..30f3c30096f 100644 --- a/test/run/ok/optimise-for-array-classical.tc.ok +++ b/test/run/ok/optimise-for-array-classical.tc.ok @@ -1 +1 @@ -optimise-for-array-classical.mo:213.6-213.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) +optimise-for-array-classical.mo:221.6-221.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) From f0bd4d6b559f76437d1b1c3ab1c79aab8f0646f6 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 15:19:56 -0700 Subject: [PATCH 15/23] Update more tests --- test/run/ok/optimise-for-array-classical.run-ir.ok | 1 + test/run/ok/optimise-for-array-classical.run-low.ok | 1 + test/run/ok/optimise-for-array-classical.run.ok | 1 + test/run/ok/optimise-for-array-classical.wasm-run.ok | 1 + test/run/ok/optimise-for-array-enhanced.run-ir.ok | 12 ++++++++++++ test/run/ok/optimise-for-array-enhanced.run-low.ok | 12 ++++++++++++ test/run/ok/optimise-for-array-enhanced.run.ok | 12 ++++++++++++ test/run/ok/optimise-for-array-enhanced.wasm-run.ok | 12 ++++++++++++ test/run/optimise-for-array-classical.mo | 7 +++++++ test/run/optimise-for-array-enhanced.mo | 8 ++++---- 10 files changed, 63 insertions(+), 4 deletions(-) diff --git a/test/run/ok/optimise-for-array-classical.run-ir.ok b/test/run/ok/optimise-for-array-classical.run-ir.ok index dee14ae4b47..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-classical.run-ir.ok +++ b/test/run/ok/optimise-for-array-classical.run-ir.ok @@ -21,3 +21,4 @@ hello immutable world want to see you +want to see you diff --git a/test/run/ok/optimise-for-array-classical.run-low.ok b/test/run/ok/optimise-for-array-classical.run-low.ok index dee14ae4b47..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-classical.run-low.ok +++ b/test/run/ok/optimise-for-array-classical.run-low.ok @@ -21,3 +21,4 @@ hello immutable world want to see you +want to see you diff --git a/test/run/ok/optimise-for-array-classical.run.ok b/test/run/ok/optimise-for-array-classical.run.ok index dee14ae4b47..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-classical.run.ok +++ b/test/run/ok/optimise-for-array-classical.run.ok @@ -21,3 +21,4 @@ hello immutable world want to see you +want to see you diff --git a/test/run/ok/optimise-for-array-classical.wasm-run.ok b/test/run/ok/optimise-for-array-classical.wasm-run.ok index dee14ae4b47..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-classical.wasm-run.ok +++ b/test/run/ok/optimise-for-array-classical.wasm-run.ok @@ -21,3 +21,4 @@ hello immutable world want to see you +want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.run-ir.ok b/test/run/ok/optimise-for-array-enhanced.run-ir.ok index 7a4990793f9..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-enhanced.run-ir.ok +++ b/test/run/ok/optimise-for-array-enhanced.run-ir.ok @@ -1,12 +1,24 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello immutable world +hello +immutable +world +want to see you want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.run-low.ok b/test/run/ok/optimise-for-array-enhanced.run-low.ok index 7a4990793f9..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-enhanced.run-low.ok +++ b/test/run/ok/optimise-for-array-enhanced.run-low.ok @@ -1,12 +1,24 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello immutable world +hello +immutable +world +want to see you want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.run.ok b/test/run/ok/optimise-for-array-enhanced.run.ok index 7a4990793f9..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-enhanced.run.ok +++ b/test/run/ok/optimise-for-array-enhanced.run.ok @@ -1,12 +1,24 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello immutable world +hello +immutable +world +want to see you want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.wasm-run.ok b/test/run/ok/optimise-for-array-enhanced.wasm-run.ok index 7a4990793f9..15f8c12cd60 100644 --- a/test/run/ok/optimise-for-array-enhanced.wasm-run.ok +++ b/test/run/ok/optimise-for-array-enhanced.wasm-run.ok @@ -1,12 +1,24 @@ hello world hello +world +hello mutable world hello mutable world hello +remutable +world +hello +remutable +world +hello immutable world +hello +immutable +world +want to see you want to see you diff --git a/test/run/optimise-for-array-classical.mo b/test/run/optimise-for-array-classical.mo index 135a68896b6..77a87682776 100644 --- a/test/run/optimise-for-array-classical.mo +++ b/test/run/optimise-for-array-classical.mo @@ -192,6 +192,13 @@ for (check6 in check6Values.values()) { ignore check6 }; // argument to vals can have an effect too, expect it for (check7 in [].vals(Prim.debugPrint "want to see you")) { }; +// DON'TFHECK: i32.load offset=(5 or 9) +// FHECK: i32.load offset= +// FHECK: i32.const 2 +// FHECK: i32.shl +// argument to vals can have an effect too, expect it +for (check7 in [].values(Prim.debugPrint "want to see you")) { }; + // FHECK: local.set $num8 // FHECK-NOT: call $@immut_array_size // DON'TFHECK: i32.load offset=(5 or 9) diff --git a/test/run/optimise-for-array-enhanced.mo b/test/run/optimise-for-array-enhanced.mo index 14fdc462907..0704b903540 100644 --- a/test/run/optimise-for-array-enhanced.mo +++ b/test/run/optimise-for-array-enhanced.mo @@ -61,8 +61,8 @@ for (check1 in [var "hello", "mutable", "world"].vals()) { Prim.debugPrint check // CHECK: i64.add for (check1 in [var "hello", "mutable", "world"].values()) { Prim.debugPrint check1 }; -let array = [var "hello", "remutable", "world"]; -array[1] := "mutable"; +let array = [var "hello", "mutable", "world"]; +array[1] := "remutable"; // FIX-CHECK-NOT: call $@immut_array_size // DON'TCHECK: i64.load offset=17 // FIX-CHECK: i64.load offset= @@ -75,8 +75,8 @@ array[1] := "mutable"; // later when we have path compression for variables in the backend, we can bring this back for (check2 in array.vals()) { Prim.debugPrint check2 }; -let arrayValues = [var "hello", "remutable", "world"]; -arrayValues[1] := "mutable"; +let arrayValues = [var "hello", "mutable", "world"]; +arrayValues[1] := "remutable"; // FIX-CHECK-NOT: call $@immut_array_size // DON'TCHECK: i64.load offset=17 // FIX-CHECK: i64.load offset= From e4ce739749703b0f883386aaf40d81253cfe8381 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 15:34:39 -0700 Subject: [PATCH 16/23] Fix warning in test --- test/run/ok/optimise-for-array-classical.tc.ok | 1 - test/run/optimise-for-array-classical.mo | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 test/run/ok/optimise-for-array-classical.tc.ok diff --git a/test/run/ok/optimise-for-array-classical.tc.ok b/test/run/ok/optimise-for-array-classical.tc.ok deleted file mode 100644 index 30f3c30096f..00000000000 --- a/test/run/ok/optimise-for-array-classical.tc.ok +++ /dev/null @@ -1 +0,0 @@ -optimise-for-array-classical.mo:221.6-221.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) diff --git a/test/run/optimise-for-array-classical.mo b/test/run/optimise-for-array-classical.mo index 77a87682776..fce68aedaa0 100644 --- a/test/run/optimise-for-array-classical.mo +++ b/test/run/optimise-for-array-classical.mo @@ -217,7 +217,7 @@ num8 := 25; for (check8 in ["hello", "keyed", "world"].keys()) { ignore (check8 + num8) }; // polymorphic arrays should still work -func f9(array : [A]) { +func _f9(array : [A]) { for (check9 in array.keys()) { } }; From 2da245091184d26c623891448ad53350c4d0dd8c Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 15:59:36 -0700 Subject: [PATCH 17/23] Update 'enhanced' test --- test/run/ok/optimise-for-array-enhanced.tc.ok | 1 - test/run/optimise-for-array-enhanced.mo | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/run/ok/optimise-for-array-enhanced.tc.ok b/test/run/ok/optimise-for-array-enhanced.tc.ok index 2bf3ae6232f..e69de29bb2d 100644 --- a/test/run/ok/optimise-for-array-enhanced.tc.ok +++ b/test/run/ok/optimise-for-array-enhanced.tc.ok @@ -1 +0,0 @@ -optimise-for-array-enhanced.mo:124.6-124.8: warning [M0194], unused identifier f9 (delete or rename to wildcard `_` or `_f9`) diff --git a/test/run/optimise-for-array-enhanced.mo b/test/run/optimise-for-array-enhanced.mo index 0704b903540..f406dff2529 100644 --- a/test/run/optimise-for-array-enhanced.mo +++ b/test/run/optimise-for-array-enhanced.mo @@ -218,7 +218,7 @@ num8 := 25; for (check8 in ["hello", "keyed", "world"].keys()) { ignore (check8 + num8) }; // polymorphic arrays should still work -func f9(array : [A]) { +func _f9(array : [A]) { for (check9 in array.keys()) { } }; From 0cecb2ae1002a05c867acba67deb448d3e24ca98 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 16:05:28 -0700 Subject: [PATCH 18/23] Add changelog entry --- Changelog.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4f31b361472..fdbc56e9480 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,27 +4,29 @@ * motoko (`moc`) -* Support explicit, safe migration of persistent data allowing arbitrary - transformations on a selected subset of stable variables. - Additional static checks warn against possible data loss (#4812). + * Add `.values()` as an alias to `.vals()` for Arrays and Blobs. - As a very simple example: - ``` - import Nat32 "mo:base/Nat32"; + * Support explicit, safe migration of persistent data allowing arbitrary + transformations on a selected subset of stable variables. + Additional static checks warn against possible data loss (#4812). + + As a very simple example: + ``` + import Nat32 "mo:base/Nat32"; - (with migration = - func (old : { var size : Nat32 }) : { var length : Nat } { - { var length = Nat32.toNat(old.size) } + (with migration = + func (old : { var size : Nat32 }) : { var length : Nat } { + { var length = Nat32.toNat(old.size) } + } + ) + persistent actor { + var length : Nat = 0; } - ) - persistent actor { - var length : Nat = 0; - } - ``` - may be used during an upgrade to rename the stable field `size` to `length`, - and change its type from `Nat32` to `Nat`. + ``` + may be used during an upgrade to rename the stable field `size` to `length`, + and change its type from `Nat32` to `Nat`. - See the documentation for full details. + See the documentation for full details. ## 0.13.7 (2025-02-03) From 607399d49ef694add3cf7fcafd9277974da790ad Mon Sep 17 00:00:00 2001 From: Ryan Vandersmith Date: Tue, 4 Feb 2025 16:16:03 -0700 Subject: [PATCH 19/23] Update Changelog.md Co-authored-by: Gabor Greif --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index fdbc56e9480..991c48ca792 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,7 +4,7 @@ * motoko (`moc`) - * Add `.values()` as an alias to `.vals()` for Arrays and Blobs. + * Add `.values()` as an alias to `.vals()` for arrays and `Blob`s (#4876). * Support explicit, safe migration of persistent data allowing arbitrary transformations on a selected subset of stable variables. From 490553ce176a6c9a8bfb4c1f551f9b85bf87d576 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 16:52:29 -0700 Subject: [PATCH 20/23] Remove unused .tc.ok file --- test/run/ok/optimise-for-array-enhanced.tc.ok | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/run/ok/optimise-for-array-enhanced.tc.ok diff --git a/test/run/ok/optimise-for-array-enhanced.tc.ok b/test/run/ok/optimise-for-array-enhanced.tc.ok deleted file mode 100644 index e69de29bb2d..00000000000 From 01c1764f7ff164288b58c09cd40d01e09623e9ef Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 17:20:44 -0700 Subject: [PATCH 21/23] Try changing local variable name --- test/run/optimise-for-array-enhanced.mo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run/optimise-for-array-enhanced.mo b/test/run/optimise-for-array-enhanced.mo index f406dff2529..c49ee467533 100644 --- a/test/run/optimise-for-array-enhanced.mo +++ b/test/run/optimise-for-array-enhanced.mo @@ -55,11 +55,11 @@ for (check1 in [var "hello", "mutable", "world"].vals()) { Prim.debugPrint check // FIX-CHECK: i64.add // DON'TCHECK: i64.load offset=25 // CHECK: i64.load offset= -// CHECK: local.tee $check1 +// CHECK: local.tee $check1Values // CHECK: call $print_ptr // CHECK: i64.const 4 // CHECK: i64.add -for (check1 in [var "hello", "mutable", "world"].values()) { Prim.debugPrint check1 }; +for (check1Values in [var "hello", "mutable", "world"].values()) { Prim.debugPrint check1Values }; let array = [var "hello", "mutable", "world"]; array[1] := "remutable"; From b53c8a3a89419fbb467361f651f7db13036323d3 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 17:43:24 -0700 Subject: [PATCH 22/23] Simplify test --- .../ok/optimise-for-array-enhanced.run-ir.ok | 11 --- .../ok/optimise-for-array-enhanced.run-low.ok | 11 --- .../run/ok/optimise-for-array-enhanced.run.ok | 11 --- .../optimise-for-array-enhanced.wasm-run.ok | 11 --- test/run/optimise-for-array-enhanced.mo | 79 +------------------ 5 files changed, 3 insertions(+), 120 deletions(-) diff --git a/test/run/ok/optimise-for-array-enhanced.run-ir.ok b/test/run/ok/optimise-for-array-enhanced.run-ir.ok index 15f8c12cd60..2a7af297b27 100644 --- a/test/run/ok/optimise-for-array-enhanced.run-ir.ok +++ b/test/run/ok/optimise-for-array-enhanced.run-ir.ok @@ -1,24 +1,13 @@ hello world hello -world -hello -mutable -world -hello mutable world hello remutable world hello -remutable -world -hello immutable world hello -immutable -world -want to see you want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.run-low.ok b/test/run/ok/optimise-for-array-enhanced.run-low.ok index 15f8c12cd60..2a7af297b27 100644 --- a/test/run/ok/optimise-for-array-enhanced.run-low.ok +++ b/test/run/ok/optimise-for-array-enhanced.run-low.ok @@ -1,24 +1,13 @@ hello world hello -world -hello -mutable -world -hello mutable world hello remutable world hello -remutable -world -hello immutable world hello -immutable -world -want to see you want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.run.ok b/test/run/ok/optimise-for-array-enhanced.run.ok index 15f8c12cd60..2a7af297b27 100644 --- a/test/run/ok/optimise-for-array-enhanced.run.ok +++ b/test/run/ok/optimise-for-array-enhanced.run.ok @@ -1,24 +1,13 @@ hello world hello -world -hello -mutable -world -hello mutable world hello remutable world hello -remutable -world -hello immutable world hello -immutable -world -want to see you want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.wasm-run.ok b/test/run/ok/optimise-for-array-enhanced.wasm-run.ok index 15f8c12cd60..2a7af297b27 100644 --- a/test/run/ok/optimise-for-array-enhanced.wasm-run.ok +++ b/test/run/ok/optimise-for-array-enhanced.wasm-run.ok @@ -1,24 +1,13 @@ hello world hello -world -hello -mutable -world -hello mutable world hello remutable world hello -remutable -world -hello immutable world hello -immutable -world -want to see you want to see you diff --git a/test/run/optimise-for-array-enhanced.mo b/test/run/optimise-for-array-enhanced.mo index c49ee467533..e5de68d744c 100644 --- a/test/run/optimise-for-array-enhanced.mo +++ b/test/run/optimise-for-array-enhanced.mo @@ -4,19 +4,6 @@ import Prim "mo:⛔"; // CHECK: (local $check0 i64) -// CHECK-NOT: call $@immut_array_size -// DON'TCHECK: i64.load offset=17 -// CHECK: i64.load offset= -// CHECK: i64.const 2 -// CHECK: i64.shr_s -// CHECK-NEXT: i64.const 3 -// CHECK-NEXT: i64.shl -// CHECK-NEXT: i64.add -// CHECK: local.tee $check0 -// CHECK: i64.const 4 -// CHECK: i64.add -for (check0 in ["hello", "world"].vals()) { Prim.debugPrint check0 }; - // CHECK-NOT: call $@immut_array_size // DON'TCHECK: i64.load offset=17 // CHECK: i64.load offset= @@ -30,22 +17,6 @@ for (check0 in ["hello", "world"].vals()) { Prim.debugPrint check0 }; // CHECK: i64.add for (check0 in ["hello", "world"].values()) { Prim.debugPrint check0 }; - -// CHECK-NOT: call $@mut_array_size -// DON'TCHECK: i64.load offset=17 -// FIX-CHECK: i64.const 2 -// FIX-CHECK: i64.shr_s -// FIX-CHECK: i64.const 3 -// FIX-CHECK: i64.shl -// FIX-CHECK: i64.add -// DON'TCHECK: i64.load offset=25 -// CHECK: i64.load offset= -// CHECK: local.tee $check1 -// CHECK: call $print_ptr -// CHECK: i64.const 4 -// CHECK: i64.add -for (check1 in [var "hello", "mutable", "world"].vals()) { Prim.debugPrint check1 }; - // CHECK-NOT: call $@mut_array_size // DON'TCHECK: i64.load offset=17 // FIX-CHECK: i64.const 2 @@ -73,33 +44,7 @@ array[1] := "remutable"; // DON'T-CHECK: local.set $check2 // `arr` being a `VarE` already (but we rebind anyway, otherwise we open a can of worms) // later when we have path compression for variables in the backend, we can bring this back -for (check2 in array.vals()) { Prim.debugPrint check2 }; - -let arrayValues = [var "hello", "mutable", "world"]; -arrayValues[1] := "remutable"; -// FIX-CHECK-NOT: call $@immut_array_size -// DON'TCHECK: i64.load offset=17 -// FIX-CHECK: i64.load offset= -// FIX-CHECK: i64.const 2 -// FIX-CHECK: i64.shr_s -// DON'T-CHECK: i64.lt_u -// DON'T-CHECK: local.get $array -// DON'T-CHECK: local.set $check2 -// `arr` being a `VarE` already (but we rebind anyway, otherwise we open a can of worms) -// later when we have path compression for variables in the backend, we can bring this back -for (check2 in arrayValues.values()) { Prim.debugPrint check2 }; - -// FIX-CHECK-NOT: call $@immut_array_size -// DON'TCHECK: i64.load offset=17 -// FIX-CHECK: i64.load offset= -// FIX-CHECK: i64.const 2 -// FIX-CHECK-NEXT: i64.shr_s -// FIX-CHECK: i64.lt_u -// FIX-CHECK: i64.add -// DON'TCHECK: i64.load offset=25 -// FIX-CHECK: local.tee $check3 -// interfering parentheses don't disturb us -for (check3 in (((["hello", "immutable", "world"].vals())))) { Prim.debugPrint check3 }; +for (check2 in array.values()) { Prim.debugPrint check2 }; // FIX-CHECK-NOT: call $@immut_array_size // DON'TCHECK: i64.load offset=17 @@ -178,20 +123,7 @@ let check6 = [var "hello", "immutable", "world"]; check6[1] := "mutable"; // `check6` being a `VarE` already and iteration variable is named identically // this passes the IR type check, which demonstrates that no name capture happens -for (check6 in check6.vals()) { ignore check6 }; - -let check6Values = [var "hello", "immutable", "world"]; -check6Values[1] := "mutable"; -// `check6` being a `VarE` already and iteration variable is named identically -// this passes the IR type check, which demonstrates that no name capture happens -for (check6 in check6Values.values()) { ignore check6 }; - -// DON'TCHECK: i64.load offset=17 -// FIX-CHECK: i64.load offset= -// FIX-CHECK: i64.const 3 -// FIX-CHECK: i64.shl -// argument to vals can have an effect too, expect it -for (check7 in [].vals(Prim.debugPrint "want to see you")) { }; +for (check6 in check6.values()) { ignore check6 }; // DON'TCHECK: i64.load offset=17 // FIX-CHECK: i64.load offset= @@ -224,10 +156,5 @@ func _f9(array : [A]) { // make sure that one-byte-sized elements still work var sum10 : Nat8 = 0; -for (check10 in ([3, 5, 7, 11] : [Nat8]).vals()) { sum10 += check10 }; -assert sum10 == 26; - -// make sure that one-byte-sized elements still work -sum10 := 0; for (check10 in ([3, 5, 7, 11] : [Nat8]).values()) { sum10 += check10 }; -assert sum10 == 26 +assert sum10 == 26; From fb22be8a2a18dd7d76f44b9e6c4859c6038e3c43 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 4 Feb 2025 18:35:26 -0700 Subject: [PATCH 23/23] Fix --- test/run/ok/optimise-for-array-enhanced.run-ir.ok | 1 - test/run/ok/optimise-for-array-enhanced.run-low.ok | 1 - test/run/ok/optimise-for-array-enhanced.run.ok | 1 - test/run/ok/optimise-for-array-enhanced.wasm-run.ok | 1 - 4 files changed, 4 deletions(-) diff --git a/test/run/ok/optimise-for-array-enhanced.run-ir.ok b/test/run/ok/optimise-for-array-enhanced.run-ir.ok index 2a7af297b27..4e52bbbb991 100644 --- a/test/run/ok/optimise-for-array-enhanced.run-ir.ok +++ b/test/run/ok/optimise-for-array-enhanced.run-ir.ok @@ -9,5 +9,4 @@ world hello immutable world -hello want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.run-low.ok b/test/run/ok/optimise-for-array-enhanced.run-low.ok index 2a7af297b27..4e52bbbb991 100644 --- a/test/run/ok/optimise-for-array-enhanced.run-low.ok +++ b/test/run/ok/optimise-for-array-enhanced.run-low.ok @@ -9,5 +9,4 @@ world hello immutable world -hello want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.run.ok b/test/run/ok/optimise-for-array-enhanced.run.ok index 2a7af297b27..4e52bbbb991 100644 --- a/test/run/ok/optimise-for-array-enhanced.run.ok +++ b/test/run/ok/optimise-for-array-enhanced.run.ok @@ -9,5 +9,4 @@ world hello immutable world -hello want to see you diff --git a/test/run/ok/optimise-for-array-enhanced.wasm-run.ok b/test/run/ok/optimise-for-array-enhanced.wasm-run.ok index 2a7af297b27..4e52bbbb991 100644 --- a/test/run/ok/optimise-for-array-enhanced.wasm-run.ok +++ b/test/run/ok/optimise-for-array-enhanced.wasm-run.ok @@ -9,5 +9,4 @@ world hello immutable world -hello want to see you