Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore(deps): replace candid next branch with published candid 0.10.30 / candid_parser 0.4.0#147

Merged
lwshang merged 8 commits into
mainfrom
decouple-from-candid-next
Jun 23, 2026
Merged

chore(deps): replace candid next branch with published candid 0.10.30 / candid_parser 0.4.0#147
lwshang merged 8 commits into
mainfrom
decouple-from-candid-next

Conversation

@lwshang

@lwshang lwshang commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Decouples the bindgen crate from the floating candid / candid_parser next branch and pins it to the published candid 0.10.30 / candid_parser 0.4.0 releases.

Why

candid next carried breaking changes — named args baked into candid::types::Function, a HashMap/TypeKey-based TypeEnv, and a serde rewrite — that are not headed to a stable release. Depending on it tied the build to a moving target. This PR keeps candid on its stable 0.10 type model and recovers the only feature the bindgen actually needs — named function arguments — from the parser AST instead.

Changes

  • Deps: candid / candid_parser → published 0.10.30 / 0.4.0 (was the next branch).
  • parser.rs: builds nameless candid::types::Function / Class and keys TypeEnv by String (no ArgType / TypeKey).
  • TS binding generators: recover argument names from the parser AST (syntax::IDLArgType.name), threaded alongside the checked types. Service-method and func-type-alias signatures keep meaningful parameter names; nested/anonymous funcs fall back to positional arg{i} (valid TS).
  • Native TS type definitions are emitted in sorted order via to_sorted_iter, matching the original-format generators, so output is deterministic regardless of candid's internal TypeEnv representation.

Test plan

  • cargo build (host) and cargo build --target wasm32-unknown-unknown — clean
  • cargo fmt --check / cargo clippy — clean
  • JS test suite (vitest) — 52/52 passing, type-check clean

🤖 Generated with Claude Code

lwshang and others added 7 commits June 23, 2026 10:06
Migrate the bindgen crate off the floating `candid`/`candid_parser` `next`
branch. Deps now point at the candid PR branch (named-args parser support);
they will switch to the published `candid` 0.10 / `candid_parser` 0.4 releases
once dfinity/candid#742 is merged and released.

`candid` 0.10's `Function`/`Class` do not carry argument names, so:
- `parser.rs` builds nameless `candid::types::Function` and keys `TypeEnv`
  by `String` (no `ArgType` / `TypeKey`).
- The TypeScript binding generators recover argument names from the parser
  AST (`syntax::IDLArgType.name`) threaded alongside the checked types, so
  service-method and func-type signatures keep meaningful parameter names
  and fall back to positional `arg{i}` only where the AST has none.

Builds clean for host and wasm32-unknown-unknown.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
candid 0.10's `TypeEnv` is a `BTreeMap<String, Type>` that iterates in
alphabetical order, whereas the old candid `next` branch iterated in an
arbitrary internal order. The native TypeScript generator walked the env
directly (`env.0.keys()`), so its declaration order flipped after the
candid migration, breaking the `example` snapshots.

Iterate via `env.to_sorted_iter()` instead, matching the original-format
generators in typescript.rs / javascript.rs. Ordering is now intentional
and independent of candid's internal `TypeEnv` representation. Regenerated
snapshots are pure reorderings — generated content is byte-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@lwshang lwshang changed the title chore(deps): track candid PR branch and source arg names from parser AST chore(deps): replace candid next branch with published candid 0.10.30 / candid_parser 0.4.0 Jun 23, 2026
@lwshang lwshang marked this pull request as ready for review June 23, 2026 17:49
@lwshang lwshang requested a review from a team as a code owner June 23, 2026 17:49
Copilot AI review requested due to automatic review settings June 23, 2026 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Rust bindgen generator to stop depending on the floating candid / candid_parser next branch and instead pin to published releases, while preserving named-argument output for TypeScript by recovering argument names from the Candid parser AST and making type emission deterministic.

Changes:

  • Pin candid / candid_parser to crates.io releases (0.10.30 / 0.4.0) and update affected generator code to match the stable 0.10 type model.
  • Adjust parsing/binding generation to drop argument names from checked candid::types::Function and recover them from the syntax AST when emitting TS signatures.
  • Emit TS native type definitions in sorted order and update snapshot expectations accordingly.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/snapshots/wasm-generate/typescript/example/example.ts.snapshot Updates expected TS output ordering/determinism after generator changes.
tests/snapshots/wasm-generate/typescript-root-export/example/example.ts.snapshot Updates expected TS output ordering/determinism for root-export variant.
tests/snapshots/wasm-generate/root-export/example/example.ts.snapshot Updates expected TS output ordering/determinism for wasm root-export path.
tests/snapshots/wasm-generate/root-export/example/example.d.ts.snapshot Updates expected .d.ts output ordering/determinism for wasm root-export path.
tests/snapshots/wasm-generate/no-root-export/example/example.ts.snapshot Updates expected TS output ordering/determinism for no-root-export path.
tests/snapshots/wasm-generate/no-root-export/example/example.d.ts.snapshot Updates expected .d.ts output ordering/determinism for no-root-export path.
tests/snapshots/generate/example/example.ts.snapshot Updates expected host-generate TS output ordering/determinism.
tests/snapshots/generate/example/example.d.ts.snapshot Updates expected host-generate .d.ts output ordering/determinism.
src/core/generate/rs/src/parser.rs Drops ArgType argument-name retention in checked types; uses stable 0.10 TypeEnv keying and function arg/ret types.
src/core/generate/rs/src/bindings/typescript.rs Updates TS printer to the stable 0.10 Function arg/ret representation.
src/core/generate/rs/src/bindings/typescript_native/original_typescript_types.rs Removes TypeKey usage and updates var type creation to use &str.
src/core/generate/rs/src/bindings/typescript_native/new_typescript_native_types.rs Adds sorted emission and recovers argument names from syntax AST for TS native signatures.
src/core/generate/rs/src/bindings/typescript_native/conversion_functions_generator.rs Updates multi-return conversion to use &[Type] instead of &[ArgType].
src/core/generate/rs/src/bindings/typescript_native/compile_wrapper.rs Removes TypeKey usage and updates conversions to stable 0.10 function type shapes.
src/core/generate/rs/src/bindings/javascript.rs Updates JS/TS IDL runtime printer to stable 0.10 function arg/ret representation.
src/core/generate/rs/Cargo.toml Pins candid and candid_parser to published versions.
Cargo.lock Updates lockfile to reflect crates.io dependencies and transitive changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…orts

The native TS generator computed a synthetic `span` carrying each type's
leading doc comment (via `add_comments`) but then used `DUMMY_SP` on the
`ExportDecl` for record, service, function, and variant types — so their
type-level IDL doc comments were silently dropped from the generated output
(only the `Var` and fallback arms used the span). Use the computed `span` on
all four export sites, matching those working arms.

Doc-comment escaping is unchanged: the `malicious_doc` fixture confirms `*/`
sequences in newly-emitted type-level comments are escaped to `*\/`, so they
cannot break out of the JSDoc block.

Reported by Copilot review on #147.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@lwshang lwshang merged commit 99791c3 into main Jun 23, 2026
11 checks passed
@lwshang lwshang deleted the decouple-from-candid-next branch June 23, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants