Skip to content

Fix global constant patterns in match/matches expressions#754

Merged
gfx merged 6 commits intomainfrom
claude/fix-global-constant-pattern-wabQe
Apr 2, 2026
Merged

Fix global constant patterns in match/matches expressions#754
gfx merged 6 commits intomainfrom
claude/fix-global-constant-pattern-wabQe

Conversation

@gfx
Copy link
Copy Markdown
Member

@gfx gfx commented Apr 2, 2026

Summary

  • Add global constant pattern support: Immutable globals and associated constants (e.g., i32::MAX) can now be used as match/matches patterns via a new TirPattern::ConstantValue variant, lowered to binding + guard comparisons
  • Fix binder scoping bug: Bare idents in matches/match patterns were added to local_names_in_function and persisted after scope exit, shadowing real globals when used as expressions later. Fixed by removing top-level bare idents from the tracking set after pattern scope exits
  • Optimize gale-generated parsers: lexer_gen.wado and parser_gen.wado now emit matches { A | B | C } for multi-token checks instead of == A || == B || == C chains, reducing peek_kind() calls from N to 1

Test plan

  • 8 e2e test cases in match_global_constant_pattern.wado covering: basic match, matches operator, or-patterns, arm body usage, post-match usage, while-condition + loop body, associated constants
  • Existing matches_scope_error.wado still catches leaked pattern bindings (Some(x) scope escape)
  • All 4 golden files (json, calculator, sexpression, sqlite) regenerated and compile successfully
  • Full e2e suite (4495 tests) and Wado test suite (1278 tests) pass
  • on-task-done clean

https://claude.ai/code/session_01VFJ65MdiFYUAuLRFzqSUhb

claude added 5 commits April 2, 2026 07:34
…terns

Immutable global variables and associated constants (e.g., i32::MAX) can
now be used in match/matches patterns. Global constants generate runtime
equality comparisons via ConstantValue patterns. Associated constants
that resolve to literals are lowered directly to Literal patterns,
enabling br_table switch optimization.

https://claude.ai/code/session_01VFJ65MdiFYUAuLRFzqSUhb
…nerated code

- is_skip: `false || best_kind == TK_A || ...` → `best_kind matches { TK_A | ... }`
- token_kind_name: sequential if-chains → match expression with global constant arms

https://claude.ai/code/session_01VFJ65MdiFYUAuLRFzqSUhb
The binder was adding bare ident names from matches/match patterns to
local_names_in_function, which caused global constants used in matches
patterns to be treated as out-of-scope locals when referenced later as
expressions. Fix by removing top-level bare idents from the tracking set
after the pattern scope exits, since they may be global constant refs.

Also update gale parser_gen to use matches operator with or-patterns for
multi-token peek_kind checks, reducing method calls in generated parsers.

https://claude.ai/code/session_01VFJ65MdiFYUAuLRFzqSUhb
@gfx gfx enabled auto-merge April 2, 2026 08:55
@gfx gfx disabled auto-merge April 2, 2026 08:56
@gfx gfx enabled auto-merge April 2, 2026 08:56
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Working tree is dirty

Integrity checks produced the following changes:

 .../match_global_constant_pattern.wir.wado         | 397 +++++++++++++++++++--
 1 file changed, 371 insertions(+), 26 deletions(-)

Please run mise run on-task-done locally and commit the changes.

@gfx gfx disabled auto-merge April 2, 2026 09:05
@gfx gfx merged commit 41af89f into main Apr 2, 2026
10 checks passed
@gfx gfx deleted the claude/fix-global-constant-pattern-wabQe branch April 2, 2026 09: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