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

Enhanced Orthogonal Persistence #4193

Merged
merged 311 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 249 commits
Commits
Show all changes
311 commits
Select commit Hold shift + click to select a range
5424d16
Comment refactoring
luc-blaeser Aug 25, 2023
cd8131e
Prepare memory compatibility check
luc-blaeser Aug 28, 2023
4d26bd1
Draft the memory compatibility check
luc-blaeser Aug 28, 2023
5bb8424
Add sub-type cache
luc-blaeser Aug 28, 2023
589542e
Code refactoring
luc-blaeser Aug 28, 2023
be38c4e
Add test case
luc-blaeser Aug 29, 2023
eb0366d
Add unit test
luc-blaeser Aug 29, 2023
40e1f35
Unit test for recursive types
luc-blaeser Aug 29, 2023
3d708e2
Code refactoring, added test case
luc-blaeser Aug 29, 2023
b3ac218
Upgrade check: Support mutable variables
luc-blaeser Aug 29, 2023
31df132
Continue compatibility check
luc-blaeser Aug 29, 2023
f2d67c5
Add test case
luc-blaeser Aug 30, 2023
ed8f4f7
Revert run script changes
luc-blaeser Aug 30, 2023
5bb6a39
Compatibility check: Support all stable primitive types
luc-blaeser Aug 31, 2023
963edbc
More unit tests
luc-blaeser Aug 31, 2023
b9e0167
Check array compatibility
luc-blaeser Aug 31, 2023
6c17834
Code refactoring
luc-blaeser Aug 31, 2023
7076c8a
Code refactoring
luc-blaeser Aug 31, 2023
dd001bd
Check tuple type compatibility
luc-blaeser Aug 31, 2023
66d0920
Recursive type constructor resolution
luc-blaeser Aug 31, 2023
4fb4b04
Adjust test case
luc-blaeser Aug 31, 2023
1f26c67
Support generic type resolution
luc-blaeser Sep 1, 2023
bf25c9a
Revert run script change
luc-blaeser Sep 1, 2023
82d8ca1
Add test case
luc-blaeser Sep 1, 2023
e788076
Adjust generic resolution
luc-blaeser Sep 1, 2023
ce36cf8
Check variant type compatibility
luc-blaeser Sep 1, 2023
b75497c
Adjust generic resolution
luc-blaeser Sep 1, 2023
a444c17
Support `any` and `none` type checks
luc-blaeser Sep 1, 2023
cca62ec
Check actor type compatibility
luc-blaeser Sep 1, 2023
87bb037
Rearrange type encoding
luc-blaeser Sep 1, 2023
f91d441
Work in progress: Function type compatibility
luc-blaeser Sep 1, 2023
0eb9bc4
Check function type compatibility
luc-blaeser Sep 1, 2023
e797c79
Adjust cache initialization
luc-blaeser Sep 4, 2023
5811ea3
Revert cache initialization
luc-blaeser Sep 4, 2023
e22be2b
Add unit tests
luc-blaeser Sep 4, 2023
23b54af
Support `Nat` to `Int` compatibility
luc-blaeser Sep 4, 2023
0eb283c
Fix contravariance check
luc-blaeser Sep 4, 2023
12af096
Revert test case changes
luc-blaeser Sep 4, 2023
95ef9fc
Increase reserved data segment section
luc-blaeser Sep 4, 2023
de7600a
Migrate from old serialization
luc-blaeser Sep 4, 2023
a3b9d76
Include missing `wasm` file
luc-blaeser Sep 4, 2023
394f873
Adjust test case
luc-blaeser Sep 4, 2023
7bdd8cd
Fix blob comparison in deserialization
luc-blaeser Sep 4, 2023
9c2736b
Upgrade stable memory version
luc-blaeser Sep 4, 2023
b26ac99
Code refactoring
luc-blaeser Sep 4, 2023
12fda07
Collect unused old stable variables
luc-blaeser Sep 5, 2023
a80e610
Require mutable invariance
luc-blaeser Sep 5, 2023
5cc4588
Update documentation
luc-blaeser Sep 5, 2023
0be9769
Update benchmark results (incremental GC)
luc-blaeser Sep 5, 2023
e9e91ce
Merge branch 'master' into luc/stable-heap
luc-blaeser Sep 6, 2023
87abf2f
Merge branch 'master' into luc/stable-heap
luc-blaeser Sep 6, 2023
c588239
Manual merge from master
luc-blaeser Sep 6, 2023
b10aedd
Adjust test
luc-blaeser Sep 7, 2023
3fae535
Merge branch 'master' into luc/stable-heap
luc-blaeser Sep 7, 2023
2c31217
Manual merge of region PR
luc-blaeser Sep 7, 2023
b119d80
Adjust profile report script
luc-blaeser Sep 7, 2023
568b3cc
Check compatibility with Candid subtype
luc-blaeser Sep 8, 2023
e9f91cf
Merge branch 'master' into luc/stable-heap
luc-blaeser Sep 12, 2023
9e0c490
Update documentation
luc-blaeser Sep 12, 2023
fdf601c
Downscale test for CI
luc-blaeser Sep 13, 2023
f5ca132
Change IC dependency to pull request
luc-blaeser Sep 14, 2023
0e7dcb7
Test CI build option
luc-blaeser Sep 14, 2023
0e73ccf
Update test.yml
ggreif Sep 14, 2023
051da06
Merge branch 'master' into luc/stable-heap
luc-blaeser Sep 22, 2023
0a8baf0
Remove memory reserve
luc-blaeser Sep 22, 2023
e984eeb
Manual merge RTS
luc-blaeser Sep 22, 2023
ad587dc
Manual merge compiler
luc-blaeser Sep 22, 2023
63e28a8
Update benchmark results
luc-blaeser Sep 22, 2023
69cf3d8
Fix typos and unwanted documentation deletion
luc-blaeser Sep 27, 2023
64bad1a
Merge branch 'master' into luc/stable-heap
luc-blaeser Sep 27, 2023
c4c98d7
Re-Insert Memory Reserve for Queries and Upgrades (#4158)
luc-blaeser Sep 27, 2023
cf9a37d
Optimize field search
luc-blaeser Sep 27, 2023
43bde5d
Improve memory compatibility check
luc-blaeser Sep 27, 2023
67ebe00
Merge branch 'master' into luc/stable-heap
luc-blaeser Sep 28, 2023
cce91a8
Delete unused source file
luc-blaeser Sep 28, 2023
a9756db
Downsize test
luc-blaeser Sep 28, 2023
cd85353
Exempt blob tag from Candid parsing
luc-blaeser Sep 29, 2023
89528b5
Merge branch 'master' into luc/stable-heap
luc-blaeser Oct 4, 2023
4d79801
Resolve merge conflict
luc-blaeser Oct 4, 2023
338ff5e
Support memory sanity checks
luc-blaeser Oct 6, 2023
76f2bde
Bug fix: Null comparison in pattern matching
luc-blaeser Oct 18, 2023
dde1d7e
Update benchmark results
luc-blaeser Oct 18, 2023
0329c71
Merge branch 'master' into luc/stable-heap
luc-blaeser Oct 18, 2023
bcb7f73
Upgrade IC dependency, use persistence flag
luc-blaeser Oct 20, 2023
df90d47
Merge branch 'master' into luc/stable-heap
luc-blaeser Oct 20, 2023
539e4b3
Update IC dependency
luc-blaeser Oct 20, 2023
29bc1fd
Update IC dependency
luc-blaeser Oct 27, 2023
8026ee9
Merge branch 'master' into luc/stable-heap
luc-blaeser Oct 27, 2023
ad1264b
Adjust test
luc-blaeser Oct 27, 2023
d27d9ee
Use new upgrade option
luc-blaeser Nov 3, 2023
149206d
Update IC dependency
luc-blaeser Nov 6, 2023
3dfa7ec
Merge branch 'master' into luc/stable-heap
luc-blaeser Nov 6, 2023
bd46954
Adjust test
luc-blaeser Nov 6, 2023
c19aabd
Update IC dependency
luc-blaeser Nov 8, 2023
867e3ad
Merge branch 'master' into luc/stable-heap
luc-blaeser Nov 8, 2023
4c90132
Merge branch 'master' into luc/stable-heap
luc-blaeser Nov 15, 2023
c6071a0
Manual merge conflict resolution
luc-blaeser Nov 15, 2023
a0bae88
Remove code redundancies
luc-blaeser Nov 15, 2023
7d3d017
Adjust version upgrade
luc-blaeser Nov 15, 2023
ccb43ac
Merge branch 'master' into luc/stable-heap
luc-blaeser Nov 22, 2023
8f42dc0
Add test cases
luc-blaeser Nov 22, 2023
def8030
Merge branch 'master' into luc/stable-heap
luc-blaeser Dec 15, 2023
cad375a
Manually resolve merge conflicts
luc-blaeser Dec 15, 2023
bc7a51f
Update IC dependency
luc-blaeser Dec 15, 2023
9d6cd0f
Manual merge conflict resolution
luc-blaeser Dec 15, 2023
f36196a
Remove non-incremental GC test options
luc-blaeser Dec 15, 2023
51d5242
Drop content of destabilized `Any`-typed actor field
luc-blaeser Dec 19, 2023
911e3d7
Refactor `is_primitive_type` in Candid parser and subtype check
luc-blaeser Dec 19, 2023
3981a91
Do not use the cache for the main actor type compatibility check
luc-blaeser Dec 19, 2023
0ca9ce3
Update benchmark results
luc-blaeser Dec 19, 2023
e8986b3
Adjust comment
luc-blaeser Dec 19, 2023
c455a11
Merge branch 'master' into luc/stable-heap
luc-blaeser Dec 19, 2023
d6daf39
Eliminate redundant size field in `Object` header
luc-blaeser Dec 20, 2023
acce2ff
Merge branch 'master' into luc/stable-heap
luc-blaeser Dec 20, 2023
3e24296
Merge branch 'master' into luc/stable-heap
luc-blaeser Dec 21, 2023
a613365
Record the upgrade instruction costs
luc-blaeser Dec 21, 2023
193a684
Update IC dependency
luc-blaeser Jan 4, 2024
eeceffc
Merge branch 'master' into luc/stable-heap
luc-blaeser Jan 4, 2024
e8fe7d8
Updating nix hashes
github-actions[bot] Jan 4, 2024
1e2e35d
Update IC dependency
luc-blaeser Jan 9, 2024
55216e2
Merge branch 'master' into luc/stable-heap
luc-blaeser Jan 9, 2024
bf3e05b
Merge branch 'master' into luc/stable-heap
luc-blaeser Feb 2, 2024
be54eca
Merge branch 'master' into luc/stable-heap
luc-blaeser Feb 13, 2024
1e83095
Enhanced Orthogonal Persistence: Use Passive Data Segments (32-Bit) (…
luc-blaeser Feb 22, 2024
ef2e8a5
Update IC dependency
luc-blaeser Feb 22, 2024
d8f7f04
Merge Preparation: Precise Tagging + Enhanced Orthogonal Persistence …
luc-blaeser Feb 29, 2024
5c6cb9d
Merge branch 'master' into luc/stable-heap
luc-blaeser Feb 29, 2024
ef69565
Merge branch 'master' into luc/stable-heap
luc-blaeser Feb 29, 2024
1aa3cd2
Merge branch 'master' into luc/stable-heap
luc-blaeser Mar 8, 2024
3e43218
Distinguish tuple type in memory compatibility check
luc-blaeser Sep 28, 2023
6b188e6
Merge branch 'master' into luc/stable-heap
luc-blaeser Mar 11, 2024
affc532
Manual merge conflict resolution
luc-blaeser Mar 11, 2024
fa85e2b
Adjust to new upgrade option
luc-blaeser Mar 12, 2024
743b9af
Update IC dependency
luc-blaeser Mar 13, 2024
87dfbb7
Adjust expected test result
luc-blaeser Mar 13, 2024
c500dd2
Optimize null pointer
luc-blaeser Mar 15, 2024
07c42db
Downsize test case
luc-blaeser Mar 15, 2024
c24994a
Merge branch 'master' into luc/stable-heap
luc-blaeser Mar 15, 2024
94e5257
Optimization: Enhanced Orthogonal Persistence with Object Pooling (#4…
luc-blaeser Mar 20, 2024
0067284
Merge branch 'master' into luc/stable-heap
luc-blaeser Mar 20, 2024
c3f1b56
Adjust stable memory metadata for enhanced orthogonal persistence
luc-blaeser Mar 25, 2024
7c8987b
Merge branch 'master' into luc/stable-heap
luc-blaeser Mar 25, 2024
ea702bf
Merge branch 'master' into luc/stable-heap
luc-blaeser Mar 27, 2024
f6abef5
Merge branch 'master' into luc/stable-heap
luc-blaeser Apr 5, 2024
df3c8a3
Upgrade IC dependency
luc-blaeser Apr 8, 2024
0e0227e
Undo temporary change in GitHub workflow
luc-blaeser Apr 9, 2024
bdaa979
Update design/OrthogonalPersistence.md
luc-blaeser Apr 9, 2024
524f996
Adjust sentinel value for static roots
luc-blaeser Apr 9, 2024
f81edb7
Remove obsolete comment
luc-blaeser Apr 9, 2024
7739fd6
Remove redundant IDL parsing case
luc-blaeser Apr 9, 2024
e98774b
Optimize global type table blob loads
luc-blaeser Apr 9, 2024
b34d4ce
Remove unclear comment
luc-blaeser Apr 9, 2024
f924ec8
Update rts/motoko-rts/src/persistence/compatibility.rs
luc-blaeser Apr 10, 2024
0101f0d
Side-effect-free constant function equality check
luc-blaeser Apr 10, 2024
d3c4ef4
Merge branch 'luc/stable-heap' of https://github.com/dfinity/motoko i…
luc-blaeser Apr 10, 2024
a4ff2e2
Enhanced Orthogonal Persistence: Optimize Nested Shared Objects (#4492)
luc-blaeser Apr 11, 2024
38878fd
Code refactoring: Constant blobs
luc-blaeser Apr 11, 2024
03f1e89
Format adjustment
luc-blaeser Apr 11, 2024
af1e6c9
Update src/codegen/compile.ml
luc-blaeser Apr 11, 2024
787b574
Move "object pool frozen" safety check
luc-blaeser Apr 11, 2024
3d52046
Code Refactoring: Getting rid of `Stream` interface.
luc-blaeser Apr 11, 2024
2c6875c
Handle all cases on constant equality
luc-blaeser Apr 11, 2024
24cfff4
Refactor null comparison
luc-blaeser Apr 11, 2024
7912b94
Adding upgrade option with explicit control of memory persistence
luc-blaeser Apr 11, 2024
0231575
Adjust test
luc-blaeser Apr 11, 2024
7d71daf
Bug fix: Enforce invariance for mutable objects, variants, and services
luc-blaeser Apr 12, 2024
66abe49
Refine test case
luc-blaeser Apr 12, 2024
695b3ef
Refine test case
luc-blaeser Apr 12, 2024
932f650
Adding some explanatory comments to test case
luc-blaeser Apr 12, 2024
0af485e
experiment: remove regression in idl_sub (#4497)
crusso Apr 12, 2024
87c1a52
Merge branch 'master' into luc/stable-heap
luc-blaeser Apr 12, 2024
9ff46f5
Merge branch 'master' into luc/stable-heap
luc-blaeser May 3, 2024
0efcfd5
Simplify memory compatibility check
luc-blaeser May 3, 2024
beb54ab
Refine documentation for actor field mutability variance
luc-blaeser May 3, 2024
2ed5e03
Add safety guard for temporary pointers during IDL deserialization
luc-blaeser May 3, 2024
cbc4908
Update benchmark results
luc-blaeser May 3, 2024
6d7fe43
Detect persistence mode
luc-blaeser May 14, 2024
24e6f03
Code refactoring
luc-blaeser May 14, 2024
2b53fe0
Merge branch 'master' into luc/stable-heap
luc-blaeser May 14, 2024
db2536e
Add WASI support when detecting persistence version
luc-blaeser May 14, 2024
f0d78ec
Support Wasi mode without stable memory support
luc-blaeser May 14, 2024
d9c23e8
Merge branch 'master' into luc/stable-heap
luc-blaeser May 17, 2024
6be52e1
subdivide ambiguous tags
crusso May 17, 2024
7b03506
WIP: rts for precise tagging
crusso May 17, 2024
cc85f80
used correct tags in compile.ml
crusso May 17, 2024
8430baa
Optimization
luc-blaeser May 22, 2024
bdf39b0
Update benchmark result
luc-blaeser May 22, 2024
4e1246b
Merge branch 'master' into luc/stable-heap
luc-blaeser May 24, 2024
99b2985
ugly attempt to tag allocations
crusso May 17, 2024
0b0976a
implement refined tagging; refine Blob Const (WIP); todo: refine Cons…
crusso May 18, 2024
00e5895
copy, don't alias, in blob_to_text;restrict blob_of_text; generslize …
crusso May 22, 2024
6bbfdea
refine Const.Array into Const.Array and Const.Tuple to reflect precis…
crusso May 22, 2024
4981b3a
adapt incremental array slicing; fix rts tests
crusso May 23, 2024
788f403
rust format
crusso May 23, 2024
30c91ee
adapt generational array slicing; updeate bench numbers
crusso May 24, 2024
28d98e0
fix blob comparistion in patterns
crusso May 30, 2024
4310118
refactor slicing
crusso May 30, 2024
448962f
hide encoding of array tags in helpers
crusso May 30, 2024
2cb651a
refactor array_slicing
crusso May 30, 2024
3de6cac
Merge branch 'master' into claudio/precise-heap-tags
crusso May 31, 2024
b44b133
extern array_slicing test
crusso May 31, 2024
8dbe885
add basic tag checking on unboxing of new tags
crusso May 31, 2024
ac88615
refine tags for actors and shared functions, TAG_BLOB_A and TAB_ARRAY_S
crusso May 31, 2024
6f581c6
format
crusso May 31, 2024
9f86d91
implement required coercions
crusso Jun 1, 2024
ba137c7
fix bugs; extend interpreter; rename prims; add __LINE__ to Tagged.sa…
crusso Jun 3, 2024
4d41889
Update rts/motoko-rts/src/debug.rs
crusso Jun 4, 2024
0fdbc12
document tags
crusso Jun 4, 2024
0ed4fe6
reformat; implement and use blob_of_ptr_size, blob_of_str; fix base32…
crusso Jun 5, 2024
41f8917
remove unused pattern match code from compile.ml
crusso Jun 5, 2024
1e8d0f6
use binary, not text, blob for IDL decoding check
crusso Jun 5, 2024
e8c4c19
add more assertions
crusso Jun 5, 2024
f5e97a9
assert array tag difference is even
crusso Jun 5, 2024
afde9e1
fix one broken assert (missing TAG_BLOB_A case); refactor other asserts
crusso Jun 5, 2024
34dd29d
Update rts/motoko-rts-tests/src/gc/heap.rs
crusso Jun 6, 2024
0082f1d
Update rts/motoko-rts-tests/src/gc/heap.rs
crusso Jun 7, 2024
a1f5db7
Merge branch 'claudio/precise-heap-tags' into luc/stable-heap
luc-blaeser Jun 7, 2024
b7cdc7a
Manual merge conflict resolution
luc-blaeser Jun 7, 2024
7331086
Merge branch 'master' into luc/stable-heap
luc-blaeser Jun 7, 2024
02b6b4b
Merge branch 'luc/stable-heap' into luc/stable-heap-merge-object-tagging
luc-blaeser Jun 7, 2024
8cffb0e
Fix usage of specific blob tags
luc-blaeser Jun 7, 2024
6ce9381
Merge branch 'master' into luc/stable-heap
luc-blaeser Jun 17, 2024
54266a0
Merge branch 'luc/stable-heap' into luc/stable-heap-merge-object-tagging
luc-blaeser Jun 17, 2024
1fd2b8f
Merge branch 'master' into luc/stable-heap
luc-blaeser Jun 21, 2024
d56083c
Merge branch 'luc/stable-heap' into luc/stable-heap-merge-object-tagging
luc-blaeser Jun 21, 2024
f0f432e
Code refactoring in RTS
luc-blaeser Jun 24, 2024
e7bf60c
Code refactoring in compiler backend
luc-blaeser Jun 24, 2024
5bd4bf2
Merge branch 'master' into luc/stable-heap
luc-blaeser Jun 25, 2024
0ff25ce
Manual merge conflict resolution
luc-blaeser Jun 25, 2024
e83e95b
Code refactoring, RTS project config
luc-blaeser Jun 26, 2024
e00bafb
Make memory check feature compile again
luc-blaeser Jun 27, 2024
49e0bc4
Deprecate `stableVarQuery`
luc-blaeser Jul 8, 2024
cd9588f
Merge branch 'master' into luc/stable-heap
luc-blaeser Jul 8, 2024
b8471c8
Manual merge conflict resolution
luc-blaeser Jul 8, 2024
0a8a13f
Adjust expected test output
luc-blaeser Jul 8, 2024
a210119
EOP: Using a Dedicated Stable Option Type in Persistent State (#4601)
luc-blaeser Jul 12, 2024
d3d9776
EOP: Relaxed Upgrade Compatibility Check (#4602)
luc-blaeser Jul 22, 2024
5ddd166
Merge branch 'master' into luc/stable-heap
luc-blaeser Jul 22, 2024
3b09b35
Merge branch 'master' into luc/stable-heap
luc-blaeser Aug 9, 2024
77d6b84
Manual merge conflict resolution
luc-blaeser Aug 9, 2024
d0ac733
Merge branch 'master' into luc/stable-heap
luc-blaeser Aug 9, 2024
5fb7341
Update benchmark result
luc-blaeser Aug 9, 2024
e0fa86c
Merge branch 'master' into luc/stable-heap
luc-blaeser Aug 19, 2024
6029604
Update benchmark result
luc-blaeser Aug 19, 2024
c325710
Enhanced Orthogonal Persistence (64-Bit without Graph Copy) (#4225)
luc-blaeser Aug 26, 2024
2b5e349
Merge branch 'master' into luc/stable-heap
luc-blaeser Aug 26, 2024
b4e036d
Update change log
luc-blaeser Aug 26, 2024
f609bda
Refine documentation
luc-blaeser Aug 26, 2024
71384a3
Fix documentation
luc-blaeser Aug 26, 2024
ce4fec0
Documentation improvement
luc-blaeser Aug 26, 2024
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
8 changes: 3 additions & 5 deletions bin/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare -A envs # list of expected environment variables with paths to products
# Define build products here
real[moc]=src/moc
hint[moc]="make -C $rel_root/src moc"
envs[moc]="MOC_NON_INCREMENTAL_RELEASE_RTS MOC_NON_INCREMENTAL_DEBUG_RTS MOC_INCREMENTAL_RELEASE_RTS MOC_INCREMENTAL_DEBUG_RTS"
envs[moc]="MOC_RELEASE_RTS MOC_DEBUG_RTS"
real[mo-ld]=src/mo-ld
hint[mo-ld]="make -C $rel_root/src mo-ld"
real[mo-doc]=src/mo-doc
Expand All @@ -32,10 +32,8 @@ hint[candid-tests]="make -C $rel_root/src candid-tests"

rts_hint="make -C $rel_root/rts"

real[MOC_NON_INCREMENTAL_RELEASE_RTS]=rts/mo-rts.wasm
real[MOC_NON_INCREMENTAL_DEBUG_RTS]=rts/mo-rts-debug.wasm
real[MOC_INCREMENTAL_RELEASE_RTS]=rts/mo-rts-incremental.wasm
real[MOC_INCREMENTAL_DEBUG_RTS]=rts/mo-rts-incremental-debug.wasm
real[MOC_RELEASE_RTS]=rts/mo-rts.wasm
real[MOC_DEBUG_RTS]=rts/mo-rts-debug.wasm

for var in ${envs[moc]}; do
hint[$var]=$rts_hint
Expand Down
72 changes: 21 additions & 51 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ rec {
mkdir -p $out/rts
cp mo-rts.wasm $out/rts
cp mo-rts-debug.wasm $out/rts
cp mo-rts-incremental.wasm $out/rts
cp mo-rts-incremental-debug.wasm $out/rts
'';

# This needs to be self-contained. Remove mention of nix path in debug
Expand All @@ -269,11 +267,6 @@ rec {
-t ${rtsDeps} \
-t ${rustStdDeps} \
$out/rts/mo-rts.wasm $out/rts/mo-rts-debug.wasm
remove-references-to \
-t ${nixpkgs.rustc-nightly} \
-t ${rtsDeps} \
-t ${rustStdDeps} \
$out/rts/mo-rts-incremental.wasm $out/rts/mo-rts-incremental-debug.wasm
'';

allowedRequisites = [];
Expand Down Expand Up @@ -363,26 +356,6 @@ rec {
(test_subdir dir deps).overrideAttrs {
EXTRA_MOC_ARGS = "--sanity-checks";
};

generational_gc_subdir = dir: deps:
(test_subdir dir deps).overrideAttrs {
EXTRA_MOC_ARGS = "--generational-gc";
};

snty_compacting_gc_subdir = dir: deps:
(test_subdir dir deps).overrideAttrs {
EXTRA_MOC_ARGS = "--sanity-checks --compacting-gc";
};

snty_generational_gc_subdir = dir: deps:
(test_subdir dir deps).overrideAttrs {
EXTRA_MOC_ARGS = "--sanity-checks --generational-gc";
};

snty_incremental_gc_subdir = dir: deps:
(test_subdir dir deps).overrideAttrs {
EXTRA_MOC_ARGS = "--sanity-checks --incremental-gc";
};

perf_subdir = dir: deps:
(test_subdir dir deps).overrideAttrs (args: {
Expand Down Expand Up @@ -442,23 +415,24 @@ rec {
'';
};

profiling-graphs = testDerivation {
src = test_src "perf";
buildInputs =
(with nixpkgs; [ perl wabt wasm-profiler-instrument wasm-profiler-postproc flamegraph-bin ]) ++
[ moc nixpkgs.drun ];
checkPhase = ''
patchShebangs .
type -p moc && moc --version
type -p drun && drun --help
./profile-report.sh
'';
installPhase = ''
mv _profile $out;
mkdir -p $out/nix-support
echo "report flamegraphs $out index.html" >> $out/nix-support/hydra-build-products
'';
};
# wasm-profiler is not compatible with passive data segments
# profiling-graphs = testDerivation {
# src = test_src "perf";
# buildInputs =
# (with nixpkgs; [ perl wabt wasm-profiler-instrument wasm-profiler-postproc flamegraph-bin ]) ++
# [ moc nixpkgs.drun ];
# checkPhase = ''
# patchShebangs .
# type -p moc && moc --version
# type -p drun && drun --help
# ./profile-report.sh
# '';
# installPhase = ''
# mv _profile $out;
# mkdir -p $out/nix-support
# echo "report flamegraphs $out index.html" >> $out/nix-support/hydra-build-products
# '';
#};


fix_names = builtins.mapAttrs (name: deriv:
Expand Down Expand Up @@ -497,9 +471,6 @@ rec {
# ic-ref-run = test_subdir "run-drun" [ moc ic-ref-run ];
drun = test_subdir "run-drun" [ moc nixpkgs.drun ];
drun-dbg = snty_subdir "run-drun" [ moc nixpkgs.drun ];
drun-compacting-gc = snty_compacting_gc_subdir "run-drun" [ moc nixpkgs.drun ] ;
drun-generational-gc = snty_generational_gc_subdir "run-drun" [ moc nixpkgs.drun ] ;
drun-incremental-gc = snty_incremental_gc_subdir "run-drun" [ moc nixpkgs.drun ] ;
fail = test_subdir "fail" [ moc ];
repl = test_subdir "repl" [ moc ];
ld = test_subdir "ld" ([ mo-ld ] ++ ldTestDeps);
Expand All @@ -510,7 +481,8 @@ rec {
perf = perf_subdir "perf" [ moc nixpkgs.drun ];
bench = perf_subdir "bench" [ moc nixpkgs.drun ic-wasm ];
# viper = test_subdir "viper" [ moc nixpkgs.which nixpkgs.openjdk nixpkgs.z3 ];
inherit qc lsp unit candid profiling-graphs coverage;
# TODO: profiling-graph is excluded because the underlying partity_wasm is deprecated and does not support passive data segments.
inherit qc lsp unit candid coverage;
}) // { recurseForDerivations = true; };

samples = stdenv.mkDerivation {
Expand Down Expand Up @@ -702,15 +674,13 @@ EOF
mkdir -p $out
ln -s ${base-doc} $out/base-doc
ln -s ${docs} $out/docs
ln -s ${tests.profiling-graphs} $out/flamegraphs
ln -s ${tests.coverage} $out/coverage
cd $out;
# generate a simple index.html, listing the entry points
( echo docs/overview-slides.html;
echo docs/html/motoko.html;
echo base-doc/
echo coverage/
echo flamegraphs/ ) | \
echo coverage/ ) | \
tree -H . -l --fromfile -T "Motoko build reports" > index.html
'';

Expand Down
6 changes: 5 additions & 1 deletion design/StableMemory.md → design/OldStableMemory.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Stable Memory API
# Old Stable Memory API

This describes the legacy stable memory mechanism intended to be replaced by
true orthogonal persistence where the main memory is retained across upgrades.
See `OrthogonalPersistence.md`.

The current implementation of stable variables is based on
serialization and deserialization of all stable data on upgrade. This
Expand Down
131 changes: 131 additions & 0 deletions design/OrthogonalPersistence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Orthogonal Persistence (Stable Heap)

This realizes the vision of keeping the canister main memory persistent even across upgrades and thus allows scalable upgrades.
Canister upgrades do no longer involve serialization and deserialization to and from secondary stable memory.

## Purpose
* **Instantenous upgrades**: New program versions simply resume on the existing main memory and have access to the memory-compatible data.
luc-blaeser marked this conversation as resolved.
Show resolved Hide resolved
* **Scalable upgrades**: The upgrade mechanism scales with larger heaps and in contrast to serialization, does not hit IC instruction limits.

## Broader Vision
In the longer term, this approach aims to enable **true orthogonal persistence** that is simple, flexible, efficient, and scalable.
While this version implements the runtime support for 32-bit memory, this could be leveraged to 64-bit persistent main memory in future.
As a result, the use of secondary storage (explicit stable memory, dedicated stable data structures, DB-like storage abstractions) will no longer be necessary:
Motoko developers could directly work on their normal object-oriented program structures that are automatically persisted and retained across program version changes.
With 64-bit main memory, large-scaled orthogonal persistence would be enabled, supported by the incremental GC that is designed to also scale in 64-bit.

## Design
The stable heap is based on the following main properties:
* Extension of the IC to retain main memory on upgrades.
* A long-term memory layout that is invariant to new compiled program versions.
* A fast memory compatibility check performed on each canister upgrade.
* Incremental garbage collection using a partitioned heap.

### IC Extension
As a prerequisite for the stable heap support, the IC runtime support has to be extended in order not to erase the main memory on upgrades.
This is realized in a specific IC PR (https://github.com/luc-blaeser/ic/tree/luc/stable-heap-on-release) that retains the main memory even on upgrades, similar to normal canister message execution.

### Memory Layout
In a co-design between the compiler and the runtime system, the main memory is arranged in the following structure, invariant of the compiled program version:
* Lower 4MB: Rust call stack.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@we need to be careful with making this a hard limit on the Rust stack size because, e.g. candid destabilization currently uses the Rust stack in recursive calls.

The other option might to modify deserialization to use its own shadow stack, allocated from a blob and avoiding the Rust stack alogether. I could look at that eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe the Candid deserialization (especially when migrating from classical persistence to enhanced orthogonal persistence) is the critical stack consumer. A custom temporary heap-allocated stack may be the ideal solution.

* Space between 4MB and 4.5MB: Limited reserved space Wasm data segments, only used for the Motoko runtime system.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I wonder if this is too limited. What happens if we add proper support for unicode to the rts? I think that might increase the data segments by up to 1MB (though hard to tell without doing the experiment).
If we get stuck, does that mean we can get unstuck by doing a graph copy upgrade?

Copy link
Contributor Author

@luc-blaeser luc-blaeser Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is hard to tell what a good limit is. We would have two options:

  • Make Rust use a passive data segment, e.g. importing such functionality in Rust.
  • Or doing a memory layout change with graph copy.

I believe the first approach would the more elegant one, especially if it is a bulk data segment.

* Between 4.5MB and 5MB: Persistent metadata.
* Thereafter: Dynamic heap space. Fix start address at 5MB.

### Persistent Metadata
The persistent metadata describes all anchor information for the program to resume after an upgrade.
More specifically, it comprises:
* A stable heap version that allows evolving the persistent memory layout in the future.
* The stable subset of the main actor, containing all stable variables declared in the main actor.
* A descriptor of the stable static types to check memory compatibility on upgrades.
* The runtime state of the garbage collector, including the dynamic heap metadata and memory statistics.
* A reserve for future metadata extensions.

### Compatibility Check
Upgrades are only permitted if the new program version is compatible to the old version, such that the runtime system guarantees a compatible memory structure.

Compatible changes for immutable types are equivalent to the allowed Motoko subtype relation, e.g.
* Adding or removing actor fields.
* Removing object fields.
* Adding variant fields.
* `Nat` to `Int`.
* Shared function parameter contravariance and return type covariance.

The existing IDL-subtype functionality is reused with some adjustments to check memory compatibility: The compiler generates the type descriptor, a type table, that is recorded in the persistent metadata. Upon an upgrade, the new type descriptor is compared against the existing type descriptor, and the upgrade only succeeds for compatible changes.

This compatibility check serves as an additional safety measure on top of the DFX Candid subtype check that can be bypassed by users (when ignoring a warning). Moreover, in some aspects, the memory compatibility rules differ to the Candid sub-type check:
* Top-level actor fields (`stable` fields) can change mutability (`let` to `var` and vice-versa).
* Support of variable (MutBox) with type invariance.
* Types cannot be made optional (no insertion of Option).
* Same arity for function parameters and function return types (no removed optional parameters, no additional optional results).
* Records cannot introduce additional optional fields.
* Same arity for tuple types (no insertion of optional items).
* Records and tuples are distinct.

### Garbage Collection
The implementation focuses on the incremental GC and abandons the other GCs because the GCs use different memory layouts. For example, the incremental GC uses a partitioned heap with objects carrying a forwarding pointer.

The incremental GC is chosen because it is designed to scale on large heaps and the stable heap design also aims to increase scalability. Moreover, it is suited to scale on 64-bit memory in future.

The garbage collection state needs to be persisted and retained across upgrades.
This is because the GC may not yet be completed at the time of an upgrade, such that object forwarding is still in use. The partition table is stored as part of the GC state.

The garbage collector uses two kinds of roots:
* Persistent roots: These refer to root objects that need to survive canister upgrades.
* Transient roots: These cover additional roots that are only valid in a specific version of a program and are discarded on an upgrade.

The persistent roots are registered in the persistent metadata and comprise:
* All stable variables of the main actor, only stored during an upgrade.
* The stable type table.

The transient roots are referenced by the Wasm data segments and comprise:
* All canister variables of the current version, including flexible variables.

### Main Actor
On an upgrade, the main actor is recreated and existing stable variables are recovered from the persistent root.
The remaining actor variables, the flexible fields as well as new stable variables, are (re)initialized.
As a result, the GC can collect unreachable flexible objects of previous canister versions.
Unused stable variables of former versions can also be reclaimed by the GC.

### No Static Heap
The static heap is abandoned and former static objects need to be allocated in the dynamic heap.
This is because these objects may also need to survive upgrades and must not be not overwritten by new data segments.

The incremental GC also operates on these objects, meaning that forwarding pointer resolution is also necessary for these objects.

For memory and runtime efficiency, object pooling is implemented for compile-time-known constant objects (with side-effect-free initialization), i.e. those objects are already created on program initialization/upgrade in the dynamic heap and thereafter the reference to the corresponding prefabricated object is looked up whenever the constant value is needed at runtime.

The runtime systems avoids any global Wasm variables for state that needs to be preserved on upgrades.
Instead, such global runtime state is stored in the persistent metadata.

### Wasm Data Segments
Only passive Wasm data segments are used by the compiler and runtime system. In contrast to ordinary active data segments, passive segments can be explicitly loaded to a dynamic address.

This simplifies two aspects:
* The generated Motoko code can contain arbitrarily large data segments which can be loaded to dynamic heap when needed.
* The IC can simply retain the main memory on an upgrade without needing to patch the active data segments of the new program version to the persistent memory.

However, more specific handling is required for the Rust-implemented runtime system:
The Rust-generated active data segments of the runtime system is changed to passive and loaded to the expected static address at the program start (canister initialization and upgrade).
The location and size of the RTS data segments is therefore limited to a defined reserve, see above.
This is acceptable because the RTS only uses small size for data segments (e.g. 54KB) that is independent of the compiled Motoko program.

### Null Sentinel
As an optimization, the top-level `null` pointer is represented as a constant sentinel value pointing to the last unallocated Wasm page. This allows fast null tests without involving forwarding pointer resolution of potential non-null comparand pointers.

### Migration Path
When migrating from the old serialization-based stabilization to the new stable heap, the old data is deserialized one last time from stable memory and then placed in the new stable heap layout.
Once operating on the stable heap, the system prevents downgrade attempts to the old serialization-based persistence.

### Old Stable Memory
The old stable memory remains equally accessible as secondary memory with the new support.

## Current Limitations
* Freeing old object fields: While new program versions can drop object fields, the runtime system should also delete the redundant fields of persistent objects of previous program versions. This could be realized during garbage collection when objects are copied. For this purpose, the runtime system may maintain a set of field hashes in use and consult this table during garbage collection.
* Bounded Rust call stack size: The Rust call stack size needs to be bounded and can no longer be configured by the user.
* The Wasm profiler (only used for the flamegraphs) is no longer applicable because the underlying `parity-wasm` crate lacks full support of passive data segments. A re-implementation of the profiler would be needed.

## Related PRs

* IC with stable main memory support: https://github.com/luc-blaeser/ic/tree/luc/stable-heap-on-release
* Wasm64 Support for Motoko: https://github.com/dfinity/motoko/pull/4136
11 changes: 1 addition & 10 deletions design/Stable.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,4 @@ Note: The post-upgrade method differs from expression declarations in the body o

## Implementation

Until Wasm provides multiple memories, the values of stable variables need to be written to the _stable memory_ provided by the System API.
There are multiple possible implementation strategies for this:

1. Lazy de/serialisation: the compiler generates a pre_upgrade hook that serialises a map of all stable variables to the stable memory, and a post_upgrade hook that deserialises.

2. Eager de/serialisation: reading/writing a stable variable de/serialises their value directly into a key/value store living in the stable memory.
Dealing with in-place update on mutable components requires indirections in the store via some extensible table.
It also necessitates some form of garbage collection of the stable heap.

3. Possibly other, like more smarter incremental approaches...
See `OrthogonalPersistence.md`.
Loading