Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

## Unreleased

### Candid

* [BREAKING]: type representation was optimized to improve performance:
+ In `Type::Var(var)` `var` now has type `TypeKey` instead of `String`. Calling `var.as_str()` returns `&str` and `var.to_string()` returns a `String`. The string representation of indexed variables remains `table{index}` to maintain compatibility with previous versions.
+ `TypeEnv` now contains a `HashMap` instead of `BTreeMap`. Code that relied on the iteration order of the map (e.g. `env.0.iter()`) should make use of the newly added `TypeEnv::to_sorted_iter()` method which returns types sorted by their keys.
+ The `args` field of the `candid::types::internal::Function` struct now is a `Vec<ArgType>` instead of `Vec<Type>`, to preserve argument names.
+ The `TypeInner::Class` variant now takes `Vec<ArgType>` instead of `Vec<Type>` as its first parameter, to preserve argument names.

* [BREAKING]: Removed the `candid::pretty::concat` function
+ `candid::pretty::enclose` and `candid::pretty:enclose_space` don't collapse the separators on empty documents anymore

* Non-breaking changes:
+ Added `pp_named_args`, `pp_named_init_args` in `pretty::candid` module.
+ The `JavaScript` `didc` target now exports its generated IDL type objects.
+ The `JavaScript` and `TypeScript` `didc` targets now export `idlService` and `idlInitArgs` (non-factory-function altneratives to `idlFactory` and `init`).

### candid_parser

* Breaking changes:
+ The `args` field in both `FuncType` and `IDLInitArgs` now have type `Vec<IDLArgType>`.

* Non-breaking changes:
+ Supports parsing the arguments' names for `func` and `service` (init args).

## 2025-08-04

### Candid 0.10.17
Expand Down Expand Up @@ -390,7 +414,7 @@ The source code of this tool has been removed, as it was deprecated in [PR#405](
* Bump ic-types to 0.3
* `candid::utils::service_compatible` to check for upgrade compatibility of two service types

## 2021-12-20
## 2021-12-20

### Rust (0.7.9)

Expand All @@ -416,7 +440,7 @@ The source code of this tool has been removed, as it was deprecated in [PR#405](

### Rust (0.7.5 -- 0.7.7)

* Support import when parsing did files with `check_file` function
* Support import when parsing did files with `check_file` function
* Fix TypeScript binding for reference types

### Candid UI
Expand All @@ -435,7 +459,7 @@ The source code of this tool has been removed, as it was deprecated in [PR#405](
* Add `#[candid_path("path_to_candid")]` helper attribute to the candid derive macro
* Update `ic-types` to 0.2.0

## 2021-06-03
## 2021-06-03

### Spec

Expand Down Expand Up @@ -475,7 +499,7 @@ The source code of this tool has been removed, as it was deprecated in [PR#405](
* Fix TypeScript binding for tuple
* Rust support for Func and Service value

## 2021-03-17
## 2021-03-17

### Rust (0.6.18)

Expand Down Expand Up @@ -626,7 +650,7 @@ The source code of this tool has been removed, as it was deprecated in [PR#405](

* No longer requires the shortest LEB128 number in deserialization [#79](https://github.com/dfinity/candid/pull/79)

### Rust
### Rust

* Parser improvements:
+ Floats in fractional number, no e-notation yet
Expand Down
27 changes: 26 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore-interior-mutability = ["candid::types::type_key::TypeKey"]
27 changes: 26 additions & 1 deletion rust/bench/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion rust/bench/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,15 @@ fn nns() -> BenchResult {
let args = candid_parser::parse_idl_args(motion_proposal).unwrap();
let serv = serv.unwrap();
let method = &env.get_method(&serv, "manage_neuron").unwrap();
let arg_tys = method
.args
.iter()
.map(|arg| arg.typ.clone())
.collect::<Vec<_>>();
drop(_p);
let bytes = {
let _p = bench_scope("1. Encoding");
args.to_bytes_with_types(&env, &method.args).unwrap()
args.to_bytes_with_types(&env, &arg_tys).unwrap()
};
{
let _p = bench_scope("2. Decoding");
Expand Down
2 changes: 2 additions & 0 deletions rust/candid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ candid_derive = { path = "../candid_derive", version = "=0.10.17" }
ic_principal = { path = "../ic_principal", version = "0.1.0" }
binread = { version = "2.2", features = ["debug_template"] }
byteorder = "1.5.0"
foldhash = "0.1.3"
hashbrown = "0.15"
leb128 = "0.2.5"
paste = "1.0"
hex.workspace = true
Expand Down
18 changes: 9 additions & 9 deletions rust/candid/src/binary_parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::types::internal::{Field, Function, Label, Type, TypeInner};
use crate::types::internal::{ArgType, Field, Function, Label, Type, TypeInner, TypeKey};
use crate::types::type_env::TypeMap;
use crate::types::{FuncMode, TypeEnv};
use anyhow::{anyhow, Context, Result};
use binread::io::{Read, Seek};
Expand Down Expand Up @@ -135,17 +136,14 @@ pub struct PrincipalBytes {
pub inner: Vec<u8>,
}

fn index_to_var(ind: i64) -> String {
format!("table{ind}")
}
impl IndexType {
fn to_type(&self, len: u64) -> Result<Type> {
Ok(match self.index {
v if v >= 0 => {
if v >= len as i64 {
return Err(anyhow!("type index {} out of range", v));
}
TypeInner::Var(index_to_var(v))
TypeInner::Var(TypeKey::indexed(v))
}
-1 => TypeInner::Null,
-2 => TypeInner::Bool,
Expand Down Expand Up @@ -201,7 +199,10 @@ impl ConsType {
let mut args = Vec::new();
let mut rets = Vec::new();
for arg in &f.args {
args.push(arg.to_type(len)?);
args.push(ArgType {
name: None,
typ: arg.to_type(len)?,
});
}
for ret in &f.rets {
rets.push(ret.to_type(len)?);
Expand Down Expand Up @@ -233,13 +234,12 @@ impl ConsType {
}
impl Table {
fn to_env(&self, len: u64) -> Result<TypeEnv> {
use std::collections::BTreeMap;
let mut env = BTreeMap::new();
let mut env = TypeMap::default();
for (i, t) in self.table.iter().enumerate() {
let ty = t
.to_type(len)
.with_context(|| format!("Invalid table entry {i}: {t:?}"))?;
env.insert(index_to_var(i as i64), ty);
env.insert(TypeKey::indexed(i as i64), ty);
}
// validate method has func type
for t in env.values() {
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub mod pretty;

// Candid hash function comes from
// https://caml.inria.fr/pub/papers/garrigue-polymorphic_variants-ml98.pdf
// Not public API. Only used by tests.
// Not public API.
// Remember to update the same function in candid_derive if you change this function.
#[doc(hidden)]
#[inline]
Expand Down
Loading