Skip to content

chore: CmpError -> CompareError - #3763

Merged
sxlijin merged 2 commits into
canaryfrom
cursor/replace-cmperror-with-compareerror-1d12
Jun 12, 2026
Merged

chore: CmpError -> CompareError#3763
sxlijin merged 2 commits into
canaryfrom
cursor/replace-cmperror-with-compareerror-1d12

Conversation

@sxlijin

@sxlijin sxlijin commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Changes

This PR systematically renames CmpError to CompareError throughout the Sortable/Comparable interface implementation.

Files Modified:

  • baml_std/baml/comparable.baml: Updated Comparable interface and all builtin implementations (int, bigint, string, float)
  • baml_std/baml/containers.baml: Updated sort_by_key error type projection
  • baml_compiler2_hir/src/builder.rs: Updated Rust comments referencing the type
  • baml_compiler2_tir/src/associated_projection.rs: Updated Rust comments
  • baml_tests/baml_src/: Updated test BAML files and documentation
  • baml_tests/tests/comparable_sort.rs: Updated all Rust test cases
  • snapshots/: Regenerated all affected snapshot tests with updated type names

The change maintains full API compatibility - it's purely a naming improvement for better clarity.

Testing

  • Unit tests added/updated
  • All 48 comparable_sort tests pass successfully
  • All snapshot tests regenerated and passing
  • Verified the renamed type works correctly in all contexts:
    • Interface definition and implementations
    • Generic type projections (T.CompareError)
    • Error propagation in sort operations
    • Fallible and infallible comparators
    • HIR and TIR compiler stages

PR Checklist

  • I have read and followed the contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Slack Thread

Open in Web Open in Cursor 

Summary by CodeRabbit

  • Refactor
    • Renamed the error type in sorting operations from CmpError to CompareError. Code that implements custom comparison logic or handles comparison errors requires updates to use the renamed error type.

- Renamed CmpError to CompareError in Comparable interface
- Updated all implementations (int, bigint, string, float)
- Updated SortError type projection to use T.CompareError
- Updated all test cases and documentation
- Updated Rust comments referencing the type name

Co-authored-by: Sam Lijin <sam@boundaryml.com>
@vercel

vercel Bot commented Jun 12, 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, Comment Jun 12, 2026 10:28pm
promptfiddle Ready Ready Preview, Comment Jun 12, 2026 10:28pm
promptfiddle2 Ready Ready Preview, Comment Jun 12, 2026 10:28pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR renames the Comparable interface's associated error type from CmpError to CompareError throughout the BAML standard library, compiler, and test suite. The change propagates from the core interface definition through all primitive implementations, the Sortable trait, array container methods, and the entire test infrastructure.

Changes

Comparable Error Type Rename

Layer / File(s) Summary
Comparable interface and primitive implementations
baml_language/crates/baml_builtins2/baml_std/baml/comparable.baml
Comparable interface's associated error type renamed from CmpError to CompareError. All primitive type implementations (int, bigint, string, float) updated to define type CompareError = never.
Sortable blanket implementation and sort dispatch
baml_language/crates/baml_builtins2/baml_std/baml/comparable.baml
Sortable trait derives SortError from T.CompareError. Blanket implementation for T[] updates sort and sort_by method signatures to throw T.CompareError. Dispatch shim _compare_shim signature updated to throw T.CompareError.
Array container sort_by_key integration
baml_language/crates/baml_builtins2/baml_std/baml/containers.baml
Array<T>.sort_by_key method signature and implementation updated to propagate U.CompareError from key comparison; comparator callback throws annotation updated accordingly.
Test type definitions and helper functions
baml_language/crates/baml_tests/baml_src/ns_arrays/sort_comparable.baml, baml_language/crates/baml_tests/baml_src/ns_arrays/arrays.baml
Test types (ComparableScore, ComparableFlaky, SortableItem, OutOfBodyScore) updated to define type CompareError. Fallible error class renamed from ComparableCmpError to ComparableCompareError. Test helper functions (sort_flaky, sort_generic) updated to throw CompareError types. Documentation comments updated to reflect new naming.
Test error handling and catch patterns
baml_language/crates/baml_tests/baml_src/ns_arrays/sort_comparable.baml
Multiple test case catch patterns updated to match ComparableCompareError instead of previous error type name.
Comprehensive test suite validation
baml_language/crates/baml_tests/tests/comparable_sort.rs
Test suite updated across all phases: Phase 2 validates CompareError associated type requirement; Phase 3+ validates generic functions propagate T.CompareError through sort, sort_by, and sort_by_key workflows. Tests for primitive fast paths, element dispatch, error normalization, and regression cases all use updated naming.
Compiler documentation comments
baml_language/crates/baml_compiler2_hir/src/builder.rs, baml_language/crates/baml_compiler2_tir/src/associated_projection.rs
Comments documenting generic parameter projection rules and associated type resolution updated to use CompareError in illustrative examples.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • BoundaryML/baml#3732: Introduces the Comparable trait and Sortable blanket implementation for generic array sorting that this PR renames error types for.
  • BoundaryML/baml#3718: Introduces the Array<T>.sort_by_key method whose error type signatures are directly updated in this PR.

Poem

🐰 The compare error was quite a bore,
CmpError, they cried, "Rename it, no more!"
So CompareError it became so bright,
Through comparable and sortable, all set right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary change: a systematic rename of the CmpError type to CompareError throughout the codebase, which is the sole focus of this PR.
Docstring Coverage ✅ Passed Docstring coverage is 91.30% which is sufficient. The required threshold is 80.00%.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 cursor/replace-cmperror-with-compareerror-1d12

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 and usage tips.

@github-actions

github-actions Bot commented Jun 12, 2026

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.

@sxlijin sxlijin changed the title Replace CmpError with CompareError in Sortable/Comparable interfaces chore: CmpError -> CompareError Jun 12, 2026
@sxlijin
sxlijin marked this pull request as ready for review June 12, 2026 21:24
@sxlijin
sxlijin enabled auto-merge June 12, 2026 21:24

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47b8c7994d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// it undefaulted keeps the `Comparable` bound permissive over `CompareError`.
interface Comparable {
type CmpError
type CompareError

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Regenerate snapshots after the associated-type rename

This rename changes the rendered stdlib HIR/TIR and the baml_src bytecode, but the checked-in insta snapshots were not updated: snapshots/compiles/__baml_std__/...03_hir.snap and ...04_tir.snap still contain T.CmpError, and snapshots/baml_src/arrays.snap still contains ComparableCmpError. The snapshot tests, including baml_tests/tests/baml_src.rs::bytecode, compare against those files, so CI will fail until the snapshots are regenerated alongside the rename.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown

No description provided.

- Updated HIR snapshot with CompareError type projections
- Updated TIR snapshot with CompareError references
- Updated arrays snapshot with ComparableCompareError class name
- All 48 comparable_sort tests pass

Co-authored-by: Sam Lijin <sam@boundaryml.com>
@sxlijin
sxlijin added this pull request to the merge queue Jun 12, 2026
Merged via the queue into canary with commit 1eb3e9a Jun 12, 2026
52 checks passed
@sxlijin
sxlijin deleted the cursor/replace-cmperror-with-compareerror-1d12 branch June 12, 2026 22:29
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