project_note
Clone
0 watching0 forksRust3.6 MiBc49f5e7Tahinli1 month ago2 commits
State Guidelines
This module owns materialized document state, container stores, diff application, checkout/replay behavior, deep/shallow values, and mergeable container visibility. Read ../../../../context/mergeable-containers.md before changing mergeable child behavior.
Local Entry Points
-
value_decode.rs: iterative postcard map/list value reader. Its layout, destruction and WASM conversion contracts are in ../../../../context/deep-value-stack-safety.md. -
../state.rs:DocState, checkout/path/deep-value traversal, state replay, lifecycle, and alive-container discovery. -
container_store/: persisted KV-backed container snapshots andContainerWrapperencoding. The decoded-value cache inInnerStoreis bounded and evicted wrappers must stay re-creatable from KV; read ../../../../context/container-value-cache.md before changing read/caching paths there. -
map_state.rs,list_state.rs,richtext_state.rs,tree_state.rs,movable_list_state.rs,counter_state.rs: per-container state and snapshot codecs.richtext_state.rsalso hostsredact_dead_style_values, used by shallow-snapshot export; read ../../../../context/shallow-snapshot-style-redaction.md before changing the richtext snapshot codec or that pass.tree_state.rsbuilds tree events two ways depending on the diff mode: ../../../../context/tree-events.md. Its depth-independent traversals, snapshot order, and nested result disposal: ../../../../context/tree-depth.md.movable_list_state.rsimport validation and the Checkout-mode fallback for moves of deleted elements, plus the List/Textvalidate_diffbounds checks: ../../../../context/movable-list-op-validation.md. -
mergeable.rs: logical child edge resolution for mergeable containers. -
dead_containers_cache.rs: dead/alive tracking. Map/list deletions are final; tree and movable-list ones are dropped whenever a move could revive them; mergeable ones are never cached: ../../../../context/dead-container-cache.md. A failed import keeps its arena indices, so store entries and caches keyed byContainerIdxstay valid; it clears this cache: ../../../../context/failed-import-arena-indices.md. -
unknown_state.rsand../diff_calc/unknown.rs: forward compatibility for unknown container types. They are never created locally; theapply_diffpre-check and undo rules are in ../../../../context/unknown-containers.md.
Mergeable Rules
MapHandler::ensure_mergeable_*writes a compact marker into the parent map and returns a handler for a deterministicContainerID.- The parent map marker, not "child has ops", decides whether a mergeable child is visible.
- Non-mergeable occupants must block
ensure_mergeable_*; same-kind marker writes are idempotent; different-kind marker writes are deliberate kind changes. - Snapshot and shallow snapshot retention must preserve hidden losing-kind mergeable state.
Validation
cargo test -p loro-internal --test mergeable_cid_encodingcargo test -p loro-internal --test mergeable_containercargo test -p loro-internal import_atomicityif import or rollback is involved.
container_tree.rs traverses ephemeral shallow values into a sink. Container identity
comes from CRDT edges, including mergeable markers and Tree metadata; ordinary
values remain opaque. See bulk reads.