Skip to content

feat: add entry_id to IDL AST and use it across parser and generators#1275

Merged
vobradovich merged 6 commits intomasterfrom
vo/ast-entry-id
Apr 2, 2026
Merged

feat: add entry_id to IDL AST and use it across parser and generators#1275
vobradovich merged 6 commits intomasterfrom
vo/ast-entry-id

Conversation

@vobradovich
Copy link
Copy Markdown
Member

Summary

This PR adds entry_id as a first-class field in the IDL AST for:

  • program constructors
  • service functions
  • service events

The parser and metadata builders now normalize these values into the AST, and JS/Rust generators consume the normalized entry_id directly instead of recomputing it from annotations or position.

What changed

  • Added entry_id: u16 to AST nodes for ctors, funcs, and events.
  • Normalized constructor entry_id in ProgramUnit::normalize().
  • Normalized function and event entry_id in ServiceUnit::normalize().
  • Updated the parser to initialize and normalize entry_id during AST construction.
  • Added validation for @partial services:
    • require explicit @entry-id on all functions/events
    • reject malformed @entry-id values
    • reject duplicate entry IDs within funcs/events/ctors
  • Updated Rust and JS client generators to use entry_id from the AST directly.
  • Preserved JS compatibility for normalized docs that omit entry_id by falling back to index.
  • Normalized ProgramUnit in idl-gen so metadata-generated constructors get stable entry IDs too.

Why

Previously, entry IDs were derived ad hoc from annotations or array position in multiple places. That made partial-service handling fragile and duplicated logic across parser, JS runtime, and generators.

This change centralizes entry-id resolution in the AST normalization layer so downstream code reads one canonical value.

Tests

Added/updated coverage for:

  • partial services with explicit @entry-id
  • missing @entry-id on partial services
  • invalid @entry-id values on partial services
  • JS fallback behavior when normalized docs omit entry_id
  • metadata-generated programs with multiple constructors receiving sequential constructor entry IDs

@vobradovich vobradovich self-assigned this Apr 2, 2026
@vobradovich vobradovich requested a review from m62624 April 2, 2026 09:42
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an explicit entry_id field to IDL components like constructors, service functions, and enum variants across both JavaScript and Rust implementations. The changes include adding normalization logic to derive these IDs from @entry-id annotations or positional indices, updating code generators to utilize the new field, and implementing validation to ensure ID uniqueness and mandatory annotations for partial services. Feedback focuses on maintaining consistency between the JS and Rust normalization logic, reducing code duplication in annotation parsing, addressing a performance regression in the type validator's scope lookup, and extending @entry-id format validation to all service types.

Comment thread js/parser-idl-v2/src/idl-v2-impls.ts
Comment thread rs/idl-meta/src/ast.rs
Comment thread rs/idl-parser-v2/src/post_process.rs
Comment thread rs/idl-parser-v2/src/post_process.rs
@vobradovich vobradovich merged commit 60d7cf1 into master Apr 2, 2026
6 checks passed
@vobradovich vobradovich deleted the vo/ast-entry-id branch April 2, 2026 11:19
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.

2 participants