-
Notifications
You must be signed in to change notification settings - Fork 125
feat: candid subtype check #3171
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
Merged
Merged
Changes from 134 commits
Commits
Show all changes
156 commits
Select commit
Hold shift + click to select a range
307df37
start implemenation of rts candid subtyping check
crusso 99a7a47
rustfmt
crusso 0a19a81
handle annotations; add TODO
crusso fe1a399
subtyping on variants
crusso 65ce587
records; first stab
crusso 8061aaf
fix bug
crusso c3adb82
opt cases
crusso a8713b7
Merge branch 'master' into claudio/candid-sub
crusso da679f1
basic bitset
crusso 23ce442
formatting
crusso 1309558
implement BitRel
crusso 3f676b4
edit
crusso de6f75b
add the cache
crusso fd4a6b0
simplify types
crusso c8f9416
clean up
crusso 813d2ef
formatting
crusso a7d5641
cleanup
crusso 18ee14e
wip
crusso d79c6bf
basic plumbing with reflexivity checks; fixed empty < _ case; added m…
crusso 6cd8d9f
fix 'base' bug in bitrel.rs; implement service subtyping; still broken
crusso 392fa80
test idl_sub
crusso 7e22e8d
fixed subtle stack corruption in rel_buf setup; first reasonable tests
crusso bcd5a02
check cache on entry
crusso 8e3de33
clean up annotation subtyping
crusso e42e25a
make BitRel word, not byte based; cleanup
crusso 7f3f67e
generate static type table for t and use to check idl_sub _ t
crusso 3fce657
fix broken argument typing of fun3 (missing async return) leading to …
crusso e5a18b9
fail, don't trap
crusso 60534e8
plumb proper end1; killl comments
crusso d2427e2
cleanup debug code
crusso e174af5
omit check for extended types
crusso 4a3d14b
fix
crusso 882e10e
Merge pull request #3157 from dfinity/claudio/candid-sub-deser-extend
crusso 759b40f
broken attempt at top-level option typing
crusso d163ade
fixed broken code
crusso ae93162
bump candid
crusso e8febab
update candid to PR branch
crusso 597cb2e
improve error message
crusso dd95ece
match previous behaviour
crusso 177cf91
Merge pull request #3166 from dfinity/claudio/candid-sub-deser-broken
crusso c59ccc2
cleanup and assert on IDL_con_alias
crusso b4ea0e6
implement nat <: int
crusso 23862d5
add (failing) test for opt defaulting in function types (prior to imp…
crusso 241def7
implement fancy function subtyping modulo defaulting; basic sanity tests
crusso 80d3a13
rename opt_empty_sub and extend to null type
crusso 3ac4ac8
test with multiple args
crusso 83303b9
test trailing defaults
crusso 2b8d1b0
remove depth argument
crusso 164c7de
remove dead code
crusso 465fea5
formatting
crusso eb0faec
refactor, renaming and reordering arguments
crusso fc2bb28
create and use global typtbl
crusso b2b1d93
fix silly bug
crusso f091758
share idl_sub properly
crusso 99c8e18
extend bitrel with visited bits; store both positive and negative res…
crusso 58e2a9b
refactor
crusso 6b1431f
use a labeled (trivial) loop to factor out the common failure continu…
crusso c9949d0
comments + renaming
crusso a42cb8f
fix comment
crusso 03cf17e
appease gods of rusts
crusso 5502400
thread memo table
crusso 77bef3c
fix bug
crusso 99257c1
cleanup
crusso 6682905
Merge pull request #3179 from dfinity/claudio/candid-sub-deser-opt-th…
crusso e39887d
wip: negative ho tests
crusso d7fdb43
add negative ho candid subtype tests
crusso 9c76d7d
rename test
crusso b5315f3
add test output
crusso 9ed2870
add record test
crusso 753d949
test optional record fields
crusso 8c7146a
add negative record tests
crusso 19e75c0
positive tests for recursive types
crusso e36a6cb
formatting
crusso 3c68763
found bug
crusso 1f613d1
fix bug (skip value on idl_sub failure); add test for recursive types
crusso 84faad6
test for stack underflow for dynamic stack allocations
crusso 39ef5a1
refactor RTS idl_sub and bitrel to avoid setting bits for initial ass…
crusso d311afd
add compile.ml TODO referencing ISSUE
crusso 358639d
add TODO
crusso 6f217e5
Update src/codegen/compile.ml
crusso d5d7dc5
Merge branch 'claudio/candid-sub-deser-opt-cache' of github.com:dfini…
crusso 9632450
add sanity check
crusso 14bf47d
merge with master
crusso 4059246
fix build after merge
crusso 3cf157c
Apply suggestions from code review
crusso b453486
revert use of i32s - not available here
crusso d52d84c
sort out nulls
crusso 12c5bfe
test extra args
crusso cc5bd7d
add tests for optional args/fields
crusso 298c364
bump candid tests
crusso ef7f5dd
experiments to get extended candid-tests passing
crusso 9e47504
deseralization at Non should not trap but skip and (as determined by…
crusso ebf2c02
tweak pretty printer
crusso a81d547
more pretty printer tweaks
crusso d33ef6a
more pretty printer tweaks
crusso 4475a8a
Revert "more pretty printer tweaks"
crusso fa308b0
Revert "more pretty printer tweaks"
crusso af4c27f
update test output
crusso d16342d
fix bug in pretty printer
crusso 04b6238
use offset
crusso 940ae96
exploit StaticBytes DSL to construct static type table data
crusso 8cf7e6b
double the RTS stack size
crusso 7f42dc0
use Int32.mul
crusso aa78f03
add Note(s)
crusso b4f097d
initialize memo table just once; not on every idl_sub call
crusso a1f9753
cleanup Env.typtbl_typs to use add/reg pattern; extend notes
crusso 9552dc1
use helper leb128_decode_ptr
crusso 49af67f
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso facdc3f
merge
crusso e2b020b
Apply suggestions from code review
crusso 1b2ad98
Update src/codegen/compile.ml
crusso 52d165b
adjust test output
crusso 5c7d7fb
Update src/codegen/compile.ml
crusso 5036236
merge with master
crusso 8812273
add variant refinement test
crusso afa0a17
add missing test
crusso 4ed442f
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 77c3f13
update test output (new behaviour expected)
crusso 7910720
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 94960e1
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso f8b1801
merge with master
crusso 6b9debc
Update src/codegen/compile.ml
crusso d21d5db
Update test/run-drun/idl-sub-opt-any.mo
crusso 1811b37
Update test/run-drun/idl-sub-opt-any-record.mo
crusso b002bb4
spacing
crusso e4a85c1
Merge branch 'claudio/candid-sub-deser-opt-cache' of github.com:dfini…
crusso aa19e7a
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso c3afc65
update expected test out (formatting only)
crusso b6fac2b
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 8bf4475
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 586d740
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso f34c85d
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 80fa794
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 4c71dc8
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 6d0d32d
Apply suggestions from code review
crusso daa1432
Apply suggestions from code review
crusso a4a7e21
fix syntax error and adjust check
crusso 1c089d8
add #[allow(dead_code)] to bitrel.rs untested functions
crusso e088a7e
test: unit test `bitrel.rs`, fixing bug (#3529)
crusso 8ddc970
Apply suggestions from code review
crusso 67fb862
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso e08e25b
use or-pattern
crusso bc1951d
Update rts/motoko-rts/src/idl.rs
crusso f7abe56
Update test/run-drun/idl-sub-ho-neg.mo
crusso cdb0a87
typo in comment
crusso f34d0e9
Merge branch 'claudio/candid-sub-deser-opt-cache' of github.com:dfini…
crusso eca0f0a
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso 4358396
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso ca39da1
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso a8bb5af
Changelog++
crusso a84c160
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso 8fc26ff
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso e905c3c
update test output
crusso 094794b
repoint candid dependencies to master
crusso 89b35cb
Changelog++
crusso 5fe8d42
less is more
crusso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| //! This module implements a simple subtype cache used by the compiler (in generated code) | ||
|
crusso marked this conversation as resolved.
|
||
|
|
||
| use crate::constants::WORD_SIZE; | ||
| use crate::idl_trap_with; | ||
| use crate::mem_utils::memzero; | ||
| use crate::types::Words; | ||
|
|
||
| const BITS: u32 = 2; | ||
|
|
||
| #[repr(packed)] | ||
| pub struct BitRel { | ||
| /// Pointer into the bit set | ||
| pub ptr: *mut u32, | ||
| /// Pointer to the end of the bit set | ||
| /// must allow at least 2 * size1 * size2 bits | ||
| pub end: *mut u32, | ||
| pub size1: u32, | ||
| pub size2: u32, | ||
| } | ||
|
|
||
| impl BitRel { | ||
| pub(crate) fn words(size1: u32, size2: u32) -> u32 { | ||
| return ((2 * size1 * size2 * BITS) + (usize::BITS - 1)) / usize::BITS; | ||
| } | ||
|
|
||
| pub(crate) unsafe fn init(&self) { | ||
| if (self.end as usize) < (self.ptr as usize) { | ||
| idl_trap_with("BitRel invalid fields"); | ||
| }; | ||
|
|
||
| let bytes = ((self.end as usize) - (self.ptr as usize)) as u32; | ||
| if (2 * self.size1 * self.size2 * BITS) > bytes * 8 { | ||
| idl_trap_with("BitRel not enough bytes"); | ||
| }; | ||
| memzero(self.ptr as usize, Words(bytes / WORD_SIZE)); | ||
| } | ||
|
crusso marked this conversation as resolved.
|
||
|
|
||
| unsafe fn locate_ptr_bit( | ||
| self: &Self, | ||
|
crusso marked this conversation as resolved.
Outdated
|
||
| p: bool, | ||
| i_j: u32, | ||
| j_i: u32, | ||
| bit: u32, | ||
| ) -> (*mut u32, u32) { | ||
| let size1 = self.size1; | ||
| let size2 = self.size2; | ||
| let (base, i, j) = if p { | ||
| (0, i_j, j_i) | ||
| } else { | ||
| (size1 * size2 * BITS, j_i, i_j) | ||
| }; | ||
| if i >= size1 { | ||
| idl_trap_with("BitRel i out of bounds"); | ||
| }; | ||
| if j >= size2 { | ||
| idl_trap_with("BitRel j out of bounds"); | ||
| }; | ||
| if bit >= BITS { | ||
| idl_trap_with("BitRel bit out of bounds"); | ||
| }; | ||
| let k = base + i * size2 * BITS + j + bit; | ||
| let word = (k / usize::BITS) as usize; | ||
| let bit = (k % usize::BITS) as u32; | ||
| let ptr = self.ptr.add(word); | ||
| if ptr > self.end { | ||
| idl_trap_with("BitRel ptr out of bounds"); | ||
| }; | ||
| return (ptr, bit); | ||
| } | ||
|
|
||
| unsafe fn set(&self, p: bool, i_j: u32, j_i: u32, bit: u32, v: bool) { | ||
| let (ptr, bit) = self.locate_ptr_bit(p, i_j, j_i, bit); | ||
| if v { | ||
| *ptr = *ptr | (1 << bit); | ||
| } else { | ||
| *ptr = *ptr & !(1 << bit); | ||
| } | ||
| } | ||
|
|
||
| unsafe fn get(&self, p: bool, i_j: u32, j_i: u32, bit: u32) -> bool { | ||
| let (ptr, bit) = self.locate_ptr_bit(p, i_j, j_i, bit); | ||
| let mask = 1 << bit; | ||
| return *ptr & mask == mask; | ||
| } | ||
|
|
||
| pub(crate) unsafe fn visited(&self, p: bool, i_j: u32, j_i: u32) -> bool { | ||
| self.get(p, i_j, j_i, 0) | ||
| } | ||
|
|
||
| pub(crate) unsafe fn visit(&self, p: bool, i_j: u32, j_i: u32) -> () { | ||
|
crusso marked this conversation as resolved.
Outdated
|
||
| self.set(p, i_j, j_i, 0, true) | ||
| } | ||
|
|
||
| // NB: we store related bits in negated form to avoid setting on assumption | ||
| // This code is a nop in production code. | ||
| pub(crate) unsafe fn assume(&self, p: bool, i_j: u32, j_i: u32) -> () { | ||
|
crusso marked this conversation as resolved.
Outdated
|
||
| debug_assert!(!self.get(p, i_j, j_i, 1)); | ||
| } | ||
|
|
||
| pub(crate) unsafe fn related(&self, p: bool, i_j: u32, j_i: u32) -> bool { | ||
| !self.get(p, i_j, j_i, 1) | ||
| } | ||
|
|
||
| pub(crate) unsafe fn disprove(&self, p: bool, i_j: u32, j_i: u32) -> () { | ||
|
crusso marked this conversation as resolved.
Outdated
|
||
| self.set(p, i_j, j_i, 1, true) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.