feat: candid subtype check#3171
Merged
mergify[bot] merged 156 commits intomasterfrom Jan 25, 2023
Merged
Conversation
…issing now always true service < service case
ggreif
reviewed
Nov 1, 2022
ggreif
approved these changes
Nov 1, 2022
Contributor
ggreif
left a comment
There was a problem hiding this comment.
Looks good, but it is a lot.
* unit test for bitrel * add unit test revealing bug; fix bug * optimize locate_ptr_bit * optimize locate_ptr_bit
Co-authored-by: Gabor Greif <gabor@dfinity.org> Co-authored-by: Luc Blaeser <112870813+luc-blaeser@users.noreply.github.com>
Co-authored-by: Gabor Greif <gabor@dfinity.org>
…ty/motoko into claudio/candid-sub-deser-opt-cache
Contributor
Author
|
@chenyan-dfinity can you check the changelog description makes sense? |
chenyan-dfinity
approved these changes
Jan 25, 2023
Contributor
Author
|
@chenyan-dfinity PTAL at the changelog. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Builds on (in reverse order)
Since this PR includes more test and fixes to previous PR, its probably best to just review this one as a diff against master:
Over #3170, this PR:
Introduces a stack allocated memo table allocated on entry to deserialize and shared amongst all recursive calls. The
extendedboolean flag is replaced by a possibly null memo table (bit_rel_opt) - the table isnullfor extended deserialization of stable values (for which subtype checks on references are just ommitted since unnecessary).Generalises the subtype check and bitrel cache to support sharing across multiple calls and caching of both positive and negative subtype test results:
Adds 1 bit per pair of types in subtype
cacheto record true/false outcome separately from plain addition to cache.Adjust each exit point that returns false to invalidate the positive subtyping assumption already in the cache (thus recording the negative result in the cache).
Unfortunately caching negative results doubles the space required to store the cache (we now need 2 bits, not 1, for every possible pair of type indices).
This subtyping between type tables with 128 entries each will consume 8K = (2 * 2 * 128 * 128/ 8) of stack space. Not great, but not terrible either.
The first,
visitedbit (bit 0 per (t1,t2) pair), is stored in unnegated form. The second,relatedbit (bit 1 per (t1,t2) type pair), is stored in negated form so that assuming the relation holds when first visited is actually a no-op (since the matrix is initialized with zero bits).Also fixes a lurking bug where I failed to skip the value when the subtype check fails (meaning previous PR were buggy).
only produce global type table entries in unextended deserialization.Not worth the effort.to_candidandfrom_candidas surface syntax. #3155