Skip to content

Commit

Permalink
Candid type selector (#544)
Browse files Browse the repository at this point in the history
* replace dhall with toml

* checkpoint

* checkpoint

* checkpoint

* checkpoint

* checkpoint

* checkpoint

* checkpoint

* random works

* test

* fix

* fix

* Refactor Rust bindgen with the new config (#546)

* checkpoint

* checkpoint

* connect with didc and test

* checkpoint

* vis

* vis

* checkpoint

* fix merging semantics

* checkpoint

* fix

* fix

* fix root config fallback

* checkpoint

* add unmatched config

* fix attr

* handlebar

* update test, diff is only space and newline

* forget to commit test

* move pp_actor inside impl

* fix

* refactor

* init args

* add test

* add_config

* clippy

* changelog and bump version
  • Loading branch information
chenyan-dfinity authored May 3, 2024
1 parent d2654f9 commit ea3c3e9
Show file tree
Hide file tree
Showing 33 changed files with 1,597 additions and 1,376 deletions.
778 changes: 248 additions & 530 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@

# Changelog

## 2024-05-03

### candid_parser 0.2.0-beta.0

* Breaking changes:
+ Rewrite `configs` and `random` modules, adapting TOML format as the parser. `configs` module is no longer under a feature flag, and no longer depend on dhall.
+ Rewrite Rust bindgen to use the new `configs` module. Use `emit_bindgen` to generate type bindings, and use `output_handlebar` to provide a handlebar template for the generated module. `compile` function provides a default template. The generated file without config is exactly the same as before.

* TO-DOs
+ Spec for path and matching semantics
+ Warning for unused path
+ Rust bindgen:
* Generate `use_type` tests. How to handle recursive types?
* Threading state through `nominalize`
* When the path starts with method, duplicate type definition when necessary.
* Number label renaming

## 2024-04-11

### Candid 0.10.7 -- 0.10.5
### Candid 0.10.5 -- 0.10.8

* Switch `HashMap` to `BTreeMap` in serialization and `T::ty()`. This leads to around 20% perf improvement for serializing complicated types.
* Disable memoization for unrolled types in serialization to save cycle cost. In some cases, type table can get slightly larger, but it's worth the trade off.
* Fix bug in `text_size`
* Fix decoding cost calculation overflow
* Fix length check in decoding principal type

## 2024-02-27

Expand Down
2 changes: 1 addition & 1 deletion rust/candid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "candid"
version = "0.10.7"
version = "0.10.8"
edition = "2021"
rust-version.workspace = true
authors = ["DFINITY Team"]
Expand Down
8 changes: 4 additions & 4 deletions rust/candid/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ impl<'a> types::Serializer for &'a mut ValueSerializer {
self.serialize_principal(blob)?;
self.serialize_text(meth)
}
fn serialize_option<T: ?Sized>(self, v: Option<&T>) -> Result<()>
fn serialize_option<T>(self, v: Option<&T>) -> Result<()>
where
T: super::CandidType,
T: super::CandidType + ?Sized,
{
match v {
None => {
Expand Down Expand Up @@ -207,9 +207,9 @@ pub struct Compound<'a> {
}
impl<'a> types::Compound for Compound<'a> {
type Error = Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
T: types::CandidType,
T: types::CandidType + ?Sized,
{
value.idl_serialize(&mut *self.ser)?;
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions rust/candid/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ pub trait Serializer: Sized {
fn serialize_text(self, v: &str) -> Result<(), Self::Error>;
fn serialize_null(self, v: ()) -> Result<(), Self::Error>;
fn serialize_empty(self) -> Result<(), Self::Error>;
fn serialize_option<T: ?Sized>(self, v: Option<&T>) -> Result<(), Self::Error>
fn serialize_option<T>(self, v: Option<&T>) -> Result<(), Self::Error>
where
T: CandidType;
T: CandidType + ?Sized;
fn serialize_struct(self) -> Result<Self::Compound, Self::Error>;
fn serialize_vec(self, len: usize) -> Result<Self::Compound, Self::Error>;
fn serialize_blob(self, v: &[u8]) -> Result<(), Self::Error>;
Expand All @@ -94,9 +94,9 @@ pub trait Serializer: Sized {

pub trait Compound {
type Error;
fn serialize_element<T: ?Sized>(&mut self, v: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, v: &T) -> Result<(), Self::Error>
where
T: CandidType;
T: CandidType + ?Sized;
// Used for simulating serde(with = "serde_bytes"). We can remove this when specialization is stable in Rust,
// or generalize this function to take a closure for with.
#[doc(hidden)]
Expand Down
11 changes: 5 additions & 6 deletions rust/candid_parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "candid_parser"
version = "0.1.4"
version = "0.2.0-beta.0"
edition = "2021"
rust-version.workspace = true
authors = ["DFINITY Team"]
Expand All @@ -26,18 +26,18 @@ num-bigint.workspace = true
pretty.workspace = true
thiserror.workspace = true
anyhow.workspace = true
serde.workspace = true

lalrpop-util = "0.20.0"
logos = "0.13"
convert_case = "0.6"
handlebars = "5.1"
toml = { version = "0.8", default-features = false, features = ["parse"] }

arbitrary = { workspace = true, 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 }
num-traits = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
dialoguer = { version = "0.11", default-features = false, features = ["editor", "completion"], optional = true }
console = { version = "0.15", optional = true }
ctrlc = { version = "3.4", optional = true }
Expand All @@ -48,8 +48,7 @@ test-generator = "0.3.0"
rand.workspace = true

[features]
configs = ["serde_dhall"]
random = ["configs", "arbitrary", "fake", "rand", "num-traits", "serde"]
random = ["dep:arbitrary", "dep:fake", "dep:rand", "dep:num-traits"]
assist = ["dep:dialoguer", "dep:console", "dep:ctrlc"]
all = ["random", "assist"]

Expand Down
Loading

0 comments on commit ea3c3e9

Please sign in to comment.