Skip to content

Support named tuple components in event signatures#1211

Merged
DZakh merged 4 commits into
mainfrom
claude/test-issue-1206-3kitR
May 15, 2026
Merged

Support named tuple components in event signatures#1211
DZakh merged 4 commits into
mainfrom
claude/test-issue-1206-3kitR

Conversation

@DZakh

@DZakh DZakh commented May 15, 2026

Copy link
Copy Markdown
Member

Summary

Adds a custom event signature parser that accepts named tuple components, enabling event signatures like event E((uint a, uint b) data) to work without requiring an ABI file. Previously, alloy's signature parser rejected these, causing codegen to fail when no abi_file_path was provided.

Key Changes

  • Introduced parse_event_signature_to_alloy() function that delegates to a new sig_parser module
  • Implemented custom recursive descent parser (sig_parser) that:
    • Parses event signatures with optional event keyword and anonymous modifier
    • Supports named tuple components in both top-level and nested contexts
    • Handles array suffixes ([], [N]) on any type
    • Preserves component names in the resulting AlloyEvent for downstream codegen
  • Updated parse_event() in abi_compat.rs to use the new parser
  • Updated Event::get_abi_event() in system_config.rs to use the new parser as fallback
  • Added regression tests verifying:
    • Named nested tuples parse correctly and preserve field names
    • Tuple arrays with named components work alongside indexed parameters
    • Event selector matches the canonical (unnamed) signature per ABI spec

Implementation Details

The sig_parser module uses a Cursor struct for position tracking and implements:

  • parse(): Entry point handling event keyword, name, parameters, and anonymous modifier
  • parse_event_param(): Parses top-level parameters with optional indexed keyword
  • parse_param(): Parses tuple component parameters (no indexed allowed)
  • parse_type(): Recursively handles leaf types, tuples, and array suffixes
  • Helper methods on Cursor for character/whitespace/identifier/digit parsing

Component names are preserved through AlloyParam and AlloyEventParam structures, allowing the ABI conversion pipeline to emit named record fields in codegen output.

https://claude.ai/code/session_017kSBtmRyLh7wPM89p29LXM

Summary by CodeRabbit

  • Bug Fixes

    • Fixed parsing of event signatures containing named tuple components, resolving previous compatibility issues.
    • Improved error handling with clearer contextual messages for event signature parsing.
  • Tests

    • Added regression tests for event signatures with named tuple types, including tuple arrays and indexed parameters.

Review Change Stack

claude added 3 commits May 14, 2026 14:34
Custom event signatures with named tuple components — e.g.
`Event((uint40 a, uint24 b) info)` — fail to parse via
`AlloyEvent::parse`, blocking codegen without an ABI file path.
Fixes #1206. alloy's `Event::parse` rejects component names inside
tuple types (e.g. `(uint40 a, uint24 b) info`), forcing users with
nested-tuple events to provide an `abi_file_path`.

Add a permissive fallback parser that builds an `AlloyEvent` with the
named components populated. Selector and ABI signature derive from the
canonical (unnamed) form, so existing call sites are unaffected.
Always route human-readable event signatures through our parser
instead of trying alloy's first. JSON ABI deserialization keeps using
alloy. Eliminates the branch where users could see two stacked error
messages and removes the silent-divergence risk between two parsers.
@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c906f98b-aa29-468e-8e0a-daa8eed61cf2

📥 Commits

Reviewing files that changed from the base of the PR and between 9a278ca and 2c0b863.

📒 Files selected for processing (2)
  • packages/cli/src/config_parsing/abi_compat.rs
  • packages/cli/src/config_parsing/system_config.rs

📝 Walkthrough

Walkthrough

This PR replaces the event signature parsing mechanism to support named tuple components. A new parse_event_signature_to_alloy function implements a custom grammar parser, integrated into parse_event and system_config event-signature handling, with regression tests for issue 1206 validating named nested tuples.

Changes

Event signature parsing with named tuple components

Layer / File(s) Summary
Custom event signature parser implementation
packages/cli/src/config_parsing/abi_compat.rs
parse_event_signature_to_alloy is a new public function implementing a custom sig_parser module that parses event signatures accepting optional event keyword, a name, parenthesized parameters (type, optional indexed, optional name), optional anonymous keyword, and array/tuple suffixes with named components.
Integration into parse_event and abi_compat tests
packages/cli/src/config_parsing/abi_compat.rs
parse_event now delegates signature parsing to parse_event_signature_to_alloy and converts the result to the public Event type. Regression tests validate named nested tuple parsing with field names/types preserved, and mixed named tuple arrays with indexed scalar parameters.
System config integration and regression test
packages/cli/src/config_parsing/system_config.rs
Event::get_abi_event switches from AlloyEvent::parse to parse_event_signature_to_alloy. Regression test confirms named tuple component event signatures parse correctly, with selector equivalence between named and canonical forms and component names preserved in the EventParam tree.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • enviodev/hyperindex#963: Both PRs modify event-signature parsing in get_abi_event, with #963 adding a normalization step before parsing and this PR routing parsing through parse_event_signature_to_alloy instead of AlloyEvent::parse.

Suggested reviewers

  • moose-code
  • JonoPrest
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Support named tuple components in event signatures' directly and clearly describes the main change: enabling support for named tuple components in event signatures, which is the core feature addition in this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@DZakh DZakh enabled auto-merge (squash) May 15, 2026 15:10
@DZakh DZakh merged commit c1ef7df into main May 15, 2026
8 checks passed
@DZakh DZakh deleted the claude/test-issue-1206-3kitR branch May 15, 2026 15:18
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