Skip to content

feat(ts): translate BuildHasherDefault as a value that holds nothing - #544

Merged
kixelated merged 7 commits into
mainfrom
quest/m3/ts-build-hasher-default
Nov 3, 2026
Merged

kixelated merged 7 commits into
mainfrom
quest/m3/ts-build-hasher-default

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts refused BuildHasherDefault<H>, std's BuildHasher of a Default Hasher, which is how rustc-hash's FxHashMap and nohash-hasher's IntMap build theirs: "unsupported type std::hash::BuildHasherDefault from another crate". Quest: quest/m3/ts-build-hasher-default.md (all of std; no moq consumer yet).

Approach

  • BuildHasherDefault holds only a PhantomData, so it joins library::nothing: its value is undefined, made by new, Default, Clone, a constant, or an aggregate, every value ==, and its Debug writes BuildHasherDefault, as std's debug_struct(..).finish() does.
  • build_hasher is H::default(). hash_one builds that, hashes, finishes, and drops the hasher then the value: through the crate's own H as feat(ts): hold a crate's own BuildHasher in a hash map or set #509's own_hash_one does, or std's DefaultHasher as RandomState's does.
  • A map or set holding one already hashes keys around it (the hash-around decision of feat(ts): hold a crate's own BuildHasher in a hash map or set #509); hasher lends undefined, which hashes through H as above.
  • Root-cause fix found by the tests: an aggregate spilled a shared reference to a value that holds nothing into a const part that nothing read once Debug ignored it, which tsc refuses (also for PhantomData, e.g. format!("{:?}", &pair.1)). Such a reference is now undefined in place. A &mut is left alone, as it may be an rt.Place.

Tests, differential against native Rust:

  • lang/hashes hashes::defaults: a logging Hasher (Tally) behind BuildHasherDefault: new, Default, Clone, a const, ==/!=, Debug ({:?}, {:#?}, inside Option), a struct deriving Default/Clone/Debug/PartialEq over it, build_hasher, and hash_one of several key kinds, logging each Default, write, finish, and drop. Then std HashMap/HashSet over BuildHasherDefault<Fnv>: default, with_capacity_and_hasher, entry API, lookups, hasher().hash_one, clone, collect, |, is_subset.
  • stock maps::default_hasher: hashbrown maps over BuildHasherDefault<DefaultHasher>, whose hasher().hash_one must match DefaultHasher::new byte for byte, and their ==.
  • Both cases also check == of a map over BuildHasherDefault against its clone, now that feat(ts): translate == of hash maps and sets as std's #543 has landed.
  • Snapshot churn in lang/cells, lang/results, lang/shapes: a shared &() or &.. part now reads as undefined in place (for example f(self) becomes f(undefined)).

Impact

  • Translator output only: BuildHasherDefault<H> translates as undefined. No public API change.

Alternatives

  • Lower std's own impls from MIR: std items are not translated, and every other std type is mapped by library, so this follows RandomState and PhantomData.
  • held_state returning None for a nothing state: changes how maps pick their key hasher; keeping it held needs no special case.

Follow-ups

  • None.

Review

🤖 Generated with Claude Code

@kixelated kixelated changed the title A map built with BuildHasherDefault feat(ts): translate BuildHasherDefault as a value that holds nothing Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 19:56
@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 54 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: fe96868b-88ba-4e2b-923d-a192a374609c
Commits

Reviewing files that changed from the base of the PR and between aff50d0 and eca1139.

Files selected for processing: 26
  • quest/m3/README.md
  • quest/m3/ts-build-hasher-default.md
  • ts/README.md
  • ts/fixtures/lang/cells/expected/cells.ts
  • ts/fixtures/lang/cells/expected/core/result.ts
  • ts/fixtures/lang/hashes/expected/hashes.Fnv.ts
  • ts/fixtures/lang/hashes/expected/hashes.Key.ts
  • ts/fixtures/lang/hashes/expected/hashes.Tallied.ts
  • ts/fixtures/lang/hashes/expected/hashes.Tally.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/lang/results/expected/core/option.ts
  • ts/fixtures/lang/results/expected/results.ts
  • ts/fixtures/lang/shapes/expected/fmt.ts
  • 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/src/lower/collections.rs
  • ts/src/lower/consts.rs
  • ts/src/lower/fmt.rs
  • ts/src/lower/library.rs
  • ts/src/lower/mir/rvalue.rs
  • ts/src/lower/mod.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 d7e0512 Nov 3, 2026
7 of 8 checks passed
@kixelated
kixelated deleted the quest/m3/ts-build-hasher-default branch November 3, 2026 20:02
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