Skip to content
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 156 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 138 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 Feb 18, 2022
99a7a47
rustfmt
crusso Feb 18, 2022
0a19a81
handle annotations; add TODO
crusso Feb 19, 2022
fe1a399
subtyping on variants
crusso Feb 19, 2022
65ce587
records; first stab
crusso Feb 21, 2022
8061aaf
fix bug
crusso Feb 21, 2022
c3adb82
opt cases
crusso Feb 28, 2022
a8713b7
Merge branch 'master' into claudio/candid-sub
crusso Mar 3, 2022
da679f1
basic bitset
crusso Mar 3, 2022
23ce442
formatting
crusso Mar 3, 2022
1309558
implement BitRel
crusso Mar 3, 2022
3f676b4
edit
crusso Mar 3, 2022
de6f75b
add the cache
crusso Mar 3, 2022
fd4a6b0
simplify types
crusso Mar 3, 2022
c8f9416
clean up
crusso Mar 3, 2022
813d2ef
formatting
crusso Mar 3, 2022
a7d5641
cleanup
crusso Mar 3, 2022
18ee14e
wip
crusso Mar 5, 2022
d79c6bf
basic plumbing with reflexivity checks; fixed empty < _ case; added m…
crusso Mar 5, 2022
6cd8d9f
fix 'base' bug in bitrel.rs; implement service subtyping; still broken
crusso Mar 6, 2022
392fa80
test idl_sub
crusso Mar 9, 2022
7e22e8d
fixed subtle stack corruption in rel_buf setup; first reasonable tests
crusso Mar 10, 2022
bcd5a02
check cache on entry
crusso Mar 10, 2022
8e3de33
clean up annotation subtyping
crusso Mar 11, 2022
e42e25a
make BitRel word, not byte based; cleanup
crusso Mar 11, 2022
7f3f67e
generate static type table for t and use to check idl_sub _ t
crusso Mar 11, 2022
3fce657
fix broken argument typing of fun3 (missing async return) leading to …
crusso Mar 14, 2022
e5a18b9
fail, don't trap
crusso Mar 15, 2022
60534e8
plumb proper end1; killl comments
crusso Mar 15, 2022
d2427e2
cleanup debug code
crusso Mar 15, 2022
e174af5
omit check for extended types
crusso Mar 15, 2022
4a3d14b
fix
crusso Mar 16, 2022
882e10e
Merge pull request #3157 from dfinity/claudio/candid-sub-deser-extend
crusso Mar 16, 2022
759b40f
broken attempt at top-level option typing
crusso Mar 17, 2022
d163ade
fixed broken code
crusso Mar 17, 2022
ae93162
bump candid
crusso Mar 17, 2022
e8febab
update candid to PR branch
crusso Mar 18, 2022
597cb2e
improve error message
crusso Mar 18, 2022
dd95ece
match previous behaviour
crusso Mar 18, 2022
177cf91
Merge pull request #3166 from dfinity/claudio/candid-sub-deser-broken
crusso Mar 21, 2022
c59ccc2
cleanup and assert on IDL_con_alias
crusso Mar 21, 2022
b4ea0e6
implement nat <: int
crusso Mar 21, 2022
23862d5
add (failing) test for opt defaulting in function types (prior to imp…
crusso Mar 21, 2022
241def7
implement fancy function subtyping modulo defaulting; basic sanity tests
crusso Mar 21, 2022
80d3a13
rename opt_empty_sub and extend to null type
crusso Mar 21, 2022
3ac4ac8
test with multiple args
crusso Mar 21, 2022
83303b9
test trailing defaults
crusso Mar 21, 2022
2b8d1b0
remove depth argument
crusso Mar 22, 2022
164c7de
remove dead code
crusso Mar 22, 2022
465fea5
formatting
crusso Mar 22, 2022
eb0faec
refactor, renaming and reordering arguments
crusso Mar 22, 2022
fc2bb28
create and use global typtbl
crusso Mar 23, 2022
b2b1d93
fix silly bug
crusso Mar 23, 2022
f091758
share idl_sub properly
crusso Mar 23, 2022
99c8e18
extend bitrel with visited bits; store both positive and negative res…
crusso Mar 24, 2022
58e2a9b
refactor
crusso Mar 24, 2022
6b1431f
use a labeled (trivial) loop to factor out the common failure continu…
crusso Mar 24, 2022
c9949d0
comments + renaming
crusso Mar 24, 2022
a42cb8f
fix comment
crusso Mar 24, 2022
03cf17e
appease gods of rusts
crusso Mar 24, 2022
5502400
thread memo table
crusso Apr 1, 2022
77bef3c
fix bug
crusso Apr 1, 2022
99257c1
cleanup
crusso Apr 1, 2022
6682905
Merge pull request #3179 from dfinity/claudio/candid-sub-deser-opt-th…
crusso Apr 1, 2022
e39887d
wip: negative ho tests
crusso Apr 4, 2022
d7fdb43
add negative ho candid subtype tests
crusso Apr 4, 2022
9c76d7d
rename test
crusso Apr 4, 2022
b5315f3
add test output
crusso Apr 4, 2022
9ed2870
add record test
crusso Apr 4, 2022
753d949
test optional record fields
crusso Apr 4, 2022
8c7146a
add negative record tests
crusso Apr 4, 2022
19e75c0
positive tests for recursive types
crusso Apr 4, 2022
e36a6cb
formatting
crusso Apr 5, 2022
3c68763
found bug
crusso Apr 5, 2022
1f613d1
fix bug (skip value on idl_sub failure); add test for recursive types
crusso Apr 6, 2022
84faad6
test for stack underflow for dynamic stack allocations
crusso Apr 6, 2022
39ef5a1
refactor RTS idl_sub and bitrel to avoid setting bits for initial ass…
crusso Apr 6, 2022
d311afd
add compile.ml TODO referencing ISSUE
crusso Apr 6, 2022
358639d
add TODO
crusso Apr 6, 2022
6f217e5
Update src/codegen/compile.ml
crusso Apr 6, 2022
d5d7dc5
Merge branch 'claudio/candid-sub-deser-opt-cache' of github.com:dfini…
crusso Apr 6, 2022
9632450
add sanity check
crusso Apr 6, 2022
14bf47d
merge with master
crusso Apr 6, 2022
4059246
fix build after merge
crusso Apr 6, 2022
3cf157c
Apply suggestions from code review
crusso Apr 7, 2022
b453486
revert use of i32s - not available here
crusso Apr 7, 2022
d52d84c
sort out nulls
crusso Apr 8, 2022
12c5bfe
test extra args
crusso Apr 8, 2022
cc5bd7d
add tests for optional args/fields
crusso Apr 8, 2022
298c364
bump candid tests
crusso Apr 8, 2022
ef7f5dd
experiments to get extended candid-tests passing
crusso Apr 9, 2022
9e47504
deseralization at Non should not trap but skip and (as determined by…
crusso Apr 9, 2022
ebf2c02
tweak pretty printer
crusso Apr 11, 2022
a81d547
more pretty printer tweaks
crusso Apr 11, 2022
d33ef6a
more pretty printer tweaks
crusso Apr 11, 2022
4475a8a
Revert "more pretty printer tweaks"
crusso Apr 11, 2022
fa308b0
Revert "more pretty printer tweaks"
crusso Apr 11, 2022
af4c27f
update test output
crusso Apr 11, 2022
d16342d
fix bug in pretty printer
crusso Apr 12, 2022
04b6238
use offset
crusso Apr 12, 2022
940ae96
exploit StaticBytes DSL to construct static type table data
crusso Apr 12, 2022
8cf7e6b
double the RTS stack size
crusso Apr 12, 2022
7f42dc0
use Int32.mul
crusso Apr 12, 2022
aa78f03
add Note(s)
crusso Apr 12, 2022
b4f097d
initialize memo table just once; not on every idl_sub call
crusso Apr 12, 2022
a1f9753
cleanup Env.typtbl_typs to use add/reg pattern; extend notes
crusso Apr 12, 2022
9552dc1
use helper leb128_decode_ptr
crusso Apr 12, 2022
49af67f
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso Apr 12, 2022
facdc3f
merge
crusso Apr 19, 2022
e2b020b
Apply suggestions from code review
crusso Apr 19, 2022
1b2ad98
Update src/codegen/compile.ml
crusso Apr 19, 2022
52d165b
adjust test output
crusso Apr 19, 2022
5c7d7fb
Update src/codegen/compile.ml
crusso Apr 20, 2022
5036236
merge with master
crusso Apr 21, 2022
8812273
add variant refinement test
crusso Apr 22, 2022
afa0a17
add missing test
crusso Apr 22, 2022
4ed442f
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Jun 8, 2022
77c3f13
update test output (new behaviour expected)
crusso Jun 7, 2022
7910720
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Jul 18, 2022
94960e1
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Aug 2, 2022
f8b1801
merge with master
crusso Sep 1, 2022
6b9debc
Update src/codegen/compile.ml
crusso Sep 1, 2022
d21d5db
Update test/run-drun/idl-sub-opt-any.mo
crusso Sep 1, 2022
1811b37
Update test/run-drun/idl-sub-opt-any-record.mo
crusso Sep 1, 2022
b002bb4
spacing
crusso Sep 13, 2022
e4a85c1
Merge branch 'claudio/candid-sub-deser-opt-cache' of github.com:dfini…
crusso Sep 13, 2022
aa19e7a
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Sep 29, 2022
c3afc65
update expected test out (formatting only)
crusso Oct 3, 2022
b6fac2b
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Oct 6, 2022
8bf4475
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Oct 6, 2022
586d740
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Oct 26, 2022
f34c85d
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Oct 26, 2022
80fa794
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Oct 27, 2022
4c71dc8
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Oct 27, 2022
6d0d32d
Apply suggestions from code review
crusso Oct 28, 2022
daa1432
Apply suggestions from code review
crusso Oct 28, 2022
a4a7e21
fix syntax error and adjust check
crusso Oct 28, 2022
1c089d8
add #[allow(dead_code)] to bitrel.rs untested functions
crusso Oct 28, 2022
e088a7e
test: unit test `bitrel.rs`, fixing bug (#3529)
crusso Nov 1, 2022
8ddc970
Apply suggestions from code review
crusso Nov 1, 2022
67fb862
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Nov 1, 2022
e08e25b
use or-pattern
crusso Nov 1, 2022
bc1951d
Update rts/motoko-rts/src/idl.rs
crusso Nov 1, 2022
f7abe56
Update test/run-drun/idl-sub-ho-neg.mo
crusso Nov 1, 2022
cdb0a87
typo in comment
crusso Nov 1, 2022
f34d0e9
Merge branch 'claudio/candid-sub-deser-opt-cache' of github.com:dfini…
crusso Nov 1, 2022
eca0f0a
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Nov 3, 2022
4358396
Merge branch 'master' into claudio/candid-sub-deser-opt-cache
crusso Nov 28, 2022
ca39da1
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso Jan 24, 2023
a8bb5af
Changelog++
crusso Jan 24, 2023
a84c160
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso Jan 25, 2023
8fc26ff
Merge remote-tracking branch 'origin/master' into claudio/candid-sub-…
crusso Jan 25, 2023
e905c3c
update test output
crusso Jan 25, 2023
094794b
repoint candid dependencies to master
crusso Jan 25, 2023
89b35cb
Changelog++
crusso Jan 25, 2023
5fe8d42
less is more
crusso Jan 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"candid": {
"branch": "master",
"branch": "claudio/candid-subtype-check",
crusso marked this conversation as resolved.
Show resolved Hide resolved
"builtin": false,
"description": "Candid Library for the Internet Computer",
"homepage": "",
"owner": "dfinity",
"repo": "candid",
"rev": "a555d77704d691bb8f34e21a049d44ba0acee3f8",
"sha256": "0vn171lcadpznrl5nq2mws2zjjqj9jxyvndb2is3dixbjqyvjssx",
"rev": "0889e288c8c44ce36682ffa67df010c83e912a33",
"sha256": "122v440prlcr0z6zj1a7j0rjpk1a2xwpvj8vxrdbldl6ss1krbff",
"type": "tarball",
"url": "https://github.com/dfinity/candid/archive/a555d77704d691bb8f34e21a049d44ba0acee3f8.tar.gz",
"url": "https://github.com/dfinity/candid/archive/0889e288c8c44ce36682ffa67df010c83e912a33.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"esm": {
Expand Down
111 changes: 111 additions & 0 deletions rts/motoko-rts/src/bitrel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//! This module implements a simple subtype cache used by the compiler (in generated code)
crusso marked this conversation as resolved.
Show resolved Hide resolved

//TODO: add unit test and remove #[allow(dead_code)] on tested functions

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 {
#[allow(dead_code)]
pub(crate) fn words(size1: u32, size2: u32) -> u32 {
return ((2 * size1 * size2 * BITS) + (usize::BITS - 1)) / usize::BITS;
}

#[allow(dead_code)]
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 bytes != BitRel::words(self.size1, self.size2) * WORD_SIZE {
idl_trap_with("BitRel missized");
};
memzero(self.ptr as usize, Words(bytes / WORD_SIZE));
}
crusso marked this conversation as resolved.
Show resolved Hide resolved

#[allow(dead_code)]
unsafe fn locate_ptr_bit(&self, 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;
}

#[allow(dead_code)]
pub(crate) unsafe fn visited(&self, p: bool, i_j: u32, j_i: u32) -> bool {
self.get(p, i_j, j_i, 0)
}

#[allow(dead_code)]
pub(crate) unsafe fn visit(&self, p: bool, i_j: u32, j_i: u32) {
self.set(p, i_j, j_i, 0, true)
}

#[allow(dead_code)]
// 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) {
debug_assert!(!self.get(p, i_j, j_i, 1));
}

#[allow(dead_code)]
pub(crate) unsafe fn related(&self, p: bool, i_j: u32, j_i: u32) -> bool {
!self.get(p, i_j, j_i, 1)
}

#[allow(dead_code)]
pub(crate) unsafe fn disprove(&self, p: bool, i_j: u32, j_i: u32) {
self.set(p, i_j, j_i, 1, true)
}
}
Loading