Fix global constant patterns in match/matches expressions#754
Merged
Conversation
…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
Working tree is dirtyIntegrity checks produced the following changes: Please run |
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
i32::MAX) can now be used asmatch/matchespatterns via a newTirPattern::ConstantValuevariant, lowered to binding + guard comparisonsmatches/matchpatterns were added tolocal_names_in_functionand 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 exitslexer_gen.wadoandparser_gen.wadonow emitmatches { A | B | C }for multi-token checks instead of== A || == B || == Cchains, reducingpeek_kind()calls from N to 1Test plan
match_global_constant_pattern.wadocovering: basic match, matches operator, or-patterns, arm body usage, post-match usage, while-condition + loop body, associated constantsmatches_scope_error.wadostill catches leaked pattern bindings (Some(x)scope escape)on-task-donecleanhttps://claude.ai/code/session_01VFJ65MdiFYUAuLRFzqSUhb