-
Notifications
You must be signed in to change notification settings - Fork 97
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
feat: candid subtype check #3171
Merged
Merged
Conversation
This file contains 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
…issing now always true service < service case
ggreif
reviewed
Nov 1, 2022
ggreif
approved these changes
Nov 1, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@chenyan-dfinity can you check the changelog description makes sense? |
chenyan-dfinity
approved these changes
Jan 25, 2023
@chenyan-dfinity PTAL at the changelog. |
chenyan-dfinity
approved these changes
Jan 25, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
extended
boolean flag is replaced by a possibly null memo table (bit_rel_opt
) - the table isnull
for 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
cache
to 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,
visited
bit (bit 0 per (t1,t2) pair), is stored in unnegated form. The second,related
bit (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_candid
andfrom_candid
as surface syntax. #3155