Skip to content

[dslx] Warn on non-const outer bindings in match patterns - #5526

Open
cdleary wants to merge 1 commit into
google:mainfrom
xlsynth:cdleary/2026-11-21-warn-non-const-match-pattern
Open

cdleary wants to merge 1 commit into
google:mainfrom
xlsynth:cdleary/2026-11-21-warn-non-const-match-pattern

Conversation

@cdleary

@cdleary cdleary commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

This PR introduces a default-on DSLX warning to prepare for the migration to Rust-style match bindings discussed in #1909. The warning, non_const_match_pattern, flags a bare pattern name that compares the matched value against a non-const outer binding.

For example, if y is a parameter, the first arm of match x { y => y, _ => false } currently tests whether x == y. Under the proposed rules, that arm would match every value of x and bind it to a new y. The diagnostic points to the outer declaration so the author can write an explicit equality test or choose a fresh pattern name.

Declared constants and value parametrics match by value. In apfloat::normalize, the comparison value depends only on parametrics, so this PR declares it as a const to make that intent explicit.

The typechecker checks match patterns before lambda rewriting can turn a captured let into a parametric binding.

All 2,232 selected targets in the optimized //xls/... sweep passed, including tests for which bindings warn, default warnings-as-errors, and selective suppression.

@cdleary
cdleary force-pushed the cdleary/2026-11-21-warn-non-const-match-pattern branch 2 times, most recently from 140e00f to 6e9876f Compare November 22, 2026 03:48
@cdleary
cdleary marked this pull request as ready for review November 22, 2026 03:48
@cdleary
cdleary force-pushed the cdleary/2026-11-21-warn-non-const-match-pattern branch from 6e9876f to 6b15f00 Compare November 22, 2026 20:57
Flag value comparisons against outer variables before the planned migration to pattern shadowing in google#1909. Keep matching by equality, and use a declared constant for the affected apfloat pattern.
@cdleary
cdleary force-pushed the cdleary/2026-11-21-warn-non-const-match-pattern branch from 6b15f00 to fbae11b Compare November 22, 2026 20:59
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 23, 2026
… patterns

Flag value comparisons against outer variables before the planned migration to pattern shadowing in google#1909. Keep matching by equality, and use a declared constant for the affected apfloat pattern.

Upstream-head: fbae11b

This branch has not been deployed

No deployments
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