-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revise array iteration optimization; add tests
- Loading branch information
Showing
7 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Prim "mo:⛔"; | ||
// test we can iterate over vals and keys of largest array | ||
let max_size = 2**29; // maximum array size | ||
let a = Prim.Array_tabulate<Nat>(max_size,func i = i+1); | ||
var c = 0; | ||
for (i in a.vals()) { | ||
assert i == c+1; c += 1; | ||
} | ||
; | ||
assert c == max_size; | ||
Prim.debugPrint(debug_show c); | ||
var d = 0; | ||
for (k in a.keys()) { | ||
assert k == d; d += 1; | ||
}; | ||
assert d == max_size; | ||
Prim.debugPrint(debug_show d); | ||
|
||
Prim.Array_tabulate<Nat>(max_size+1,func i = i+1); // should trap | ||
|
||
//SKIP run | ||
//SKIP run-ir | ||
//SKIP run-low |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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<Nat>(max_size, 666); | ||
var c = 0; | ||
for (v in a.vals()) { | ||
assert v == 666; c += 1; | ||
} | ||
; | ||
assert c == max_size; | ||
Prim.debugPrint(debug_show c); | ||
var d = 0; | ||
for (k in a.keys()) { | ||
assert k == d; d += 1; | ||
}; | ||
assert d == max_size; | ||
Prim.debugPrint(debug_show d); | ||
|
||
Prim.Array_init<Nat>(max_size+1,0); // should trap | ||
|
||
//SKIP run | ||
//SKIP run-ir | ||
//SKIP run-low |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
536_870_912 | ||
536_870_912 | ||
RTS error: Array allocation too large | ||
Error: failed to run main module `_out/array-iter-max.wasm` | ||
|
||
Caused by: | ||
0: failed to invoke command default | ||
1: error while executing at wasm backtrace: | ||
0: rts_trap | ||
1: motoko_rts::trap_with_prefix::hb9fcc00b15d04524 | ||
2: motoko_rts::rts_trap_with::h22ec7878647e017a | ||
3: motoko_rts::memory::alloc_array::h29955cba75599907 | ||
4: alloc_array | ||
5: Array_tabulate | ||
6: init | ||
7: _start | ||
2: wasm trap: unreachable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Return code 134 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
536_870_912 | ||
536_870_912 | ||
RTS error: Array allocation too large | ||
Error: failed to run main module `_out/mut-array-iter-max.wasm` | ||
|
||
Caused by: | ||
0: failed to invoke command default | ||
1: error while executing at wasm backtrace: | ||
0: rts_trap | ||
1: motoko_rts::trap_with_prefix::hb9fcc00b15d04524 | ||
2: motoko_rts::rts_trap_with::h22ec7878647e017a | ||
3: motoko_rts::memory::alloc_array::h29955cba75599907 | ||
4: alloc_array | ||
5: Array_init | ||
6: init | ||
7: _start | ||
2: wasm trap: unreachable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Return code 134 |