From 1c00b4af7ce33dcaf8399e829caafd671c3de397 Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:35:31 -0800 Subject: [PATCH] Release candid 0.10 (#493) --- .github/workflows/bench.yml | 2 +- .github/workflows/rust.yml | 8 +- Cargo.lock | 373 +++++------ Cargo.toml | 12 + Changelog.md | 34 +- rust/candid/Cargo.toml | 94 +-- rust/candid/benches/benchmark.rs | 5 +- rust/candid/fuzz/Cargo.lock | 597 ++---------------- rust/candid/fuzz/Cargo.toml | 2 +- rust/candid/fuzz/fuzz_targets/type_decoder.rs | 4 +- rust/candid/src/binary_parser.rs | 16 +- rust/candid/src/bindings/mod.rs | 20 - rust/candid/src/de.rs | 106 +++- rust/candid/src/error.rs | 168 ++--- rust/candid/src/lib.rs | 156 +---- rust/candid/src/parser/grammar.rs | 2 - rust/candid/src/parser/mod.rs | 36 -- .../candid/src/{bindings => pretty}/candid.rs | 46 +- rust/candid/src/pretty/mod.rs | 4 + .../candid/src/{pretty.rs => pretty/utils.rs} | 7 +- rust/candid/src/ser.rs | 33 +- rust/candid/src/types/arc.rs | 5 +- rust/candid/src/types/impls.rs | 12 +- rust/candid/src/types/internal.rs | 102 +-- rust/candid/src/types/leb128.rs | 100 +++ rust/candid/src/types/mod.rs | 10 + rust/candid/src/types/number.rs | 121 +--- rust/candid/src/types/principal.rs | 354 +---------- rust/candid/src/types/rc.rs | 5 +- rust/candid/src/types/subtype.rs | 94 ++- rust/candid/src/types/type_env.rs | 20 +- rust/candid/src/types/value.rs | 59 +- rust/candid/src/utils.rs | 103 +-- rust/candid/tests/number.rs | 69 +- rust/candid/tests/serde.rs | 8 +- rust/candid/tests/types.rs | 48 +- rust/candid_derive/Cargo.toml | 2 +- rust/candid_derive/src/func.rs | 8 +- rust/candid_derive/src/lib.rs | 2 +- rust/candid_parser/Cargo.toml | 57 ++ rust/candid_parser/LICENSE | 1 + rust/{candid => candid_parser}/build.rs | 3 +- .../src/bindings/analysis.rs | 2 +- .../src/bindings/javascript.rs | 33 +- rust/candid_parser/src/bindings/mod.rs | 8 + .../src/bindings/motoko.rs | 20 +- .../src/bindings/rust.rs | 44 +- .../src/bindings/typescript.rs | 22 +- .../parser => candid_parser/src}/configs.rs | 2 +- rust/candid_parser/src/error.rs | 126 ++++ .../src}/grammar.lalrpop | 15 +- rust/candid_parser/src/grammar.rs | 2 + rust/candid_parser/src/lib.rs | 152 +++++ .../parser => candid_parser/src}/random.rs | 117 ++-- .../src/parser => candid_parser/src}/test.rs | 10 +- .../src/parser => candid_parser/src}/token.rs | 0 .../src/parser => candid_parser/src}/types.rs | 2 +- .../parser => candid_parser/src}/typing.rs | 20 +- rust/candid_parser/src/utils.rs | 82 +++ .../tests/assets/actor.did | 0 .../tests/assets/bad_comment.did | 0 .../tests/assets/bad_import.did | 0 .../tests/assets/class.did | 0 .../tests/assets/codegen/basic/invalid_id.did | 0 .../tests/assets/codegen/basic/invalid_id.rs | 0 .../tests/assets/codegen/basic/prim_types.did | 0 .../tests/assets/codegen/basic/prim_types.rs | 0 .../tests/assets/codegen/basic/recursive.did | 0 .../tests/assets/codegen/basic/recursive.rs | 0 .../assets/codegen/examples/linkedup.did | 0 .../tests/assets/codegen/examples/linkedup.rs | 0 .../tests/assets/collision_fields.did | 0 .../tests/assets/collision_fields2.did | 0 .../tests/assets/comment.did | 0 .../tests/assets/cyclic.did | 0 rust/candid_parser/tests/assets/empty.did | 6 + .../tests/assets/escape.did | 0 .../tests/assets/example.did | 0 .../tests/assets/fieldnat.did | 0 .../tests/assets/import/a.did | 0 .../tests/assets/import/b/b.did | 0 .../tests/assets/invalid_cyclic.did | 0 .../tests/assets/keyword.did | 0 .../tests/assets/management.did | 0 .../tests/assets/not_func.did | 0 .../tests/assets/not_serv.did | 0 .../tests/assets/ok/actor.d.ts | 0 .../tests/assets/ok/actor.did | 0 .../tests/assets/ok/actor.js | 0 .../tests/assets/ok/actor.mo | 0 .../tests/assets/ok/actor.rs | 0 .../tests/assets/ok/bad_comment.fail | 0 .../tests/assets/ok/bad_import.fail | 0 .../tests/assets/ok/class.d.ts | 0 .../tests/assets/ok/class.did | 0 .../tests/assets/ok/class.js | 0 .../tests/assets/ok/class.mo | 0 .../tests/assets/ok/class.rs | 0 .../tests/assets/ok/collision_fields.fail | 0 .../tests/assets/ok/collision_fields2.fail | 0 .../tests/assets/ok/comment.d.ts | 0 .../tests/assets/ok/comment.did | 0 .../tests/assets/ok/comment.js | 0 .../tests/assets/ok/comment.mo | 0 .../tests/assets/ok/comment.rs | 0 .../tests/assets/ok/cyclic.d.ts | 0 .../tests/assets/ok/cyclic.did | 0 .../tests/assets/ok/cyclic.js | 0 .../tests/assets/ok/cyclic.mo | 0 .../tests/assets/ok/cyclic.rs | 0 rust/candid_parser/tests/assets/ok/empty.d.ts | 11 + rust/candid_parser/tests/assets/ok/empty.did | 6 + rust/candid_parser/tests/assets/ok/empty.js | 14 + rust/candid_parser/tests/assets/ok/empty.mo | 11 + rust/candid_parser/tests/assets/ok/empty.rs | 35 + .../tests/assets/ok/escape.d.ts | 0 .../tests/assets/ok/escape.did | 0 .../tests/assets/ok/escape.js | 0 .../tests/assets/ok/escape.rs | 0 .../tests/assets/ok/example.d.ts | 0 .../tests/assets/ok/example.did | 0 .../tests/assets/ok/example.js | 0 .../tests/assets/ok/example.mo | 0 .../tests/assets/ok/example.rs | 0 .../tests/assets/ok/fieldnat.d.ts | 0 .../tests/assets/ok/fieldnat.did | 0 .../tests/assets/ok/fieldnat.js | 0 .../tests/assets/ok/fieldnat.mo | 0 .../tests/assets/ok/fieldnat.rs | 0 .../tests/assets/ok/invalid_cyclic.fail | 0 .../tests/assets/ok/keyword.d.ts | 0 .../tests/assets/ok/keyword.did | 0 .../tests/assets/ok/keyword.js | 0 .../tests/assets/ok/keyword.mo | 0 .../tests/assets/ok/keyword.rs | 0 .../tests/assets/ok/management.d.ts | 0 .../tests/assets/ok/management.did | 0 .../tests/assets/ok/management.js | 0 .../tests/assets/ok/management.mo | 0 .../tests/assets/ok/management.rs | 0 .../tests/assets/ok/not_func.fail | 0 .../tests/assets/ok/not_serv.fail | 0 .../tests/assets/ok/oneway.fail | 0 .../tests/assets/ok/recursion.d.ts | 0 .../tests/assets/ok/recursion.did | 0 .../tests/assets/ok/recursion.js | 0 .../tests/assets/ok/recursion.mo | 0 .../tests/assets/ok/recursion.rs | 0 .../tests/assets/ok/recursive_class.d.ts | 0 .../tests/assets/ok/recursive_class.did | 0 .../tests/assets/ok/recursive_class.js | 0 .../tests/assets/ok/recursive_class.mo | 0 .../tests/assets/ok/recursive_class.rs | 0 .../tests/assets/ok/service.d.ts | 0 .../tests/assets/ok/service.did | 0 .../tests/assets/ok/service.js | 0 .../tests/assets/ok/service.mo | 0 .../tests/assets/ok/service.rs | 0 .../tests/assets/ok/surrogate.fail | 0 .../tests/assets/ok/undefine.fail | 0 .../tests/assets/ok/unicode.d.ts | 0 .../tests/assets/ok/unicode.did | 0 .../tests/assets/ok/unicode.js | 0 .../tests/assets/ok/unicode.rs | 0 .../tests/assets/oneway.did | 0 .../tests/assets/recursion.did | 0 .../tests/assets/recursive_class.did | 0 .../tests/assets/service.did | 0 .../tests/assets/surrogate.did | 0 .../tests/assets/undefine.did | 0 .../tests/assets/unicode.did | 0 .../tests/parse_type.rs | 15 +- .../tests/parse_value.rs | 27 +- .../tests/test_suite.rs | 4 +- rust/{candid => candid_parser}/tests/value.rs | 13 +- rust/ic_principal/Cargo.toml | 44 ++ rust/ic_principal/LICENSE | 1 + rust/ic_principal/README.md | 5 + rust/ic_principal/src/lib.rs | 388 ++++++++++++ .../tests/principal.rs | 5 +- tools/didc/Cargo.toml | 2 +- tools/didc/src/main.rs | 72 ++- 182 files changed, 2101 insertions(+), 2123 deletions(-) delete mode 100644 rust/candid/src/bindings/mod.rs delete mode 100644 rust/candid/src/parser/grammar.rs delete mode 100644 rust/candid/src/parser/mod.rs rename rust/candid/src/{bindings => pretty}/candid.rs (92%) create mode 100644 rust/candid/src/pretty/mod.rs rename rust/candid/src/{pretty.rs => pretty/utils.rs} (90%) create mode 100644 rust/candid/src/types/leb128.rs create mode 100644 rust/candid_parser/Cargo.toml create mode 120000 rust/candid_parser/LICENSE rename rust/{candid => candid_parser}/build.rs (62%) rename rust/{candid => candid_parser}/src/bindings/analysis.rs (98%) rename rust/{candid => candid_parser}/src/bindings/javascript.rs (93%) create mode 100644 rust/candid_parser/src/bindings/mod.rs rename rust/{candid => candid_parser}/src/bindings/motoko.rs (92%) rename rust/{candid => candid_parser}/src/bindings/rust.rs (95%) rename rust/{candid => candid_parser}/src/bindings/typescript.rs (93%) rename rust/{candid/src/parser => candid_parser/src}/configs.rs (99%) create mode 100644 rust/candid_parser/src/error.rs rename rust/{candid/src/parser => candid_parser/src}/grammar.lalrpop (96%) create mode 100644 rust/candid_parser/src/grammar.rs create mode 100644 rust/candid_parser/src/lib.rs rename rust/{candid/src/parser => candid_parser/src}/random.rs (82%) rename rust/{candid/src/parser => candid_parser/src}/test.rs (95%) rename rust/{candid/src/parser => candid_parser/src}/token.rs (100%) rename rust/{candid/src/parser => candid_parser/src}/types.rs (98%) rename rust/{candid/src/parser => candid_parser/src}/typing.rs (95%) create mode 100644 rust/candid_parser/src/utils.rs rename rust/{candid => candid_parser}/tests/assets/actor.did (100%) rename rust/{candid => candid_parser}/tests/assets/bad_comment.did (100%) rename rust/{candid => candid_parser}/tests/assets/bad_import.did (100%) rename rust/{candid => candid_parser}/tests/assets/class.did (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/basic/invalid_id.did (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/basic/invalid_id.rs (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/basic/prim_types.did (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/basic/prim_types.rs (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/basic/recursive.did (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/basic/recursive.rs (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/examples/linkedup.did (100%) rename rust/{candid => candid_parser}/tests/assets/codegen/examples/linkedup.rs (100%) rename rust/{candid => candid_parser}/tests/assets/collision_fields.did (100%) rename rust/{candid => candid_parser}/tests/assets/collision_fields2.did (100%) rename rust/{candid => candid_parser}/tests/assets/comment.did (100%) rename rust/{candid => candid_parser}/tests/assets/cyclic.did (100%) create mode 100644 rust/candid_parser/tests/assets/empty.did rename rust/{candid => candid_parser}/tests/assets/escape.did (100%) rename rust/{candid => candid_parser}/tests/assets/example.did (100%) rename rust/{candid => candid_parser}/tests/assets/fieldnat.did (100%) rename rust/{candid => candid_parser}/tests/assets/import/a.did (100%) rename rust/{candid => candid_parser}/tests/assets/import/b/b.did (100%) rename rust/{candid => candid_parser}/tests/assets/invalid_cyclic.did (100%) rename rust/{candid => candid_parser}/tests/assets/keyword.did (100%) rename rust/{candid => candid_parser}/tests/assets/management.did (100%) rename rust/{candid => candid_parser}/tests/assets/not_func.did (100%) rename rust/{candid => candid_parser}/tests/assets/not_serv.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/actor.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/actor.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/actor.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/actor.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/actor.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/bad_comment.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/bad_import.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/class.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/class.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/class.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/class.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/class.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/collision_fields.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/collision_fields2.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/comment.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/comment.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/comment.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/comment.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/comment.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/cyclic.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/cyclic.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/cyclic.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/cyclic.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/cyclic.rs (100%) create mode 100644 rust/candid_parser/tests/assets/ok/empty.d.ts create mode 100644 rust/candid_parser/tests/assets/ok/empty.did create mode 100644 rust/candid_parser/tests/assets/ok/empty.js create mode 100644 rust/candid_parser/tests/assets/ok/empty.mo create mode 100644 rust/candid_parser/tests/assets/ok/empty.rs rename rust/{candid => candid_parser}/tests/assets/ok/escape.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/escape.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/escape.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/escape.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/example.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/example.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/example.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/example.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/example.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/fieldnat.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/fieldnat.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/fieldnat.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/fieldnat.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/fieldnat.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/invalid_cyclic.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/keyword.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/keyword.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/keyword.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/keyword.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/keyword.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/management.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/management.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/management.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/management.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/management.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/not_func.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/not_serv.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/oneway.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursion.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursion.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursion.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursion.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursion.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursive_class.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursive_class.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursive_class.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursive_class.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/recursive_class.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/service.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/service.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/service.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/service.mo (100%) rename rust/{candid => candid_parser}/tests/assets/ok/service.rs (100%) rename rust/{candid => candid_parser}/tests/assets/ok/surrogate.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/undefine.fail (100%) rename rust/{candid => candid_parser}/tests/assets/ok/unicode.d.ts (100%) rename rust/{candid => candid_parser}/tests/assets/ok/unicode.did (100%) rename rust/{candid => candid_parser}/tests/assets/ok/unicode.js (100%) rename rust/{candid => candid_parser}/tests/assets/ok/unicode.rs (100%) rename rust/{candid => candid_parser}/tests/assets/oneway.did (100%) rename rust/{candid => candid_parser}/tests/assets/recursion.did (100%) rename rust/{candid => candid_parser}/tests/assets/recursive_class.did (100%) rename rust/{candid => candid_parser}/tests/assets/service.did (100%) rename rust/{candid => candid_parser}/tests/assets/surrogate.did (100%) rename rust/{candid => candid_parser}/tests/assets/undefine.did (100%) rename rust/{candid => candid_parser}/tests/assets/unicode.did (100%) rename rust/{candid => candid_parser}/tests/parse_type.rs (88%) rename rust/{candid => candid_parser}/tests/parse_value.rs (93%) rename rust/{candid => candid_parser}/tests/test_suite.rs (85%) rename rust/{candid => candid_parser}/tests/value.rs (93%) create mode 100644 rust/ic_principal/Cargo.toml create mode 120000 rust/ic_principal/LICENSE create mode 100644 rust/ic_principal/README.md create mode 100644 rust/ic_principal/src/lib.rs rename rust/{candid => ic_principal}/tests/principal.rs (98%) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index ea2101ec..c9b3bb0e 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -2,7 +2,7 @@ name: Rust Bench on: pull_request: paths: - - 'rust/**' + - 'rust/candid/**' jobs: runBenchMark: name: run benchmark diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b50037a8..9f21e218 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,9 +26,13 @@ jobs: target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Build - run: cargo build + run: | + cargo build - name: Run tests - run: cargo test --features all + run: | + cargo test --no-default-features + cargo test + cargo test --features all - name: fmt run: cargo fmt -v -- --check - name: lint diff --git a/Cargo.lock b/Cargo.lock index 899e13ab..5ca030d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,9 +35,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -59,9 +59,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.5.0" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", @@ -73,15 +73,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" dependencies = [ "utf8parse", ] @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "2.1.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys 0.48.0", @@ -113,9 +113,9 @@ checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "arbitrary" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e" +checksum = "a2e1373abdaa212b704512ec2bd8b26bd0b7d5c3f70117411a5d9a451383c859" [[package]] name = "arrayvec" @@ -182,7 +182,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d9672209df1714ee804b1f4d4f68c8eb2a90b1f7a07acf472f88ce198ef1fed" dependencies = [ "either", - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", "syn 1.0.109", ] @@ -210,9 +210,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block-buffer" @@ -251,59 +251,69 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "candid" -version = "0.9.11" +version = "0.10.0" dependencies = [ "anyhow", - "arbitrary", "bincode", "binread", "byteorder", "candid_derive", - "codespan-reporting", - "convert_case", - "crc32fast", "criterion", - "data-encoding", - "fake", - "goldenfile", "hex", - "impls", - "lalrpop", - "lalrpop-util", + "ic_principal", "leb128", - "logos", "num-bigint", "num-traits", - "num_enum", "paste", "pretty 0.12.3", "rand", "serde", "serde_bytes", "serde_cbor", - "serde_dhall", "serde_json", - "serde_test", - "sha2 0.10.8", "stacker", - "test-generator", "thiserror", ] [[package]] name = "candid_derive" -version = "0.6.4" +version = "0.6.5" dependencies = [ "lazy_static", - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", - "syn 2.0.37", + "syn 2.0.38", +] + +[[package]] +name = "candid_parser" +version = "0.1.0" +dependencies = [ + "anyhow", + "arbitrary", + "candid", + "codespan-reporting", + "convert_case", + "fake", + "goldenfile", + "hex", + "lalrpop", + "lalrpop-util", + "logos", + "num-bigint", + "num-traits", + "pretty 0.12.3", + "rand", + "serde", + "serde_dhall", + "test-generator", + "thiserror", ] [[package]] @@ -368,9 +378,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.5" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824956d0dca8334758a5b7f7e50518d66ea319330cbceedcf76905c2f6ab30e3" +checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" dependencies = [ "clap_builder", "clap_derive", @@ -378,26 +388,26 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.5" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122ec64120a49b4563ccaedcbea7818d069ed8e9aa6d829b82d8a4128936b2ab" +checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" dependencies = [ "anstream", "anstyle", - "clap_lex 0.5.1", + "clap_lex 0.6.0", "strsim", ] [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -411,9 +421,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "codespan-reporting" @@ -454,9 +464,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" dependencies = [ "libc", ] @@ -561,6 +571,12 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +[[package]] +name = "deunicode" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a1abaf4d861455be59f64fd2b55606cb151fce304ede7165f410243ce96bde6" + [[package]] name = "dhall" version = "0.11.1" @@ -592,7 +608,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df7c81d16870879ef530b07cef32bc6088f98937ab4168106cc8e382a05146bf" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", "syn 1.0.109", ] @@ -602,8 +618,8 @@ name = "didc" version = "0.3.5" dependencies = [ "anyhow", - "candid", - "clap 4.4.5", + "candid_parser", + "clap 4.4.7", "hex", "pretty-hex", "rand", @@ -699,33 +715,22 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "errno-dragonfly", "libc", "windows-sys 0.48.0", ] -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "fake" -version = "2.8.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9af7b0c58ac9d03169e27f080616ce9f64004edca3d2ef4147a811c21b23b319" +checksum = "26221445034074d46b276e13eb97a265ebdb8ed8da705c4dddd3dd20b66b45d2" dependencies = [ + "deunicode", "rand", - "unidecode", ] [[package]] @@ -806,9 +811,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "heck" @@ -846,6 +851,24 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "ic_principal" +version = "0.1.0" +dependencies = [ + "arbitrary", + "crc32fast", + "data-encoding", + "hex", + "impls", + "serde", + "serde_bytes", + "serde_cbor", + "serde_json", + "serde_test", + "sha2 0.10.8", + "thiserror", +] + [[package]] name = "idna" version = "0.4.0" @@ -874,12 +897,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad227c3af19d4914570ad36d30409928b75967c298feb9ea1969db3a610bb14e" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.2", ] [[package]] @@ -972,9 +995,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "linux-raw-sys" @@ -984,9 +1007,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -1015,10 +1038,10 @@ checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68" dependencies = [ "beef", "fnv", - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", "regex-syntax 0.6.29", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1032,9 +1055,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.3" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memoffset" @@ -1091,34 +1114,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "num_enum" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" -dependencies = [ - "proc-macro-crate", - "proc-macro2 1.0.67", - "quote 1.0.33", - "syn 2.0.37", -] - [[package]] name = "once_cell" version = "1.18.0" @@ -1139,9 +1141,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "os_str_bytes" -version = "6.5.1" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "parking_lot" @@ -1155,13 +1157,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall 0.4.1", "smallvec", "windows-targets 0.48.5", ] @@ -1180,9 +1182,9 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pest" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c022f1e7b65d6a24c0dbbd5fb344c66881bc01f3e5ae74a1c8100f2f985d98a4" +checksum = "ae9cee2a55a544be8b89dc6848072af97a20f2422603c10865be2a42b580fff5" dependencies = [ "memchr", "thiserror", @@ -1206,16 +1208,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d8630a7a899cb344ec1c16ba0a6b24240029af34bdc0a21f84e411d7f793f29" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", "syn 1.0.109", ] [[package]] name = "pest_derive" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35513f630d46400a977c4cb58f78e1bfbe01434316e60c37d27b9ad6139c66d8" +checksum = "81d78524685f5ef2a3b3bd1cafbc9fcabb036253d9b1463e726a91cd16e2dfc2" dependencies = [ "pest", "pest_generator", @@ -1223,22 +1225,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc9fc1b9e7057baba189b5c626e2d6f40681ae5b6eb064dc7c7834101ec8123a" +checksum = "68bd1206e71118b5356dae5ddc61c8b11e28b09ef6a31acbd15ea48a28e0c227" dependencies = [ "pest", "pest_meta", - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "pest_meta" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df74e9e7ec4053ceb980e7c0c8bd3594e977fde1af91daba9c928e8e8c6708d" +checksum = "7c747191d4ad9e4a4ab9c8798f1e82a39affe7ef9648390b7e5548d18e099de6" dependencies = [ "once_cell", "pest", @@ -1252,7 +1254,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.0.1", + "indexmap 2.0.2", ] [[package]] @@ -1339,16 +1341,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131" -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - [[package]] name = "proc-macro2" version = "0.4.30" @@ -1360,9 +1352,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -1391,7 +1383,7 @@ version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", ] [[package]] @@ -1462,6 +1454,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -1475,14 +1476,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.5" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.8", - "regex-syntax 0.7.5", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -1493,13 +1494,13 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-automata" -version = "0.3.8" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", ] [[package]] @@ -1514,13 +1515,19 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rustix" -version = "0.38.19" +version = "0.38.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", @@ -1556,9 +1563,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] @@ -1584,13 +1591,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1652,9 +1659,9 @@ dependencies = [ [[package]] name = "similar" -version = "2.2.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +checksum = "2aeaf503862c419d66959f5d7ca015337d864e9c49485d771b732e2a20453597" dependencies = [ "bstr", "unicode-segmentation", @@ -1737,18 +1744,18 @@ version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", "unicode-ident", ] [[package]] name = "syn" -version = "2.0.37" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", "unicode-ident", ] @@ -1806,22 +1813,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1858,23 +1865,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.0.1", - "toml_datetime", - "winnow", -] - [[package]] name = "typed-arena" version = "2.0.2" @@ -1938,12 +1928,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "unidecode" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402bb19d8e03f1d1a7450e2bd613980869438e0666331be3e073089124aa1adc" - [[package]] name = "url" version = "2.4.1" @@ -2002,9 +1986,9 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-shared", ] @@ -2024,9 +2008,9 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ - "proc-macro2 1.0.67", + "proc-macro2 1.0.69", "quote 1.0.33", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2209,12 +2193,3 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "winnow" -version = "0.5.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" -dependencies = [ - "memchr", -] diff --git a/Cargo.toml b/Cargo.toml index 352d28c5..45a462f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,20 @@ [workspace] members = [ "rust/candid", + "rust/candid_parser", "rust/candid_derive", + "rust/ic_principal", "tools/didc", ] resolver = "2" +[workspace.dependencies] +hex = "0.4.3" +num-bigint = { version = "0.4", features = ["serde"] } +num-traits = "0.2" +pretty = "0.12" +serde = { version = "1.0", features = ["derive"] } +thiserror = "1.0" +anyhow = "1.0" +rand = "0.8" +arbitrary = "1.3" diff --git a/Changelog.md b/Changelog.md index 51a20b77..83381c74 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,9 +1,41 @@ # Changelog -## Rust 0.9.9 +## Rust 0.10.0 + +### Breaking changes + +* The original `candid` crate is split into three crates: + * `candid`: mainly for Candid data (de-)serialization. + + `candid::bindings::candid` moves to `candid::pretty::candid`. `candid::pretty` moves to `candid::pretty::utils`. These modules are only available under feature flag `printer` (enabled by default). + + `candid::{Int, Nat}` is only available under feature flag `bignum` (enabled by default). If this feature is not enabled, you can use `i128/u128` for `int/nat` type. + + Remove operator for `i32` and `Nat`. + + Add `IDLValue::Blob(Vec)` enum for efficient handling of blob value. + + `candid::types::number::pp_num_str` moves to `candid::utils::pp_num_str`. + + `candid::types::value` module is only availble under feature flag `value`. + + `mute_warning` feature flag is removed, use `candid::types::subtype_with_config` instead. + * `candid_parser`: used to be the `parser` and `bindings` module in `candid` crate. + + Remove `FromStr` trait for `IDLArgs` and `IDLValue`. Use `parse_idl_args` and `parse_idl_value` respectively instead. + + `TypeEnv.ast_to_type` becomes `candid_parser::typing::ast_to_type`. + + `bindings::rust::Config` uses builder pattern. + + `candid` is re-exported in `candid_parser::candid`. + + `candid::*` is re-exported in `candid_parser`. + * `ic_principal`: only for `Principal` and `PrincipalError`. + +### Non-breaking changes + +* Add `candid::types::subtype_with_config` to control the error reporting level of special opt rule. +* Add `Type.is_blob(env)` method to check if a type is a blob type. +* Fix TS binding for `variant {}`. + +## Rust 0.9.9 -- 0.9.11 * Set different config values for `full_error_message` and `zero_sized_values` for Wasm and non-Wasm target. +* Fix subtyping error message for empty type. +* Remove name duplication check in `candid_method` to avoid errors on certain IDEs. +* Improvements in Candid UI + + Add II button, thanks to @Web3NL. + + Support streaming download of profiling data. ## 2023-09-27 diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index 9580da64..fa44a26a 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "candid" -version = "0.9.11" +version = "0.10.0" edition = "2021" authors = ["DFINITY Team"] description = "Candid is an interface description language (IDL) for interacting with canisters running on the Internet Computer." @@ -9,57 +9,35 @@ documentation = "https://docs.rs/candid" repository = "https://github.com/dfinity/candid" license = "Apache-2.0" readme = "README.md" - -categories = ["encoding", "parsing", "wasm"] -keywords = ["internet-computer", "idl", "candid", "dfinity", "parser"] -include = ["src", "Cargo.toml", "build.rs", "LICENSE", "README.md"] -build = "build.rs" - -[build-dependencies] -lalrpop = { version = "0.20.0", optional = true } +categories = ["encoding", "wasm"] +keywords = ["internet-computer", "idl", "candid", "dfinity"] +include = ["src", "Cargo.toml", "LICENSE", "README.md"] [dependencies] -byteorder = "1.4.3" -candid_derive = { path = "../candid_derive", version = "=0.6.4" } -codespan-reporting = "0.11" -crc32fast = "1.3.0" -data-encoding = "2.4.0" -hex = "0.4.2" -leb128 = "0.2.4" -num_enum = "0.6.1" -num-bigint = { version = "0.4.2", features = ["serde"] } -num-traits = "0.2.12" -paste = "1.0.0" -pretty = "0.12.0" -serde = { version = "1.0.118", features = ["derive"] } -serde_bytes = "0.11" -sha2 = "0.10.1" -thiserror = "1.0.20" -anyhow = "1.0" +candid_derive = { path = "../candid_derive", version = "=0.6.5" } +ic_principal = { path = "../ic_principal", version = "0.1.0" } binread = { version = "2.1", features = ["debug_template"] } +byteorder = "1.5.0" +leb128 = "0.2.5" +paste = "1.0" +hex.workspace = true +serde.workspace = true +thiserror.workspace = true +anyhow.workspace = true -lalrpop-util = { version = "0.20.0", optional = true } -logos = { version = "0.13", optional = true } -convert_case = { version = "0.6", optional = true } - -arbitrary = { version = "1.0", optional = true } -# Don't upgrade serde_dhall. It will introduce dependency with invalid license. -serde_dhall = { version = "0.11", default-features = false, optional = true } -fake = { version = "2.4", optional = true } -rand = { version = "0.8", optional = true } +serde_bytes = { version = "0.11", optional = true } +pretty = { workspace = true, optional = true } +num-bigint = { workspace = true, optional = true } +num-traits = { workspace = true, optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] stacker = "0.1" [dev-dependencies] -goldenfile = "1.1.0" -test-generator = "0.3.0" -rand = "0.8" +rand.workspace = true criterion = "0.4" serde_cbor = "0.11.2" serde_json = "1.0.74" -serde_test = "1.0.137" -impls = "1" bincode = "1.3.3" [[bench]] @@ -67,29 +45,25 @@ name = "benchmark" harness = false path = "benches/benchmark.rs" +[features] +bignum = ["dep:num-bigint", "dep:num-traits"] +printer = ["dep:pretty"] +value = ["bignum", "printer"] +default = ["serde_bytes", "printer", "bignum"] +all = ["default", "value", "ic_principal/arbitrary"] + [[test]] -name = "test_suite" -path = "tests/test_suite.rs" -required-features = ["parser"] -[[test]] -name = "value" -path = "tests/value.rs" -required-features = ["parser"] +name = "types" +path = "tests/types.rs" +required-features = ["value"] [[test]] -name = "parse_value" -path = "tests/parse_value.rs" -required-features = ["parser"] +name = "serde" +path = "tests/serde.rs" +required-features = ["bignum"] [[test]] -name = "parse_type" -path = "tests/parse_type.rs" -required-features = ["parser"] - -[features] -configs = ["serde_dhall"] -random = ["parser", "configs", "arbitrary", "fake", "rand"] -parser = ["lalrpop", "lalrpop-util", "logos", "convert_case"] -all = ["random"] -mute_warnings = [] +name = "number" +path = "tests/number.rs" +required-features = ["bignum"] # docs.rs-specific configuration # To test locally: RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --features all diff --git a/rust/candid/benches/benchmark.rs b/rust/candid/benches/benchmark.rs index 14deb618..6a66c519 100644 --- a/rust/candid/benches/benchmark.rs +++ b/rust/candid/benches/benchmark.rs @@ -92,8 +92,9 @@ fn bench_collections(c: &mut Criterion) { }); } { - let map: BTreeMap = - (0..65536).map(|i| (i.to_string(), Nat::from(i))).collect(); + let map: BTreeMap = (0u32..65536u32) + .map(|i| (i.to_string(), Nat::from(i))) + .collect(); group.bench_function("vec (text, nat)", |b| { b.iter_batched( || map.clone(), diff --git a/rust/candid/fuzz/Cargo.lock b/rust/candid/fuzz/Cargo.lock index a908c669..0ffc0331 100644 --- a/rust/candid/fuzz/Cargo.lock +++ b/rust/candid/fuzz/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - [[package]] name = "anyhow" version = "1.0.68" @@ -19,9 +10,9 @@ checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" [[package]] name = "arbitrary" -version = "1.2.3" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e90af4de65aa7b293ef2d09daff88501eb254f58edde2e1ac02c82d873eadad" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" [[package]] name = "arrayvec" @@ -29,38 +20,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" -[[package]] -name = "ascii-canvas" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" -dependencies = [ - "term", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "beef" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" - [[package]] name = "binread" version = "2.2.0" @@ -81,30 +46,9 @@ dependencies = [ "either", "proc-macro2", "quote", - "syn", -] - -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", + "syn 1.0.107", ] -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "block-buffer" version = "0.10.3" @@ -116,34 +60,28 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "candid" -version = "0.9.0-beta.2" +version = "0.9.100" dependencies = [ "anyhow", "binread", "byteorder", "candid_derive", - "codespan-reporting", - "crc32fast", - "data-encoding", "hex", - "lalrpop", - "lalrpop-util", + "ic_principal", "leb128", - "logos", "num-bigint", "num-traits", - "num_enum", "paste", "pretty", "serde", "serde_bytes", - "sha2", + "stacker", "thiserror", ] @@ -159,12 +97,12 @@ dependencies = [ [[package]] name = "candid_derive" -version = "0.6.0" +version = "0.6.5" dependencies = [ "lazy_static", "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -182,16 +120,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - [[package]] name = "cpufeatures" version = "0.2.5" @@ -210,12 +138,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "crypto-common" version = "0.1.6" @@ -232,12 +154,6 @@ version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb" -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - [[package]] name = "digest" version = "0.10.6" @@ -248,54 +164,12 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" -[[package]] -name = "ena" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" -dependencies = [ - "log", -] - -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "generic-array" version = "0.14.6" @@ -306,32 +180,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hex" version = "0.4.3" @@ -339,22 +187,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +name = "ic_principal" +version = "0.1.0" dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", + "arbitrary", + "crc32fast", + "data-encoding", + "hex", + "serde", + "serde_bytes", + "sha2", + "thiserror", ] [[package]] @@ -366,38 +209,6 @@ dependencies = [ "libc", ] -[[package]] -name = "lalrpop" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" -dependencies = [ - "ascii-canvas", - "atty", - "bit-set", - "diff", - "ena", - "itertools", - "lalrpop-util", - "petgraph", - "pico-args", - "regex", - "regex-syntax", - "string_cache", - "term", - "tiny-keccak", - "unicode-xid", -] - -[[package]] -name = "lalrpop-util" -version = "0.19.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" -dependencies = [ - "regex", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -412,9 +223,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libfuzzer-sys" @@ -427,69 +238,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "logos" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" -dependencies = [ - "logos-derive", -] - -[[package]] -name = "logos-derive" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" -dependencies = [ - "beef", - "fnv", - "proc-macro2", - "quote", - "regex-syntax", - "syn", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "new_debug_unreachable" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" - -[[package]] -name = "nom8" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" -dependencies = [ - "memchr", -] - [[package]] name = "num-bigint" version = "0.4.3" @@ -521,180 +269,62 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_enum" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "once_cell" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys", -] - [[package]] name = "paste" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" -[[package]] -name = "petgraph" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" -dependencies = [ - "fixedbitset", - "indexmap", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pico-args" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - [[package]] name = "pretty" -version = "0.10.0" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9940b913ee56ddd94aec2d3cd179dd47068236f42a1a6415ccf9d880ce2a61" +checksum = "b55c4d17d994b637e2f4daf6e5dc5d660d209d5642377d675d7a1c3ab69fa579" dependencies = [ "arrayvec", "typed-arena", -] - -[[package]] -name = "proc-macro-crate" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34" -dependencies = [ - "once_cell", - "toml_edit", + "unicode-width", ] [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] -name = "quote" -version = "1.0.23" +name = "psm" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", + "cc", ] [[package]] -name = "regex" -version = "1.7.1" +name = "quote" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "proc-macro2", ] -[[package]] -name = "regex-syntax" -version = "0.6.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" - [[package]] name = "rustversion" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" version = "1.0.152" @@ -721,7 +351,7 @@ checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -736,28 +366,16 @@ dependencies = [ ] [[package]] -name = "siphasher" -version = "0.3.10" +name = "stacker" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "string_cache" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" +checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared", - "precomputed-hash", + "cc", + "cfg-if", + "libc", + "psm", + "winapi", ] [[package]] @@ -772,23 +390,14 @@ dependencies = [ ] [[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - -[[package]] -name = "termcolor" -version = "1.2.0" +name = "syn" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ - "winapi-util", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] @@ -808,33 +417,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", - "syn", -] - -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - -[[package]] -name = "toml_datetime" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" - -[[package]] -name = "toml_edit" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b" -dependencies = [ - "indexmap", - "nom8", - "toml_datetime", + "syn 1.0.107", ] [[package]] @@ -861,24 +444,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "winapi" version = "0.3.9" @@ -895,74 +466,8 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" diff --git a/rust/candid/fuzz/Cargo.toml b/rust/candid/fuzz/Cargo.toml index 2c011dab..47e0514e 100644 --- a/rust/candid/fuzz/Cargo.toml +++ b/rust/candid/fuzz/Cargo.toml @@ -15,7 +15,7 @@ serde = "1.0.115" [dependencies.candid] path = ".." -features = ["parser"] +features = ["all"] # Prevent this from interfering with workspaces [workspace] diff --git a/rust/candid/fuzz/fuzz_targets/type_decoder.rs b/rust/candid/fuzz/fuzz_targets/type_decoder.rs index b6e4a609..201c03e7 100644 --- a/rust/candid/fuzz/fuzz_targets/type_decoder.rs +++ b/rust/candid/fuzz/fuzz_targets/type_decoder.rs @@ -11,10 +11,10 @@ pub struct Token { pub sha256: Option, } -define_function!(pub callback : (&u8) -> (Nat)); +define_function!(pub Callback : (&u8) -> (Nat)); #[derive(CandidType, Deserialize)] pub struct CallbackStrategy { - pub callback: callback, + pub callback: Callback, pub token: Token, } diff --git a/rust/candid/src/binary_parser.rs b/rust/candid/src/binary_parser.rs index 74875313..03a7b6e2 100644 --- a/rust/candid/src/binary_parser.rs +++ b/rust/candid/src/binary_parser.rs @@ -5,14 +5,14 @@ use binread::io::{Read, Seek}; use binread::{BinRead, BinResult, Error as BError, ReadOptions}; use std::convert::TryInto; -fn read_leb(reader: &mut R, ro: &ReadOptions, _: ()) -> BinResult { +fn read_leb(reader: &mut R, ro: &ReadOptions, (): ()) -> BinResult { let pos = reader.stream_position()?; leb128::read::unsigned(reader).map_err(|_| BError::Custom { pos, err: Box::new(ro.variable_name.unwrap_or("Invalid leb128")), }) } -fn read_sleb(reader: &mut R, ro: &ReadOptions, _: ()) -> BinResult { +fn read_sleb(reader: &mut R, ro: &ReadOptions, (): ()) -> BinResult { let pos = reader.stream_position()?; leb128::read::signed(reader).map_err(|_| BError::Custom { pos, @@ -178,7 +178,7 @@ impl ConsType { ConsType::Record(fs) | ConsType::Variant(fs) => { let mut res = Vec::new(); let mut prev = None; - for f in fs.inner.iter() { + for f in &fs.inner { if let Some(prev) = prev { if prev >= f.id { return Err(anyhow!("field id {} collision or not sorted", f.id)); @@ -200,10 +200,10 @@ impl ConsType { ConsType::Func(f) => { let mut args = Vec::new(); let mut rets = Vec::new(); - for arg in f.args.iter() { + for arg in &f.args { args.push(arg.to_type(len)?); } - for ret in f.rets.iter() { + for ret in &f.rets { rets.push(ret.to_type(len)?); } TypeInner::Func(Function { @@ -215,7 +215,7 @@ impl ConsType { ConsType::Service(serv) => { let mut res = Vec::new(); let mut prev = None; - for m in serv.meths.iter() { + for m in &serv.meths { if let Some(prev) = prev { if prev >= &m.name { return Err(anyhow!("method name {} duplicate or not sorted", m.name)); @@ -242,9 +242,9 @@ impl Table { env.insert(index_to_var(i as i64), ty); } // validate method has func type - for (_, t) in env.iter() { + for t in env.values() { if let TypeInner::Service(ms) = t.as_ref() { - for (name, ty) in ms.iter() { + for (name, ty) in ms { if let TypeInner::Var(id) = ty.as_ref() { if matches!(env.get(id).map(|t| t.as_ref()), Some(TypeInner::Func(_))) { continue; diff --git a/rust/candid/src/bindings/mod.rs b/rust/candid/src/bindings/mod.rs deleted file mode 100644 index 89d86ab3..00000000 --- a/rust/candid/src/bindings/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Candid bindings for different languages. -// This module assumes the input are type checked, it is safe to use unwrap. - -pub mod candid; - -#[cfg_attr(docsrs, doc(cfg(feature = "parser")))] -#[cfg(feature = "parser")] -pub mod analysis; -#[cfg_attr(docsrs, doc(cfg(feature = "parser")))] -#[cfg(feature = "parser")] -pub mod javascript; -#[cfg_attr(docsrs, doc(cfg(feature = "parser")))] -#[cfg(feature = "parser")] -pub mod motoko; -#[cfg_attr(docsrs, doc(cfg(feature = "parser")))] -#[cfg(feature = "parser")] -pub mod rust; -#[cfg_attr(docsrs, doc(cfg(feature = "parser")))] -#[cfg(feature = "parser")] -pub mod typescript; diff --git a/rust/candid/src/de.rs b/rust/candid/src/de.rs index 036440c6..67d88e14 100644 --- a/rust/candid/src/de.rs +++ b/rust/candid/src/de.rs @@ -4,11 +4,13 @@ use super::{ error::{Error, Result}, types::internal::{text_size, type_of, TypeId}, types::{Field, Label, SharedLabel, Type, TypeEnv, TypeInner}, - CandidType, Int, Nat, + CandidType, }; +#[cfg(feature = "bignum")] +use super::{Int, Nat}; use crate::{ binary_parser::{BoolValue, Header, Len, PrincipalBytes}, - types::subtype::{subtype, Gamma}, + types::subtype::{subtype_with_config, Gamma, OptReport}, }; use anyhow::{anyhow, Context}; use binread::BinRead; @@ -56,6 +58,9 @@ impl<'de> IDLDeserialize<'de> { self.de.is_untyped = false; self.deserialize_with_type(T::ty()) } + #[cfg_attr(docsrs, doc(cfg(feature = "value")))] + #[cfg(feature = "value")] + /// Deserialize one value as `IDLValue` from deserializer. Note that `expected_type` should not contain `TypeInner::Knot`. pub fn get_value_with_type( &mut self, env: &TypeEnv, @@ -136,8 +141,29 @@ impl<'de> IDLDeserialize<'de> { } pub struct Config { - pub zero_sized_values: usize, - pub full_error_message: bool, + zero_sized_values: usize, + full_error_message: bool, +} +impl Config { + pub fn new() -> Self { + Self { + zero_sized_values: 2_000_000, + full_error_message: true, + } + } + pub fn set_zero_sized_values(&mut self, n: usize) -> &mut Self { + self.zero_sized_values = n; + self + } + pub fn set_full_error_message(&mut self, n: bool) -> &mut Self { + self.full_error_message = n; + self + } +} +impl Default for Config { + fn default() -> Self { + Self::new() + } } macro_rules! assert { @@ -273,7 +299,8 @@ impl<'de> Deserializer<'de> { Ok(res) } fn check_subtype(&mut self) -> Result<()> { - subtype( + subtype_with_config( + OptReport::Silence, &mut self.gamma, &self.table, &self.wire_type, @@ -332,9 +359,11 @@ impl<'de> Deserializer<'de> { // Customize deserailization methods // Several deserialize functions will call visit_byte_buf. // We reserve the first byte to be a tag to distinguish between different callers: - // int(0), nat(1), principal(2), reserved(3), service(4), function(5) + // int(0), nat(1), principal(2), reserved(3), service(4), function(5), blob(6) // This is necessary for deserializing IDLValue because // it has only one visitor and we need a way to know who called the visitor. + #[cfg_attr(docsrs, doc(cfg(feature = "bignum")))] + #[cfg(feature = "bignum")] fn deserialize_int<'a, V>(&'a mut self, visitor: V) -> Result where V: Visitor<'de>, @@ -354,6 +383,8 @@ impl<'de> Deserializer<'de> { bytes.extend_from_slice(&int.0.to_signed_bytes_le()); visitor.visit_byte_buf(bytes) } + #[cfg_attr(docsrs, doc(cfg(feature = "bignum")))] + #[cfg(feature = "bignum")] fn deserialize_nat<'a, V>(&'a mut self, visitor: V) -> Result where V: Visitor<'de>, @@ -419,6 +450,22 @@ impl<'de> Deserializer<'de> { bytes.extend_from_slice(&id); visitor.visit_byte_buf(bytes) } + fn deserialize_blob<'a, V>(&'a mut self, visitor: V) -> Result + where + V: Visitor<'de>, + { + self.unroll_type()?; + check!( + self.expect_type.is_blob(&self.table) && self.wire_type.is_blob(&self.table), + "blob" + ); + let len = Len::read(&mut self.input)?.0; + let blob = self.borrow_bytes(len)?; + let mut bytes = Vec::with_capacity(len + 1); + bytes.push(6u8); + bytes.extend_from_slice(blob); + visitor.visit_byte_buf(bytes) + } fn deserialize_empty<'a, V>(&'a mut self, _visitor: V) -> Result where V: Visitor<'de>, @@ -449,14 +496,19 @@ impl<'de> Deserializer<'de> { { use de::Deserializer; let tid = type_of(&visitor); - if tid != TypeId::of::() // derive Copy - && tid != TypeId::of::() // derive Copy + if tid != TypeId::of::() // derive Copy // OptionVisitor doesn't derive Copy, but has only PhantomData. // OptionVisitor is private and we cannot get TypeId of OptionVisitor, // we also cannot downcast V to concrete type, because of 'de // The only option left seems to be type_name, but it is not guaranteed to be stable, so there is risk here. && !tid.name.starts_with("serde::de::impls::OptionVisitor<") { + #[cfg(feature = "value")] + if tid != TypeId::of::() { + // derive Copy + panic!("Not a valid visitor: {tid:?}"); + } + #[cfg(not(feature = "value"))] panic!("Not a valid visitor: {tid:?}"); } // This is safe, because the visitor either impl Copy or is zero sized @@ -501,8 +553,14 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { } self.unroll_type()?; match self.expect_type.as_ref() { + #[cfg(feature = "bignum")] TypeInner::Int => self.deserialize_int(visitor), + #[cfg(not(feature = "bignum"))] + TypeInner::Int => self.deserialize_i128(visitor), + #[cfg(feature = "bignum")] TypeInner::Nat => self.deserialize_nat(visitor), + #[cfg(not(feature = "bignum"))] + TypeInner::Nat => self.deserialize_u128(visitor), TypeInner::Nat8 => self.deserialize_u8(visitor), TypeInner::Nat16 => self.deserialize_u16(visitor), TypeInner::Nat32 => self.deserialize_u32(visitor), @@ -526,6 +584,10 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { TypeInner::Principal => self.deserialize_principal(visitor), // construct types TypeInner::Opt(_) => self.deserialize_option(visitor), + // This is an optimization for blob, mostly likely used by IDLValue, but it won't help the native Vec + TypeInner::Vec(_) if self.expect_type.is_blob(&self.table) => { + self.deserialize_blob(visitor) + } TypeInner::Vec(_) => self.deserialize_seq(visitor), TypeInner::Record(_) => self.deserialize_struct("_", &[], visitor), TypeInner::Variant(_) => self.deserialize_enum("_", &[], visitor), @@ -564,22 +626,13 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { where V: Visitor<'de>, { - use num_traits::ToPrimitive; + use crate::types::leb128::{decode_int, decode_nat}; self.unroll_type()?; assert!(*self.expect_type == TypeInner::Int); let value: i128 = match self.wire_type.as_ref() { - TypeInner::Int => { - let int = Int::decode(&mut self.input).map_err(Error::msg)?; - int.0 - .to_i128() - .ok_or_else(|| Error::msg("Cannot convert int to i128"))? - } - TypeInner::Nat => { - let nat = Nat::decode(&mut self.input).map_err(Error::msg)?; - nat.0 - .to_i128() - .ok_or_else(|| Error::msg("Cannot convert nat to i128"))? - } + TypeInner::Int => decode_int(&mut self.input)?, + TypeInner::Nat => i128::try_from(decode_nat(&mut self.input)?) + .map_err(|_| Error::msg("Cannot convert nat to i128"))?, t => return Err(Error::subtype(format!("{t} cannot be deserialized to int"))), }; visitor.visit_i128(value) @@ -588,17 +641,12 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { where V: Visitor<'de>, { - use num_traits::ToPrimitive; self.unroll_type()?; check!( *self.expect_type == TypeInner::Nat && *self.wire_type == TypeInner::Nat, "nat" ); - let nat = Nat::decode(&mut self.input).map_err(Error::msg)?; - let value = nat - .0 - .to_u128() - .ok_or_else(|| Error::msg("Cannot convert nat to u128"))?; + let value = crate::types::leb128::decode_nat(&mut self.input)?; visitor.visit_u128(value) } fn deserialize_unit(self, visitor: V) -> Result @@ -671,9 +719,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { { self.unroll_type()?; match (self.wire_type.as_ref(), self.expect_type.as_ref()) { - (TypeInner::Null, TypeInner::Opt(_)) | (TypeInner::Reserved, TypeInner::Opt(_)) => { - visitor.visit_none() - } + (TypeInner::Null | TypeInner::Reserved, TypeInner::Opt(_)) => visitor.visit_none(), (TypeInner::Opt(t1), TypeInner::Opt(t2)) => { self.wire_type = t1.clone(); self.expect_type = t2.clone(); diff --git a/rust/candid/src/error.rs b/rust/candid/src/error.rs index 9181d4a0..39cf280b 100644 --- a/rust/candid/src/error.rs +++ b/rust/candid/src/error.rs @@ -1,30 +1,21 @@ //! `candid::Result = Result>` -use codespan_reporting::diagnostic::Label; use serde::{de, ser}; -use std::io; +use std::{io, num::ParseIntError}; use thiserror::Error; -#[cfg(feature = "parser")] -use crate::parser::token; -#[cfg(feature = "parser")] -use codespan_reporting::{ - diagnostic::Diagnostic, - files::{Error as ReportError, SimpleFile}, - term::{self, termcolor::StandardStream}, -}; - pub type Result = std::result::Result; +#[derive(Debug)] +pub struct Label { + pos: usize, + message: String, +} + #[derive(Debug, Error)] pub enum Error { - #[cfg_attr(docsrs, doc(cfg(feature = "parser")))] - #[cfg(feature = "parser")] - #[error("Candid parser error: {0}")] - Parse(#[from] token::ParserError), - - #[error("binary parser error: {}", .0.get(0).map(|f| format!("{} at byte offset {}", f.message, f.range.start/2)).unwrap_or_else(|| "io error".to_string()))] - Binread(Vec>), + #[error("binary parser error: {}", .0.get(0).map_or_else(|| "io error".to_string(), |f| format!("{} at byte offset {}", f.message, f.pos/2)))] + Binread(Vec