Skip to content

r2il: refuse out-of-range lane-compare constants in FoldDialect - #1980

Merged
AdaWorldAPI merged 3 commits into
mainfrom
ccr-8062bcc7-l7lkz9-g2
Nov 7, 2026
Merged

AdaWorldAPI merged 3 commits into
mainfrom
ccr-8062bcc7-l7lkz9-g2

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Problem

The raw FoldDialect (crates/lance-graph-r2il/src/lib.rs) clamped any lane-compare constant that did not fit the lane type, instead of refusing it. The clamp was i32::try_from(x).unwrap_or(i32::MAX) or the u32 equivalent. As a result:

  • a constant above the range compared as MAX;
  • a large negative constant also compared as MAX;
  • the compare silently answered a different question.

Change

The five compare sites now refuse through new const_u32 / const_i32 helpers:

  • IntEqual on a U32 lane;
  • IntEqual on an I32 lane;
  • IntEqual on a VIA key;
  • IntSLess, in both operand orders.

Each refusal is the new FoldError::ConstOutOfRange(FnIndex, i64). No existing variant fits: Overflow means scalar arithmetic left i64, and WrongOperandKind is about operand shape.

KEY_RUNS counted a selected NULL key. Its precondition (ordered keys, NULLs masked) is now documented on the KEY_RUNS arm, in the crate doc and on the polyfill lens. The behaviour does not change, because the validity channel already exists: procs::count_distinct_sorted ANDs the key's presence plane into the mask.

Non-test diff: about 40 lines (lib.rs, polyfill.rs). binding.rs and binding_native.rs are untouched, so there is no overlap with #1979.

Callers

None needed changes:

  • Every caller already passes a typed i32/u32: r2il procs, relalg lower.rs, the nal crate, math-polyfill, and r2il-mask-abi-probe.
  • The binding path already refuses out-of-range constants before they reach the dialect.
  • No FoldError match is exhaustive. egglog-r2il-probe and holo-h14d-probe use wildcard arms, which I verified by reading them.

No published result changes.

Tests

New tests in tests/dialect.rs:

  • in_range_compare_constants_behave_as_before: type-range boundaries, both operand orders.
  • out_of_range_compare_constants_are_refused: -1, i64::MIN, u32::MAX+1, i32::MAX+1, i32::MIN-1, i64::MAX.
  • via_compare_constants_are_range_checked.
  • key_runs_counts_a_selected_null_key_unless_the_mask_excludes_it: 3 without the presence mask, 2 with it.

Disable run. After the commit, I restored the clamp at all five sites (the patch applied 2+1+2 times as asserted). out_of_range_compare_constants_are_refused and via_compare_constants_are_range_checked went red; the other 11 tests in dialect.rs stayed green. I then restored the code with git checkout.

Validation

All runs used CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_INCREMENTAL=0.

  • cargo test on r2il: 88 passed, 0 failed (re-run independently).
  • cargo test passes on math-polyfill-probe, lance-graph-relalg, lance-graph-nal and r2il-mask-abi-probe.
  • cargo clippy --all-targets -D warnings is clean on r2il.
  • cargo fmt is applied.

Open


Generated by Claude Code

The raw FoldDialect narrowed a lane compare's constant with
`try_from(..).unwrap_or(MAX)` at five sites (IntEqual on U32, I32 and a
VIA key; IntSLess in both operand orders). A constant outside the lane's
type therefore compared against a different number: -1 against a U32
lane matched the row holding u32::MAX, and every out-of-range I32
constant, including a large negative one, became i32::MAX. The dialect
now refuses such a call as the new FoldError::ConstOutOfRange(opcode,
value); no existing variant names a constant that does not fit a lane.
The binding seam already refused these first, so its results do not
change.

KEY_RUNS takes no validity: a selected NULL row counts its payload as a
key. The precondition (key-ordered lane, NULL keys masked out) is now
documented on the arm, the crate doc and the polyfill lens, and pinned
by a test (3 unmasked, 2 with the presence plane ANDed in, as
procs::count_distinct_sorted does).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b077e77d-0b21-4c00-be25-3bf5bf186d5c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T22:08:32.285160Z a958271 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…-range constants

The seam's compare check stays; it reports the refusal as an ExecRefusal at
bind time. The dialect no longer saturates (FoldError::ConstOutOfRange), so
the 'would otherwise saturate' wording was stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
@AdaWorldAPI
AdaWorldAPI merged commit a546911 into main Nov 7, 2026
15 checks passed
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