Skip to content

Emit virtual call for comparison operators - #4313

Merged
2kai2kai2 merged 1 commit into
canaryfrom
kai/lower-user-ordering
Jul 31, 2026
Merged

Emit virtual call for comparison operators#4313
2kai2kai2 merged 1 commit into
canaryfrom
kai/lower-user-ordering

Conversation

@2kai2kai2

@2kai2kai2 2kai2kai2 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Ordering operators (<, <=, >, >=) now support custom comparison behavior for user-defined types, enums, booleans, generics, and interface implementations.
    • Custom operator overrides and default comparison methods are honored consistently.
  • Bug Fixes

    • Improved comparison behavior in conditions, short-circuit expressions, assignments, and error-handling scenarios.
    • Added validation for unsupported comparison type combinations and incomplete comparison implementations.
  • Tests

    • Expanded coverage for generic dispatch, runtime behavior, reflexivity, and comparison consistency.

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview Jul 31, 2026 8:30pm
promptfiddle2 Ready Ready Preview Jul 31, 2026 8:30pm

Request Review

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@vercel
vercel Bot temporarily deployed to Preview – beps July 31, 2026 19:50 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 31, 2026 19:57 Inactive
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 61f35d48-1a61-41fe-98a7-00622f3a077d

📥 Commits

Reviewing files that changed from the base of the PR and between 5269ffb and 607ec85.

⛔ Files ignored due to path filters (1)
  • baml_language/crates/baml_tests/snapshots/baml_src/operators.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_tests/baml_src/ns_operators/operators.baml
  • baml_language/crates/baml_tests/tests/interfaces.rs
  • baml_language/crates/bex_vm/tests/comparison_driver.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • baml_language/crates/baml_tests/baml_src/ns_operators/operators.baml
  • baml_language/crates/bex_vm/tests/comparison_driver.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_tests/tests/interfaces.rs

📝 Walkthrough

Walkthrough

Ordering operators preserve primitive opcode lowering and dispatch non-primitive operands through baml.ops.Compare. Compiler, language, TIR, and VM tests cover defaults, overrides, generics, control flow, destinations, and runtime errors.

Changes

Ordering Compare dispatch

Layer / File(s) Summary
Compiler ordering lowering
baml_language/crates/baml_compiler2_mir/src/lower.rs
Primitive comparisons retain specialized opcodes. Other supported operands call the mapped baml.ops.Compare method through virtual dispatch.
Language and TIR coverage
baml_language/crates/baml_tests/baml_src/ns_operators/operators.baml, baml_language/crates/baml_tests/tests/interfaces.rs
Tests cover Compare implementations, defaults, overrides, generics, Self, control flow, non-local destinations, panic propagation, and type restrictions.
VM comparison coverage
baml_language/crates/bex_vm/tests/comparison_driver.rs
VM tests cover booleans, classes, enums, bounded generics, default methods, reflexivity, and direct overrides.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CompilerLowering
  participant PrimitiveOpcode
  participant CompareVirtualCall
  participant BamlOpsCompare
  CompilerLowering->>PrimitiveOpcode: lower primitive-compatible operands
  CompilerLowering->>CompareVirtualCall: lower non-primitive ordering
  CompareVirtualCall->>BamlOpsCompare: invoke lt, le, gt, or ge
Loading

Possibly related PRs

Poem

I hop through Compare, quick and bright,
Primitive paths retain their flight.
Classes and generics now compare,
Defaults and overrides travel there.
Tests guard each operator with care.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding virtual-call dispatch for comparison operators.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kai/lower-user-ordering

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
baml_language/crates/baml_compiler2_mir/src/lower.rs (1)

6303-6310: 📐 Maintainability & Code Quality | 🔵 Trivial

Track the documented != limitation.

The comment records a real behavior gap: an Equals.neq override is ignored by the != operator. The comment has no issue reference, so the gap can be lost.

Do you want me to open a tracking issue that captures this analysis?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_compiler2_mir/src/lower.rs` around lines 6303 -
6310, Open a tracking issue for the documented limitation in the != lowering
near the Equals.neq handling, recording that operator dispatch ignores neq
overrides for inconsistent eq/neq implementations and that cross-type semantics
require a design decision. Link or reference the tracking issue in the existing
BUG comment so the limitation remains discoverable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/crates/baml_tests/baml_src/ns_operators/operators.baml`:
- Around line 696-707: Update ord_into_capture so the lambda assigns a
comparison result that evaluates to true, allowing the final assertion to verify
that set() wrote to out rather than merely observing its initial false value.

---

Nitpick comments:
In `@baml_language/crates/baml_compiler2_mir/src/lower.rs`:
- Around line 6303-6310: Open a tracking issue for the documented limitation in
the != lowering near the Equals.neq handling, recording that operator dispatch
ignores neq overrides for inconsistent eq/neq implementations and that
cross-type semantics require a design decision. Link or reference the tracking
issue in the existing BUG comment so the limitation remains discoverable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33dd5fa9-457b-47a3-8911-9db57985c4a3

📥 Commits

Reviewing files that changed from the base of the PR and between 098a8ce and 5269ffb.

⛔ Files ignored due to path filters (1)
  • baml_language/crates/baml_tests/snapshots/baml_src/operators.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_tests/baml_src/ns_operators/operators.baml
  • baml_language/crates/baml_tests/tests/interfaces.rs
  • baml_language/crates/bex_vm/tests/comparison_driver.rs

Comment thread baml_language/crates/baml_tests/baml_src/ns_operators/operators.baml Outdated
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 27.4 MB 11.6 MB file 27.4 MB -10.6 KB (-0.0%) OK
packed-program Linux 🔒 17.7 MB 7.3 MB file 17.7 MB +23.1 KB (+0.1%) OK
baml-cli macOS 🔒 21.3 MB 10.2 MB file 21.3 MB -35.0 KB (-0.2%) OK
packed-program macOS 🔒 13.8 MB 6.4 MB file 13.8 MB -4.6 KB (-0.0%) OK
baml-cli Windows 🔒 22.9 MB 10.4 MB file 23.0 MB -53.9 KB (-0.2%) OK
packed-program Windows 🔒 14.8 MB 6.5 MB file 14.8 MB -14.3 KB (-0.1%) OK
bridge_wasm WASM 16.8 MB 🔒 4.6 MB gzip 4.6 MB -41.3 KB (-0.9%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@2kai2kai2
2kai2kai2 force-pushed the kai/lower-user-ordering branch from 5269ffb to 607ec85 Compare July 31, 2026 20:21
@vercel
vercel Bot temporarily deployed to Preview – beps July 31, 2026 20:22 Inactive
@2kai2kai2
2kai2kai2 enabled auto-merge July 31, 2026 20:28
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 31, 2026 20:30 Inactive
@2kai2kai2
2kai2kai2 added this pull request to the merge queue Jul 31, 2026
Merged via the queue into canary with commit 6aeeab0 Jul 31, 2026
82 checks passed
@2kai2kai2
2kai2kai2 deleted the kai/lower-user-ordering branch July 31, 2026 20:42
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