8000 [dslx][ir] Reject equality of incomparable types by cdleary · Pull Request #5468 · google/xls · GitHub
[go: up one dir, main page]

Skip to content

[dslx][ir] Reject equality of incomparable types - #5468

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
xlsynth:cdleary/2026-11-18-reject-incomparable-equality
Nov 24, 2026
Merged

copybara-service[bot] merged 1 commit into
google:mainfrom
xlsynth:cdleary/2026-11-18-reject-incomparable-equality

Conversation

@cdleary
@cdleary cdleary commented Nov 19, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

The IR verifier checked only the outer operand type, so it accepted this comparison between tuples containing tokens.

const A = token();
const B = token();

pub fn main(x: bool) -> bool {
    (A,) == (if x { A } else { B },)
}

The DSLX interpreter compares token identity and returns x. IR conversion emits payload-free tokens and loses the distinction between A and B. The IR interpreter therefore returns true for x = false, and the optimizer silently folds the function to a constant true. The JIT rejects the unoptimized comparison.

Require comparable operand types for DSLX ==, !=, assert_eq, and assert_ne. Arrays, tuples, and ordinary structs support equality recursively when their element or member types do. The IR verifier now rejects eq and ne operands that contain a token at any depth. Regression tests cover the reproducer, comparable aggregates, and the IR verifier.

Testing

All 2,226 selected targets passed in the optimized //xls/... OSS sweep. The sweep skips tests that build OpenROAD, Yosys, or Clang.

@cdleary
cdleary force-pushed the cdleary/2026-11-18-reject-incomparable-equality branch from 3b71ae5 to 96637a4 Compare November 19, 2026 04:15
@cdleary
cdleary marked this pull request as ready for review November 19, 2026 04:15
@ericastor ericastor left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good fix - thank you.

cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 23, 2026
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
@copybara-service
copybara-service Bot merged commit d584f1a into google:main Nov 24, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0