Skip to content

feat(ts): translate std::ops operator methods on primitives called by path - #489

Merged
moq-bot[bot] merged 6 commits into
mainfrom
quest/m3/ts-operator-paths
Nov 3, 2026
Merged

moq-bot[bot] merged 6 commits into
mainfrom
quest/m3/ts-operator-paths

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

On a primitive, rustc lowers an operator to a MIR operation, but a std::ops method called by its path, such as <u8 as AddAssign>::add_assign(&mut n, 1), stays a call to the trait method. The binary operators already mapped there, but every *Assign method, Neg::neg, and Not::not of an integer, a float, or a bool was an "unsupported call", written or as a function value.

Approach

Reuse the operators' own lowering, so each call means what its operator does:

  • call.rs: the *Assign mapping that wrote a Wrapping's or a Saturating's result through the &mut also takes a primitive, computing the result with num::binary, as += does. A right side by reference (AddAssign<&u8>) and a shift amount of another type come along.
  • library.rs: Neg and Not of a primitive, or a reference to one, lower with num::unary, as -x and !x do.

A function value of one translates as its call already (#470), so passing it to a generic body or coercing it to a fn pointer needs nothing more.

New fixture lang/operators, differential against native wasm32: every operator trait's method, its *Assign form, and its by-reference impls, on every integer width, f64, f32, and bool, each written as a call, passed as a function value, and through a fn pointer. The caller sweeps each width's edges (MIN / -1, division by zero, shifts at, past, and far past the width, negative i16 amounts, 128-bit values past 2^64) and floats' signed zeros, subnormals, infinities, and NaN: 39177 cases, 8298 of them panics. A mutation mapping DivAssign to % fails 1980 of them.

Consumer: crates that pass an operator method as a value or call it generically, as num-traits-style code and folds such as fold(0, Add::add) do; moq reaches them through its dependencies.

Impact

  • The translator's output: these calls translate instead of being refused. No public Rust API change.

Alternatives

  • Lowering std's primitive impls from their MIR, as the quest suggested measuring: their bodies are the operator, but each *Assign takes &mut self, which from_mir refuses for std, and each call would emit a function per impl and instance. The mapping reuses the exact lowering the operator form gets, in about 15 lines.

Follow-ups

None.

Review

mechanical fix by quest land watch: merged main at 7e7af66f6f58c6daebd363a2ec969cac1349ad5e with the quest merge driver (head 0ff7cc7)

Codex gpt-6.1-sol, medium effort, via quest review, on head ceb9eed0477fa6e707b93a0f5ab30559338528e4: no findings. b6f0c0f9136ebcd2989f5fa4a3f2723693931465 adds only conflict-free merges of origin/main.

🤖 Generated with Claude Code

@kixelated kixelated changed the title Operator trait methods called by path feat(ts): translate std::ops operator methods on primitives called by path Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 05:36
@coderabbitai

coderabbitai Bot commented Nov 3, 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: 678c1e38-7d50-4898-af79-6e0978795124
  • 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@kixelated
kixelated enabled auto-merge November 3, 2026 06:00
@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 3, 2026
@moq-bot

moq-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

quest land watch: the merge queue removed this pull request at b6f0c0f because it conflicts with main (merge_conflict).

The land fixer works on it in the background, and the watcher re-enqueues it at the back of the queue once it is fixed or judged flaky, or hands it back here with what it needs.

(written by quest land watch)

@moq-bot
moq-bot Bot enabled auto-merge November 3, 2026 06:02
@moq-bot

moq-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

quest land watch: armed auto-merge on this pull request at 0ff7cc7, so it joins the back of the merge queue once its required checks pass, with main at 7e7af66 merged in by the quest merge driver.

(written by quest land watch)

@moq-bot
moq-bot Bot added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 1eb763b Nov 3, 2026
5 checks passed
@moq-bot
moq-bot Bot deleted the quest/m3/ts-operator-paths branch November 3, 2026 06:06
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.

1 participant