Skip to content

feat(ts): translate == of hash maps and sets as std's - #543

Merged
kixelated merged 4 commits into
mainfrom
quest/m3/ts-hash-map-eq
Nov 3, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m3/ts-hash-map-eq

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

== and != of two HashMaps or two HashSets, std's or hashbrown's, were refused as an unsupported call, for a RandomState map too, and so was a derived PartialEq of a type that holds one. Completes quest/m3/ts-hash-map-eq.md. No consumer yet; planned because rust2 aims to support all of std.

Approach

  • rt.hashEq(eq?) does what std's and hashbrown's PartialEq do: equal lengths, then each entry of self looked up in other, and self's value == the one found. A set passes no value eq.
  • eq_fn maps a HashMap or HashSet to it, so maps inside a Vec, an Option, or a derived PartialEq compare too.
  • A lookup now calls eq of the key looked up by, given the held key, as hashbrown's Equivalent does (self == key.borrow()). The runtime called the held key's eq instead, which a logging Eq showed for every lookup, not only map equality.
  • Hashing stays around the crate's own BuildHasher, as feat(ts): hold a crate's own BuildHasher in a hash map or set #509 decided: the runtime never calls it, so maps whose hashers differ (seeded apart on each side) compare by their keys alone, as std's do.

Tests, differential against native Rust:

  • lang/hashes hashes::equal: std maps and sets with a crate BuildHasher seeded apart on each side, of a key and value that log each Hash and eq with the side they are on. Each compares both ways, against the same bytes in another order, all but the last, and one byte flipped. The crate hasher puts the key in hashbrown's tag bits so native calls eq only on the matching key; logs are written in call order for maps of at most one entry, sorted for equal maps, and dropped otherwise, as std's order decides which entries it visits before one differs. Then RandomState maps of primitive and string keys, maps in a Vec, and a derived PartialEq holding a map and a set.
  • stock maps::equal: hashbrown's maps and sets with a crate BuildHasher seeded apart on each side, and the default hasher.
  • Reverting the lookup's eq order fails hashes::equal.

Impact

  • rt.hashEq is new in the runtime; the translator's output for ==/!= of hash maps and sets.
  • A lookup in a translated hash map calls the looked-up key's eq rather than the held key's, matching std. No API change.

Alternatives

Follow-ups

Review

Codex (quest review), gpt-6.1-sol, medium effort, round 1 on 8a32ee10d551546d8a5e330a4911e7c7719336f6: no findings. c4de918b992ed29e5b45f3f4a1705c58dc9a4fca adds only conflict-free merges of origin/main on top, after which just ci passed.

🤖 Generated with Claude Code

kixelated and others added 2 commits November 3, 2026 10:59
Quest-Claim: 6d48ccdf3947cf4f
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Equality of hash maps and sets feat(ts): translate == of hash maps and sets as std's Nov 3, 2026
kixelated and others added 2 commits November 3, 2026 11:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 19:25
@pullfrog

pullfrog Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

This run was cancelled before it finished.

Pullfrog  | View workflow run | via Pullfrog

@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: 86b1832a-7f05-4675-b1ea-d0ecd0476d73
Commits

Reviewing files that changed from the base of the PR and between 7e7e420 and c4de918.

Files selected for processing: 16
  • quest/m3/README.md
  • quest/m3/ts-hash-map-eq.md
  • ts/README.md
  • ts/fixtures/lang/hashes/expected/hashes.Index.ts
  • ts/fixtures/lang/hashes/expected/hashes.Sided.ts
  • ts/fixtures/lang/hashes/expected/hashes.Spread.ts
  • ts/fixtures/lang/hashes/expected/hashes.ts
  • ts/fixtures/lang/hashes/expected/lib.ts
  • ts/fixtures/lang/hashes/src/hashes.rs
  • ts/fixtures/lang/hashes/src/lib.rs
  • ts/fixtures/stock/expected/harness.ts
  • ts/fixtures/stock/expected/maps.ts
  • ts/fixtures/stock/src/harness.rs
  • ts/fixtures/stock/src/maps.rs
  • ts/runtime/rt/collections.ts
  • ts/src/lower/collections.rs
  • 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.

Merged via the queue into main with commit f6d1412 Nov 3, 2026
7 of 8 checks passed
@kixelated
kixelated deleted the quest/m3/ts-hash-map-eq branch November 3, 2026 19:37
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