Skip to content

D196 (#2372): HashMap[K, V, Minted] — an unseeded hasher for IDs the program minted; generic arity is checked - #3069

Merged
ehartford merged 3 commits into
mainfrom
d196-minted-hasher
Nov 7, 2026
Merged

ehartford merged 3 commits into
mainfrom
d196-minted-hasher

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

D196 (Eric, 2026-11-08, #2372): the per-process seed stays the default hasher for every key type (D96); a map or set whose keys are integer IDs the program minted names the unseeded hasher where it is declared, as a type: HashMap[K, V, Minted], HashSet[T, Minted]. A multiply-mix, never identity; refused over a non-integer key; never chosen by key type. Iteration order is insertion order either way, so nothing about output or the fixpoint changes. Spec §11.7, changelog v7.41, decision log entry.

Runtime (rt/rt_core.w): the map's str flag becomes a key kind (HM_KEY_BYTES/STR/FNS/MINTED); kind 3 hashes with hm_hash_minted — k *% 0x9E3779B97F4A7C15, high half folded down, so the low bits the table indexes by get the mix (sequential IDs would cluster under identity; a bare product leaves the low bits as they were).

Std: std.collections.Minted, an empty marker type with the rule in its doc.

Sema. validate_generic_arity (new): a declared generic type refuses a wrong argument count. HashMap[i32, i32, i32] had been accepted and miscompiled (get found nothing) because nothing checked arity for struct generics; the hasher slot is the one extension (HashMap's third, HashSet's second argument, Minted only, integer key only). setup_generic_inst_substitution binds impl[K, V] HashMap[K, V] to the three-argument instance; the map-literal target and two MirLower collect targets accept "at least two". Name[A, B, C] in expression position parses as a multi-index; when its base names a type and every spec is a scalar, it is the type (multi_index_names_type, both type-level resolvers, check_multi_index, the static-receiver paths), so HashMap[i32, V, Minted].new() works as HashMap[K, V].new() does.

Backends: both pass kind 3 at every map creation when the destination type names Minted (map_type_is_minted / map_tid_is_minted).

Fixtures: behav_d196_minted_hasher.w (insert/get/remove/order/set/literal/constructor form), err_d196_minted_over_str_key.w, err_d196_hasher_names_other_type.w, err_generic_arity_list.w.

Tool: tools/sweep_minted_maps.w adds , Minted to every HashMap[i32|i64, …] / HashSet[i32|i64] in a file (Lexer, bracket-matched) and the import. The src/ sweep is not in this PR: src/ is compiled by the pinned seed against the seed's std, which knows no Minted; it lands after the next seed. Before it does, every map's key provenance is reviewed (a map keyed by a parsed or received integer stays seeded).

Measurement (a stage2 built from a swept scratch copy of src/ against the unswept one, both checking the same src/main.w, one run each, same machine):

compiler check src/main.w max RSS
unswept 123.8 s 773 MB
swept (790 maps Minted) 98.7 s 773 MB

A fifth of the check, against the third the profile attributed to SipHash: the rest of that third is probe count and the hasher calls the swept maps still make through hm_find_slot, which is the next thing to measure per the ruling.

Eric Hartford added 3 commits November 7, 2026 09:37
…er where it is declared

`HashMap[K, V, Minted]` / `HashSet[T, Minted]` (std.collections.Minted): the
runtime's key kind 3 hashes an integer ID with a folded multiply-mix,
unseeded, because nothing outside the process chose it; the seed stays the
default for every key type (D96). Sema's new validate_generic_arity refuses
a wrong argument count for any declared generic (`HashMap[i32, i32, i32]`
was accepted and miscompiled) and admits the hasher slot for an integer
key only; a three-argument `Name[A, B, C]` in expression position is the
type when its base names one. Both backends pass the kind at map creation.
§11.7, changelog v7.41, decision log. tools/sweep_minted_maps.w adds the
argument to a file's integer-keyed maps; the src/ sweep waits for a seed
that knows Minted. Measured: a stage2 built from a swept src checks
src/main.w in 98.7 s against 123.8 s unswept.
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