Start phasing out ibids. Other marshal improvements #2886
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Turning on the commented out instrumentation and running
yarn test
over all ofagoric-sdk
there is only this one case where the output without ibids is larger than the output with ibids. It seems to be from one of the swingset tests but I'm not sure which. Even in this unusual case, the expansion is less than 2x.This PR adds a new
cyclePolicy
of'noIbids'
. Serialization is now also parameterized by acyclePolicy
in addition to unserialization. The default unserialization policy remains'forbidCycles'
. The default serialization policy is'noIbids'
which never encodes and ibid, but does detect and reject cycles during serialization, preventing unbounded recursion.marshal
now deals withconvertSlotToVal
more like the way it has always dealt withconvertValToSlot
--- it uses its own internal bookkeeping to avoid asking these external functions redundant questions. Previously, if a slot would have been repeated, the serialization side would instead encode it with an ibid. But the unserialization side did not insist on that. If the same slot number appeared in the encoding multiple times, the unserialization would callconvertSlotToVal
redundantly, possibly producing different vals for different occurrences of the same slot number. This PR eliminates that hazard.Without ibids, we should now have the invariant that
sameStructure(x, y)
implies thatserialize(x).body === serialize(y).body
. In other word, with respect to thesameStructure
equivalence class,serialize
should now be canonical. Our pass-by-copy superstructure cannot have cycles. And it always has tree semantics whether it is originally a DAG or not. It will always unserialize to a tree.This PR expands complexity a bit in order to deal with the transition to an ibid-less world without breaking anything. Once we're on the other side of that, a lot of this will become simpler.
Attn @cwebber