Skip to content

Commit

Permalink
release candid 0.9 (#447)
Browse files Browse the repository at this point in the history
* release candid 0.9

* fix

* bump clap to v4

* bump lalrpop and use 2021 edition

* fix
  • Loading branch information
chenyan-dfinity authored Jul 1, 2023
1 parent e660ff0 commit 199fd05
Show file tree
Hide file tree
Showing 14 changed files with 590 additions and 405 deletions.
537 changes: 314 additions & 223 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

# Changelog

## Rust 0.9.0-beta
## 2022-06-30 (Rust 0.9.0)

### Breaking changes:

* Deserializer only checks subtyping for reference types, fully conforming to Candid spec 1.4. You can now decode `opt variant` even if the variant tags are not the same, allowing upgrading variant types without breaking the client code.
* The old `candid::Type` is now `candid::TypeInner`, and `Type` is a newtype of `Rc<TypeInner>`. This change significantly improves deserialization performance (25% -- 50% improvements)
* `candid::parser` module is only available under feature flag `"parser"`. This significantly cut down compilation time and Wasm binary size
* `candid::parser` module is only available under feature flag `"parser"`. This significantly cuts down compilation time and Wasm binary size
* Disable the use of `candid::Func` and `candid::Service` to avoid footguns. Use `define_function!` and `define_service!` macro instead
* `candid::parser::typing::TypeEnv` moved to `candid::types::TypeEnv`. Use of `candid::TypeEnv` is not affected
* `candid::parser::types::FuncMode` moved to `candid::types::FuncMode`
Expand All @@ -22,7 +22,10 @@
* Macros for constructing type AST nodes: `service!`, `func!` and `field!`
* Support future types
* Bound recursion depth in deserialization for non-Wasm target (Wasm canister doesn't have a specified C ABI, and runs in a sandbox. It's okay to stack overflow)
* Limit the size of vec null/reversed in deserialization
* `Nat` serialization for JSON and CBOR
* Support custom candid path for `export_service!`
* Support `composite_query` function annotation

## 2022-11-17 (Rust 0.8.3 -- 0.8.4)

Expand Down
8 changes: 4 additions & 4 deletions rust/candid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "candid"
version = "0.9.0-beta.4"
edition = "2018"
version = "0.9.0"
edition = "2021"
authors = ["DFINITY Team"]
description = "Candid is an interface description language (IDL) for interacting with canisters running on the Internet Computer."
homepage = "https://internetcomputer.org/docs/current/developer-docs/build/candid/candid-concepts"
Expand All @@ -16,7 +16,7 @@ include = ["src", "Cargo.toml", "build.rs", "LICENSE", "README.md"]
build = "build.rs"

[build-dependencies]
lalrpop = { version = "0.19.0", optional = true }
lalrpop = { version = "0.20.0", optional = true }

[dependencies]
byteorder = "1.4.3"
Expand All @@ -38,7 +38,7 @@ thiserror = "1.0.20"
anyhow = "1.0"
binread = { version = "2.1", features = ["debug_template"] }

lalrpop-util = { version = "0.19.0", optional = true }
lalrpop-util = { version = "0.20.0", optional = true }
logos = { version = "0.12", optional = true }

arbitrary = { version = "1.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/src/bindings/motoko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn escape(id: &str, is_method: bool) -> RcDoc {
} else if !is_method {
str("_").append(crate::idl_hash(id).to_string()).append("_")
} else {
panic!("Candid method {} is not a valid Motoko id", id);
panic!("Candid method {id} is not a valid Motoko id");
}
}

Expand Down
5 changes: 1 addition & 4 deletions rust/candid/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ impl<'de> Deserializer<'de> {
where
V: Visitor<'de>,
{
use std::convert::TryInto;
self.unroll_type()?;
assert!(*self.expect_type == TypeInner::Int);
let mut bytes = vec![0u8];
Expand Down Expand Up @@ -399,7 +398,7 @@ impl<'de> Deserializer<'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<")
{
panic!("Not a valid visitor: {:?}", tid);
panic!("Not a valid visitor: {tid:?}");
}
// This is safe, because the visitor either impl Copy or is zero sized
let v = unsafe { std::ptr::read(&visitor) };
Expand Down Expand Up @@ -506,7 +505,6 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
where
V: Visitor<'de>,
{
use std::convert::TryInto;
self.unroll_type()?;
assert!(*self.expect_type == TypeInner::Int);
let value: i128 = match self.wire_type.as_ref() {
Expand All @@ -526,7 +524,6 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
where
V: Visitor<'de>,
{
use std::convert::TryInto;
self.unroll_type()?;
check!(
*self.expect_type == TypeInner::Nat && *self.wire_type == TypeInner::Nat,
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Error {
InvalidToken { location } => {
Label::primary((), *location..location + 1).with_message("Invalid token")
}
UnrecognizedEOF { location, expected } => {
UnrecognizedEof { location, expected } => {
diag = diag.with_notes(report_expected(expected));
Label::primary((), *location..location + 1).with_message("Unexpected EOF")
}
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/src/types/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ macro_rules! service {
let mut ms = vec![ $(($meth.to_string(), $ty)),* ];
ms.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap());
if let Err(e) = $crate::utils::check_unique(ms.iter().map(|m| &m.0)) {
panic!(e);
panic!("{e}");
}
Into::<$crate::types::Type>::into($crate::types::TypeInner::Service(ms))
}}
Expand Down
1 change: 0 additions & 1 deletion rust/candid/src/types/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ impl<'de> Deserialize<'de> for Nat {
formatter.write_str("Nat value")
}
fn visit_i64<E: de::Error>(self, v: i64) -> Result<Nat, E> {
use std::convert::TryFrom;
Ok(Nat(BigUint::try_from(v).map_err(|_| {
de::Error::custom("int cannot be converted to nat")
})?))
Expand Down
1 change: 0 additions & 1 deletion rust/candid/src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ impl<'de> Visitor<'de> for IDLValueVisitor {
visit_prim!(Float64, f64);
// Deserialize Candid specific types: Bignumber, principal, reversed, service, function
fn visit_byte_buf<E: de::Error>(self, value: Vec<u8>) -> DResult<E> {
use std::convert::TryFrom;
let (tag, mut bytes) = value.split_at(1);
match tag[0] {
0u8 => {
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "candid_derive"
version = "0.6.1"
edition = "2018"
edition = "2021"
authors = ["DFINITY Team"]
description = "Macros implementation of #[derive(CandidType)] for the Candid."
homepage = "https://docs.rs/candid_derive"
Expand Down
6 changes: 3 additions & 3 deletions tools/didc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "didc"
version = "0.3.1"
version = "0.3.2"
authors = ["DFINITY Team"]
edition = "2018"
edition = "2021"

[dependencies]
candid = { path = "../../rust/candid", features = ["all"] }
clap = { version = "3", features = ["derive"] }
clap = { version = "4.3", features = ["derive"] }
pretty-hex = "0.2.1"
hex = "0.4.2"
anyhow = "1.0.32"
Expand Down
14 changes: 7 additions & 7 deletions tools/didc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ enum Command {
Bind {
/// Specifies did file for code generation
input: PathBuf,
#[clap(short, long, possible_values = &["js", "ts", "did", "mo", "rs", "rs-agent"])]
#[clap(short, long, value_parser = ["js", "ts", "did", "mo", "rs", "rs-agent"])]
/// Specifies target language
target: String,
},
/// Generate test suites for different languages
Test {
/// Specifies .test.did file for test suites generation
input: PathBuf,
#[clap(short, long, possible_values = &["js", "did"], default_value = "js")]
#[clap(short, long, value_parser = ["js", "did"], default_value = "js")]
/// Specifies target language
target: String,
},
/// Compute the hash of a field name
Hash { input: String },
/// Encode Candid value
Encode {
#[clap(parse(try_from_str = parse_args))]
#[clap(value_parser = parse_args)]
/// Specifies Candid textual format for encoding
/// If omitted, the text will be read from stdin.
args: Option<IDLArgs>,
#[clap(flatten)]
annotate: TypeAnnotation,
#[clap(short, long, possible_values = &["hex", "pretty", "blob"], default_value = "hex")]
#[clap(short, long, value_parser = ["hex", "pretty", "blob"], default_value = "hex")]
/// Specifies hex format
format: String,
},
Expand All @@ -55,7 +55,7 @@ enum Command {
/// Specifies Candid binary data in hex string.
/// If omitted, the hex will be read from stdin.
blob: Option<String>,
#[clap(short, long, possible_values = &["hex", "blob"], default_value = "hex")]
#[clap(short, long, value_parser = ["hex", "blob"], default_value = "hex")]
/// Specifies hex format
format: String,
#[clap(flatten)]
Expand All @@ -71,7 +71,7 @@ enum Command {
#[clap(short, long)]
/// Load random value generation config from file
file: Option<String>,
#[clap(short, long, possible_values = &["did", "js"], default_value = "did")]
#[clap(short, long, value_parser = ["did", "js"], default_value = "did")]
/// Specifies target language
lang: String,
#[clap(short, long, requires("method"))]
Expand All @@ -90,7 +90,7 @@ enum Command {
#[derive(Parser)]
struct TypeAnnotation {
#[clap(name = "types", short, long)]
#[clap(parse(try_from_str = parse_types))]
#[clap(value_parser = parse_types)]
/// Annotates values with Candid types
tys: Option<IDLTypes>,
#[clap(short, long, conflicts_with("types"), requires("defs"))]
Expand Down
Loading

0 comments on commit 199fd05

Please sign in to comment.