fix(core/emitter): widen string-literal enum tag to u16 for 257+ members - #200
Open
zuohuadong wants to merge 1 commit into
Open
fix(core/emitter): widen string-literal enum tag to u16 for 257+ members#200zuohuadong wants to merge 1 commit into
zuohuadong wants to merge 1 commit into
Conversation
R5 emitted every string-literal union as enum(u8), which overflows the u8 ordinal range once a union has 257 or more members (Zig rejects member values >= 256 under enum(u8)). Apps with large generated unions currently need a local overlay to build. Use enum(u16) only when members.length > 256; 256 members still occupy ordinals 0..255 and stay enum(u8). Wire order, payload layout and the one-line/multi-line formatting paths are unchanged.
|
@zas4exd is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
R5 emits every string-literal union as
enum(u8). Once a union has 257 or more members, the zero-based ordinals exceed theu8range and Zig rejects the generated declaration (enum(u8)cannot hold member value256). Apps with large generated unions currently need a local overlay to build.This change uses
enum(u16)only whenmembers.length > 256; unions with 256 members still occupy ordinals0..255and stayenum(u8). Wire order, payload layout, and the one-line/multi-line formatting paths are unchanged.Why this is general (not app-specific)
The u8 ceiling is a property of Zig's
enum(u8)representation, not of any app's domain. Any Native SDK app whose transpiledMsg/catalog union crosses 257 members hits this today and must carry a local emitter patch. Keeping it local means every SDK upgrade re-baselines the overlay; landing it upstream removes that surface for everyone.Behavior
enum(u8)enum(u8)(unchanged)enum(u8)(overflows at runtime once a member maps to 255 is fine, but a 257th member cannot be represented)enum(u8)(unchanged; 256 members occupy0..255)enum(u8)(fails to compile)enum(u16)Test coverage
R5 string-literal union becomes a wire-stable enumstill assertsenum(u8)for 3 members.R5 string-literal union with 257+ members emits enum(u16)assertsenum(u16),m0 = 0,,m256 = 256,.R5 string-literal union with exactly 256 members stays enum(u8)guards the boundary.`packages/core` test suite: 152/152 pass with the change.
Compatibility
No wire/protocol change: the on-the-wire tag is the declaration ordinal, and consumers that compare by tag name (
.all,.done, switch scrutinee) are unaffected. A u16 tag is a strict superset of u8 for apps that currently fit in u8.