Skip to content

[draft] serde-generate / solidity: allow non-contiguous enum variant indices#98

Draft
ma2bd wants to merge 8 commits into
zefchain:mainfrom
ma2bd:fix_solidity_enums
Draft

[draft] serde-generate / solidity: allow non-contiguous enum variant indices#98
ma2bd wants to merge 8 commits into
zefchain:mainfrom
ma2bd:fix_solidity_enums

Conversation

@ma2bd
Copy link
Copy Markdown
Contributor

@ma2bd ma2bd commented May 15, 2026

Summary

Although the derive macros of Serde always generate contiguous variant indices, it could be desirable to relax this constraint in some cases (see linera-io/linera-protocol#6309).

Test Plan

CI

ma2bd added 8 commits May 17, 2026 00:22
… Serde index, with precomputed hex discriminants.

This also fixes a latent SimpleEnum bug: the previous path emitted the discriminant as a single byte and produced wrong BCS for indices >=128 (SimpleEnum now routes through the same ULEB128 helper as the complex Enum path).
…ncode variant indices, not just length prefixes.
…ant carries a payload (sparse all-Unit or >256-variant all-Unit enums), with a regression test.
…Write in hex_literal to avoid per-byte allocation.
…ip test, exercising the multi-byte ULEB128 indices the old single-byte codec silently mishandled.
…rect integer-to-enum cast (guarded by a range check to defeat uint8 truncation), shrinking bytecode from O(N) branches to a constant.
…etter, guaranteeing user-supplied names cannot collide with generated lowercase prefixes (offset_, seq_, opt_, ...) in function names; covered by a should_panic test.
@ma2bd ma2bd force-pushed the fix_solidity_enums branch from 2f0dc7a to 2cd876e Compare May 17, 2026 19:20
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.

1 participant