Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple stable memory regions (and a new primitive type Region). #3768

Merged
merged 384 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
384 commits
Select commit Hold shift + click to select a range
02c4abe
cargo fmt
matthewhammer Mar 22, 2023
e841f89
integrate generational GC with new global in RTS for region0.
matthewhammer Mar 22, 2023
bac5505
integrate mark-compact GC with new global in RTS for region0.
matthewhammer Mar 22, 2023
aeb5a3b
remove println; fix test logic.
matthewhammer Mar 22, 2023
2718a04
impl StableMem.set_mem_size so that the compiler codegen destabilize.
matthewhammer Mar 23, 2023
17f13b3
clear the special value that we need to keep between upgrades.
matthewhammer Mar 23, 2023
109c796
nit
matthewhammer Mar 23, 2023
07ec568
revert classic unit test, stable-mem-nat8
matthewhammer Mar 23, 2023
e068c14
fix region0_load_blob
matthewhammer Mar 23, 2023
e95548d
full region API exposed through compiler.
matthewhammer Mar 23, 2023
2d69338
remove scratch file.
matthewhammer Mar 23, 2023
2643f7c
nits.
matthewhammer Mar 23, 2023
78c5f24
prints for debugging and determining skewed vs unskewed.
matthewhammer Mar 24, 2023
456e7a3
debugging blob load/store bug.
matthewhammer Mar 24, 2023
21cd5f5
avoid from-val to-val round-trip conversion in region0_load_blob.
matthewhammer Mar 24, 2023
ef1b7f4
fix the call conventions (on RTS side) for region0_store_blob. Thank…
matthewhammer Mar 24, 2023
00d9293
load/store blob unit test passes. Thanks Claudio!
matthewhammer Mar 24, 2023
338ce6c
copy fix to region_ API
matthewhammer Mar 25, 2023
7624356
starting test for isolation.
matthewhammer Mar 27, 2023
ecf89ff
plan cases for multi-region reads and writes.
matthewhammer Mar 27, 2023
470aedb
do loads block by block.
matthewhammer Mar 27, 2023
7c5d389
simple test for isolated regions.
matthewhammer Mar 27, 2023
6b04983
finish isolation test, which passes.
matthewhammer Mar 27, 2023
3effd5c
nits, and verify with println that we are doing the general case for …
matthewhammer Mar 27, 2023
8c02b4f
add flag for region new manager system.
matthewhammer Mar 28, 2023
cd1db26
reserving regions 2-15 for future use by Motoko.
matthewhammer Mar 28, 2023
db5a640
unit test for regions' serialization/deserialization as stable vars.
matthewhammer Mar 28, 2023
5402e4c
nit.
matthewhammer Mar 28, 2023
93c1b99
reading and making notes.
matthewhammer Mar 28, 2023
17a4e72
some attempt to start serializing the Region type.
matthewhammer Mar 28, 2023
b1b2c82
writing more cases, but unsure. same result.
matthewhammer Mar 28, 2023
e7bbf91
Update src/codegen/compile.ml
matthewhammer Mar 29, 2023
a3d25fd
WIP: region serialization
crusso Mar 29, 2023
9dde00f
no extra byte in size comp
crusso Mar 29, 2023
6d0bc06
WIP (still broken)
crusso Mar 29, 2023
7df427c
cleanup
crusso Mar 29, 2023
7409286
Merge branch 'claudio/msm' into multiple-stable-memory
matthewhammer Mar 30, 2023
a5b8605
revise doc, using new example (two regions for a random-access log).
matthewhammer Apr 3, 2023
b569f9a
WIP: region serialization (#3906)
crusso Apr 4, 2023
fcbf51a
reserve per-region space for GC meta data.
matthewhammer Apr 4, 2023
c99e09a
remove region0 from public API. Add comment explaining.
matthewhammer Apr 4, 2023
53232e3
fix tests for removed prim.
matthewhammer Apr 4, 2023
0057d44
simple actor that fills up stable memory in a predictable way.
matthewhammer Apr 7, 2023
26add78
simple actor that fills up stable memory in a predictable way. Wasm.
matthewhammer Apr 7, 2023
5e2bb2a
WIP
matthewhammer Apr 14, 2023
a8c69e5
Update doc/md/stablememory.md
matthewhammer Apr 14, 2023
8cc2826
Update doc/md/stablememory.md
matthewhammer Apr 14, 2023
b36bc66
Update doc/md/stablememory.md
matthewhammer Apr 14, 2023
5ec3952
Update doc/md/stablememory.md
matthewhammer Apr 14, 2023
dc4aea5
Update doc/md/stablememory.md
matthewhammer Apr 14, 2023
04375f1
Update doc/md/stablememory.md
matthewhammer Apr 14, 2023
3dc7fca
Update doc/md/examples/StableLog.mo
matthewhammer Apr 14, 2023
93a088b
Update doc/md/examples/StableLog.mo
matthewhammer Apr 14, 2023
d1cc1b7
Update doc/md/examples/StableLog.mo
matthewhammer Apr 14, 2023
2861f82
Update doc/md/examples/StableLog.mo
matthewhammer Apr 14, 2023
930425d
Update doc/md/examples/StableLog.mo
matthewhammer Apr 14, 2023
c29baac
attempt to merge conflict in default.nix
matthewhammer Apr 14, 2023
fa17241
Merge branch 'multiple-stable-memory' of github.com:dfinity/motoko in…
matthewhammer Apr 14, 2023
e165d36
update version number in StableMem, in compile.ml, for region system …
matthewhammer Apr 14, 2023
c4e251d
migration design.
matthewhammer Apr 14, 2023
1540993
nit.
matthewhammer Apr 14, 2023
284e2e6
nit.
matthewhammer Apr 14, 2023
bad61c5
attempt at corrections for accuracy.
matthewhammer Apr 15, 2023
58b6b56
current thoughts about migration path.
matthewhammer May 15, 2023
b7786a3
reflect discussion with Claudio.
matthewhammer May 16, 2023
08a9b11
nits and more details.
matthewhammer May 16, 2023
6a65db2
nits and more details.
matthewhammer May 16, 2023
87d92a7
nit.
matthewhammer May 16, 2023
489b33a
test commit.
matthewhammer May 16, 2023
054b018
Merge branch 'multiple-stable-memory' of github.com:dfinity/motoko in…
matthewhammer May 16, 2023
028e1a8
try to use default.nix from master.
matthewhammer May 16, 2023
b3f5aa5
trying to start using moc flag for regions. baby steps.
matthewhammer May 24, 2023
960b853
use the flag, and restore old stable mem code, case by case...
matthewhammer May 24, 2023
5cdbac5
use flag in every case.
matthewhammer May 24, 2023
7d0d33d
add flag to region tests.
matthewhammer May 24, 2023
fe210a5
restore flags
matthewhammer Jun 6, 2023
4c33508
test helper (temp file) and work log (another temp file).
matthewhammer Jun 14, 2023
a4a28a9
remove dead end.
matthewhammer Jun 14, 2023
eb29dd8
Update src/codegen/compile.ml
matthewhammer Jun 14, 2023
3b9d80a
Update rts/motoko-rts/src/region.rs
matthewhammer Jun 14, 2023
5ddae06
remove inaccurate comment.
matthewhammer Jun 14, 2023
6bccf80
Merge branch 'multiple-stable-memory' of github.com:dfinity/motoko in…
matthewhammer Jun 14, 2023
457c41a
update doc of RegionObject layout
matthewhammer Jun 14, 2023
0db11ea
re-run script on more tests.
matthewhammer Jun 15, 2023
56915e5
0 vs -128
matthewhammer Jun 15, 2023
cbf85bf
fix some OCaml precedence issues.
matthewhammer Jun 15, 2023
c8ac583
revert test.
matthewhammer Jun 15, 2023
41bd43a
restore files with success and failures
matthewhammer Jun 15, 2023
1ff83a0
progress.
matthewhammer Jun 20, 2023
8d87f8a
update default.nix to match master.
matthewhammer Jun 20, 2023
a249067
Update stable region PR to latest `master` branch. (#4057)
matthewhammer Jun 21, 2023
3f92146
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 21, 2023
c8a53fa
fix merge.
matthewhammer Jun 21, 2023
b24f65e
fix merge, again.
matthewhammer Jun 21, 2023
9af4831
test outcomes.
matthewhammer Jun 21, 2023
2362675
introduce max_pages arg for region growth.
matthewhammer Jun 22, 2023
6268fb6
custom max tests work now.
matthewhammer Jun 22, 2023
b593986
flag affects version number.
matthewhammer Jun 22, 2023
850720c
remove some old comments.
matthewhammer Jun 22, 2023
7da523c
fix.
matthewhammer Jun 22, 2023
724d631
update logs.
matthewhammer Jun 22, 2023
1d07ce3
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 22, 2023
7a5767c
working towards a test harness for migration logic. Adapted another d…
matthewhammer Jun 22, 2023
912ecfc
test actors are in place. test passes for the wrong reason.
matthewhammer Jun 22, 2023
5ae1bf2
nit: remove names.
matthewhammer Jun 22, 2023
715da4b
verify that moc_flags are ignored in drun scripts.
matthewhammer Jun 22, 2023
8c79714
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 22, 2023
0ba1746
support flags in .drun sources files
crusso Jun 22, 2023
5fe7449
removed old temp API.
matthewhammer Jun 22, 2023
90748e3
region_migration triggered at the right time.
matthewhammer Jun 22, 2023
01d6778
cargo fmt
matthewhammer Jun 22, 2023
55d31da
move logic from init into migration, where we have version numbers.
matthewhammer Jun 23, 2023
8112224
nit.
matthewhammer Jun 23, 2023
305138e
refactor.
matthewhammer Jun 23, 2023
1f2db85
draft of migration logic.
matthewhammer Jun 23, 2023
93392a4
debugging migration logic.
matthewhammer Jun 23, 2023
5bb617f
debugging. cargo fmt.
matthewhammer Jun 23, 2023
93aa66d
remove temp debug prints from test output.
matthewhammer Jun 23, 2023
c40d99e
progress.
matthewhammer Jun 23, 2023
0030b16
fix so migration logic works.
matthewhammer Jun 24, 2023
44a513b
migration test passes. update ok output.
matthewhammer Jun 24, 2023
a7c7a3a
fix tests.
matthewhammer Jun 24, 2023
d408cd9
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 24, 2023
9ffe763
test: allocate regions on each upgrade.
matthewhammer Jun 25, 2023
74a3ba7
fix rts tests.
matthewhammer Jun 26, 2023
9eb91af
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 26, 2023
d4f674a
fix test
matthewhammer Jun 26, 2023
e64b2a5
Merge branch 'multiple-stable-memory' of github.com:dfinity/motoko in…
matthewhammer Jun 26, 2023
1c617e9
conditional compilation
matthewhammer Jun 26, 2023
0aa76b0
fix build
matthewhammer Jun 26, 2023
d68c4e5
compiler provides stable64 indirection for Wasi target.
matthewhammer Jun 26, 2023
88bc18d
fix build.
matthewhammer Jun 26, 2023
f1051f4
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 27, 2023
7c9bde3
adjust test.
matthewhammer Jun 27, 2023
a35cf4a
Merge branch 'multiple-stable-memory' of github.com:dfinity/motoko in…
matthewhammer Jun 27, 2023
c17075f
experiment: multiple-stable-memory assertion fixes (#4077)
crusso Jun 27, 2023
0462528
drop allocation of region1, never given as root to any GC. (#4079)
matthewhammer Jun 27, 2023
09d8160
accept incorrect behavior for aliasing region0 as what we expect.
matthewhammer Jun 27, 2023
02028a1
fix underflow, and document the other '- 1' as safe. (#4084)
matthewhammer Jun 28, 2023
7b346fa
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 28, 2023
862ce00
fix comparison bug. (#4085)
matthewhammer Jun 28, 2023
bd783bf
call header.init_forward on newly-allocated region objects.
matthewhammer Jun 28, 2023
0a71922
integration of region0 and incremental GC root set.
matthewhammer Jun 28, 2023
e99e1b0
fix tests wrt region0_ptr_loc.
matthewhammer Jun 28, 2023
64c8656
fix build, 'cargo build --target=wasm32-wasi --features incremental_gc'
matthewhammer Jun 28, 2023
0964f06
GC Adjustments for Stable Regions (#4087)
luc-blaeser Jun 29, 2023
6bc8fa5
Merge branch 'master' into multiple-stable-memory
matthewhammer Jun 30, 2023
cdd7b01
update test output
crusso Jul 6, 2023
ad4b429
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 10, 2023
d6c21b8
Update design/StableRegions.md
matthewhammer Jul 10, 2023
07d0e10
Update rts/motoko-rts/src/ic0_stable.rs
matthewhammer Jul 10, 2023
77fd927
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 10, 2023
2f53218
Update rts/motoko-rts/src/ic0_stable.rs
matthewhammer Jul 10, 2023
1e87138
Update rts/motoko-rts/src/region0.rs
matthewhammer Jul 10, 2023
ebb4493
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 10, 2023
a985492
Apply suggestions from code review
matthewhammer Jul 10, 2023
9298f03
Apply suggestions from code review
matthewhammer Jul 10, 2023
32e63d1
restore original StableLog.mo in doc/examples
matthewhammer Jul 10, 2023
b59e796
restore original stablememory.md
matthewhammer Jul 10, 2023
751c997
clean up.
matthewhammer Jul 10, 2023
fd79ee8
restore docs for stable-regions, as a separate file.
matthewhammer Jul 10, 2023
6eb3368
progress.
matthewhammer Jul 13, 2023
52d8e5f
fix typo.
matthewhammer Jul 13, 2023
eb61f9c
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 13, 2023
5d9f31d
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 13, 2023
c566c4d
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 13, 2023
ca52f74
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 13, 2023
86e1b2f
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 13, 2023
3cde02e
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 13, 2023
7117c42
Update rts/motoko-rts/src/region.rs
matthewhammer Jul 13, 2023
d187237
trigger CI
chenyan-dfinity Jul 14, 2023
c59debc
merge with master
crusso Jul 17, 2023
26bd114
fix Rust
crusso Jul 17, 2023
15d4df3
Merge branch 'master' into multiple-stable-memory
crusso Jul 18, 2023
916f7c5
fix hash, as per error in CI.
matthewhammer Jul 18, 2023
caca9a3
accept bench changes
matthewhammer Jul 18, 2023
28f09b2
accept bench changes
matthewhammer Jul 18, 2023
2d2d84b
try to build a Darwin binary.
matthewhammer Jul 18, 2023
33a0d10
try again.
matthewhammer Jul 18, 2023
cae6038
refactor artifact build
chenyan-dfinity Jul 18, 2023
bfe2a28
fix
chenyan-dfinity Jul 18, 2023
45f5c8b
bugfix: define regions to be stable, but not shared, adding testcase …
crusso Jul 25, 2023
3a7dbfe
failing test repro
crusso Jul 25, 2023
b18e1e3
use StableMem as underlying page allocator, remove region_set/get_mem…
crusso Jul 24, 2023
0a2ea99
rust format
crusso Jul 24, 2023
98ad265
remove unused globals
crusso Jul 24, 2023
63f8f93
update bench output
crusso Jul 24, 2023
306c0c7
experiment: refactor enforcement of --max-stable-pages (#4145)
crusso Jul 25, 2023
03e5e92
repro for overflowing bounds check (#4148)
crusso Jul 25, 2023
34f18e6
Merge branch 'master' into multiple-stable-memory
matthewhammer Jul 25, 2023
222f6cb
Update design/StableRegions.md
crusso Jul 26, 2023
a0f6338
Update design/StableRegions.md
crusso Jul 26, 2023
2443bc5
Apply suggestions from code review
crusso Jul 26, 2023
e4731ad
fixes after accepting suggestions
crusso Jul 26, 2023
2c9348c
detect overflows; still need to reproduce error txt
crusso Jul 26, 2023
39a30ed
harmonize stablemem and region range checks, fixing bug in stablemem …
crusso Jul 27, 2023
c4afb05
update bench data
crusso Jul 27, 2023
f05e744
refactor region_recover
crusso Jul 28, 2023
d13a799
reduce allocation in stable-region-migration.drun
crusso Jul 28, 2023
317840a
early return from region_recover
crusso Jul 28, 2023
9a66d4e
refactor tests as queries to avoid disk pressure
crusso Jul 28, 2023
3b9e651
failing test for region.new trap on overflow
crusso Jul 28, 2023
a31362e
trap on out of region failure in new_region. Add test
crusso Jul 28, 2023
1102818
add asserts (commented out for imminent removal of ops used)
crusso Jul 28, 2023
f38d90f
benchmark stablemem vs regions
crusso Jul 28, 2023
f4744cf
bench *-mem.mo: remove dep on test/run-drun
crusso Jul 28, 2023
b8642de
check for grow failure
crusso Jul 29, 2023
ea1f7a7
update bench numbers
crusso Jul 29, 2023
ce3d517
add magic header MOREGION and version to layout; minor fixes
crusso Jul 29, 2023
cc43523
repro for failure to write big blobs due limitations on Rust slices (…
crusso Jul 29, 2023
5caba85
copy large blobs in halves to avoid limitations of slices; fix test o…
crusso Jul 29, 2023
a70a9c3
update bench results
crusso Jul 29, 2023
271e78d
add region/stable-mem stats to show overhead
crusso Jul 31, 2023
4810c88
* add rts_stable_mem_size and rts_logical_stable_mem_size (in pages)
crusso Jul 31, 2023
3bc522d
make regionId return Nat, not Nat32 (for extensibility/GC); update te…
crusso Aug 1, 2023
6eff1ce
Merge branch 'master' into multiple-stable-memory
crusso Aug 2, 2023
50e30d5
re-order TAG_REGION to simplify asserts
crusso Aug 10, 2023
7aa5874
reorder Region tags in compile.ml; zap trailing whitespace
crusso Aug 10, 2023
6556e17
improve Region errors
crusso Aug 10, 2023
3a3374c
implement two missing overflow checks
crusso Aug 10, 2023
91a01b2
Merge branch 'master' into multiple-stable-memory
crusso Aug 10, 2023
da55cca
widen metadata for block allocations to 32 bits (so we can count up t…
crusso Aug 10, 2023
a3a370d
Merge branch 'multiple-stable-memory' of github.com:dfinity/motoko in…
crusso Aug 10, 2023
7eed176
update perf numbers
crusso Aug 10, 2023
d94fd70
add asserts on blob reads
crusso Aug 11, 2023
2be6b81
use new bytes_of<T> to refer to memtadata sizes
crusso Aug 11, 2023
c754dd3
use memzero_bytes and memcpy_bytes
crusso Aug 11, 2023
38c13cc
add const LAST_RESERVED_REGION_ID; refactor region_reserve_id_span
crusso Aug 11, 2023
f765f71
add assertions preventing overflow
crusso Aug 11, 2023
3a62122
optimize vector access using single u16 read/write
crusso Aug 11, 2023
052c808
restore deleted bench results
crusso Aug 11, 2023
2fd28e4
add missing barrier
crusso Aug 11, 2023
11c7fc0
refactor ic0_stable.rs to stable_mem.rs, distinguishing ic0 from moc …
crusso Aug 12, 2023
94bf29e
flatten stable_mem::util into stable_mem
crusso Aug 12, 2023
ee79edf
Merge branch 'master' into multiple-stable-memory
crusso Aug 12, 2023
da0e23f
experiment: lazy migration for stable memory for regions (#4171)
crusso Aug 16, 2023
fef65b2
regions: add missing write-barrier plus refactoring (#4172)
crusso Aug 18, 2023
0c2a7ae
regions: refactor for 64-bit region ids, dropping region table (#4176)
crusso Aug 23, 2023
365d1b8
Merge branch 'master' into multiple-stable-memory
crusso Aug 29, 2023
682c592
regions: reduce metadata overhead of code using Regions before ESM fr…
crusso Sep 5, 2023
3f76b76
experiment: increase EXTRA_BATCHES arg to drun (#4186)
crusso Sep 5, 2023
c427556
documentation and changelog for region types (#4185)
crusso Sep 5, 2023
4f8c721
Merge remote-tracking branch 'origin/master' into multiple-stable-memory
crusso Sep 5, 2023
2d9a913
update doc; add Region.md; make StableMultiLog.mo checkable
crusso Sep 5, 2023
b856317
doc tweaks
crusso Sep 5, 2023
1a5c233
document --stable-regions flag
crusso Sep 5, 2023
0300613
describe type Region and new; refactor example; rename self to state
crusso Sep 5, 2023
27a8adf
Merge branch 'master' into multiple-stable-memory
crusso Sep 5, 2023
7765630
update design doc
crusso Sep 6, 2023
f5387d0
restore stable-region-blob.mo; extract stable-region-misc.mo
crusso Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mo_frontend/coverage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ let pick_val vs = function
| T.Blob
| T.Error
| T.Principal
| T.Region
| T.Float -> Any

let rec expand_notval t n vs : desc list =
Expand Down
1 change: 1 addition & 0 deletions src/mo_idl/mo_to_idl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ let prim p =
| Text -> I.PrimT I.Text
| Blob -> I.BlobT
| Principal -> I.PrincipalT
| Region -> assert false
| Error -> assert false

let rec typ t =
Expand Down
1 change: 1 addition & 0 deletions src/mo_types/arrange_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let prim = function
| Blob -> Atom "Blob"
| Error -> Atom "Error"
| Principal -> Atom "Principal"
| Region -> Atom "Region"

let con c = Atom (Type.string_of_con c)

Expand Down
1 change: 1 addition & 0 deletions src/mo_types/typ_hash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ let prim = function
| Blob -> "B"
| Error -> "E"
| Principal -> "P"
| Region -> "R"

let rec go = function
| Prim p -> ((Nullary, prim p), [])
Expand Down
7 changes: 6 additions & 1 deletion src/mo_types/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type prim =
| Blob (* IR use: Packed representation, vec u8 IDL type *)
| Error
| Principal
| Region

type t = typ
and typ =
Expand Down Expand Up @@ -88,6 +89,7 @@ let tag_prim = function
| Blob -> 15
| Error -> 16
| Principal -> 17
| Region -> 18

let tag_func_sort = function
| Local -> 0
Expand Down Expand Up @@ -313,6 +315,7 @@ let blob = Prim Blob
let error = Prim Error
let char = Prim Char
let principal = Prim Principal
let region = Prim Region

let fields flds =
List.sort compare_field
Expand Down Expand Up @@ -367,6 +370,7 @@ let prim = function
| "Blob" -> Blob
| "Error" -> Error
| "Principal" -> Principal
| "Region" -> Region
| s -> raise (Invalid_argument ("Type.prim: " ^ s))

let seq = function [t] -> t | ts -> Tup ts
Expand Down Expand Up @@ -703,7 +707,7 @@ let rec span = function
| Con _ as t -> span (promote t)
| Prim Null -> Some 1
| Prim Bool -> Some 2
| Prim (Nat | Int | Float | Text | Blob | Error | Principal) -> None
| Prim (Nat | Int | Float | Text | Blob | Error | Principal | Region) -> None
| Prim (Nat8 | Int8) -> Some 0x100
| Prim (Nat16 | Int16) -> Some 0x10000
| Prim (Nat32 | Int32 | Nat64 | Int64 | Char) -> None (* for all practical purposes *)
Expand Down Expand Up @@ -1417,6 +1421,7 @@ let string_of_prim = function
| Blob -> "Blob"
| Error -> "Error"
| Principal -> "Principal"
| Region -> "Region"

let string_of_obj_sort = function
| Object -> ""
Expand Down
2 changes: 2 additions & 0 deletions src/mo_types/type.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type prim =
| Blob (* IR use: Packed representation, vec u8 IDL type *)
| Error
| Principal
| Region

type t = typ

Expand Down Expand Up @@ -93,6 +94,7 @@ val blob : typ
val error : typ
val char : typ
val principal : typ
val region : typ

val sum : (lab * typ) list -> typ
val obj : obj_sort -> (lab * typ) list -> typ
Expand Down
1 change: 1 addition & 0 deletions src/prelude/prelude.mo
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ type Text = prim "Text";
type Blob = prim "Blob";
type Error = prim "Error";
type Principal = prim "Principal";
type Region = prim "Region";
72 changes: 72 additions & 0 deletions src/prelude/prim.mo
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Types = {
public type Blob = prim "Blob";
public type Error = prim "Error";
public type Principal = prim "Principal";
public type Memory = prim "Memory";
matthewhammer marked this conversation as resolved.
Show resolved Hide resolved
};

func abs(x : Int) : Nat { (prim "abs" : Int -> Nat) x };
Expand Down Expand Up @@ -370,6 +371,77 @@ func stableMemoryStoreBlob(offset : Nat64, val : Blob) : () =
func stableVarQuery() : shared query () -> async {size : Nat64} =
(prim "stableVarQuery" : () -> (shared query () -> async {size : Nat64})) () ;

// multiple-stable memory

func multStableMemoryNew() : Memory =
matthewhammer marked this conversation as resolved.
Show resolved Hide resolved
(prim "multStableMemoryNew" : () -> Memory) ();

func multStableMemorySize(Memory : m) : Nat64 =
(prim "multStableMemorySize" : Memory -> Nat64) m;

func multStableMemoryGrow(Memory : m, pages : Nat64) : Nat64 =
(prim "multStableMemoryGrow" : (Memory, Nat64) -> Nat64) (m, pages);

func multStableMemoryLoadNat32(Memory : m, offset : Nat64) : Nat32 =
(prim "multStableMemoryLoadNat32" : (Memory, Nat64) -> Nat32) (m, offset);

func multStableMemoryStoreNat32(Memory : m, offset : Nat64, val : Nat32) : () =
(prim "multStableMemoryStoreNat32" : (Memory, Nat64, Nat32) -> ()) (m, offset, val);

func multStableMemoryLoadNat8(Memory : m, offset : Nat64) : Nat8 =
(prim "multStableMemoryLoadNat8" : (Memory, Nat64) -> Nat8) (m, offset);

func multStableMemoryStoreNat8(Memory : m, offset : Nat64, val : Nat8) : () =
(prim "multStableMemoryStoreNat8" : (Memory, Nat64, Nat8) -> ()) (m, offset, val);

func multStableMemoryLoadNat16(Memory : m, offset : Nat64) : Nat16 =
(prim "multStableMemoryLoadNat16" : (Memory, Nat64) -> Nat16) (m, offset);

func multStableMemoryStoreNat16(Memory : m, offset : Nat64, val : Nat16) : () =
(prim "multStableMemoryStoreNat16" : (Memory, Nat64, Nat16) -> ()) (m, offset, val);

func multStableMemoryLoadNat64(Memory : m, offset : Nat64) : Nat64 =
(prim "multStableMemoryLoadNat64" : (Memory, Nat64) -> Nat64) (m, offset);

func multStableMemoryStoreNat64(Memory : m, offset : Nat64, val : Nat64) : () =
(prim "multStableMemoryStoreNat64" : (Memory, Nat64, Nat64) -> ()) (m, offset, val);

func multStableMemoryLoadInt32(Memory : m, offset : Nat64) : Int32 =
(prim "multStableMemoryLoadInt32" : (Memory, Nat64) -> Int32) (m, offset);

func multStableMemoryStoreInt32(Memory : m, offset : Nat64, val : Int32) : () =
(prim "multStableMemoryStoreInt32" : (Memory, Nat64, Int32) -> ()) (m, offset, val);

func multStableMemoryLoadInt8(Memory : m, offset : Nat64) : Int8 =
(prim "multStableMemoryLoadInt8" : (Memory, Nat64) -> Int8) (m, offset);

func multStableMemoryStoreInt8(Memory : m, offset : Nat64, val : Int8) : () =
(prim "multStableMemoryStoreInt8" : (Memory, Nat64, Int8) -> ()) (m, offset, val);

func multStableMemoryLoadInt16(Memory : m, offset : Nat64) : Int16 =
(prim "multStableMemoryLoadInt16" : (Memory, Nat64) -> Int16) (m, offset);

func multStableMemoryStoreInt16(Memory : m, offset : Nat64, val : Int16) : () =
(prim "multStableMemoryStoreInt16" : (Memory, Nat64, Int16) -> ()) (m, offset, val);

func multStableMemoryLoadInt64(Memory : m, offset : Nat64) : Int64 =
(prim "multStableMemoryLoadInt64" : (Memory, Nat64) -> Int64) (m, offset);

func multStableMemoryStoreInt64(Memory : m, offset : Nat64, val : Int64) : () =
(prim "multStableMemoryStoreInt64" : (Memory, Nat64, Int64) -> ()) (m, offset, val);

func multStableMemoryLoadFloat(Memory : m, offset : Nat64) : Float =
(prim "multStableMemoryLoadFloat" : (Memory, Nat64) -> Float) (m, offset);

func multStableMemoryStoreFloat(Memory : m, offset : Nat64, val : Float) : () =
(prim "multStableMemoryStoreFloat" : (Memory, Nat64, Float) -> ()) (m, offset, val);

func multStableMemoryLoadBlob(Memory : m, offset : Nat64, size : Nat) : Blob =
(prim "multStableMemoryLoadBlob" : (Memory, Nat64, Nat) -> Blob) (m, offset, size);

func multStableMemoryStoreBlob(Memory : m, offset : Nat64, val : Blob) : () =
(prim "multStableMemoryStoreBlob" : (Memory, Nat64, Blob) -> ()) (m, offset, val);


let call_raw = @call_raw;

Expand Down