SharedHole: let lowering state that two type positions are the same - #72
Merged
Conversation
Contributor
Author
dpmills
marked this pull request as draft
August 10, 2026 20:57
This was referenced Aug 10, 2026
dpmills
force-pushed
the
dmills/shared-hole
branch
from
August 10, 2026 21:41
faad609 to
0627ead
Compare
dpmills
marked this pull request as ready for review
August 10, 2026 21:50
This was referenced Aug 11, 2026
sortalongo
approved these changes
Aug 11, 2026
dpmills
force-pushed
the
dmills/shared-hole
branch
from
August 11, 2026 23:36
e5f32d2 to
ab58b46
Compare
A `groupby`'s key type *is* its key function's codomain, and the lowered shape relates them nowhere: `__gb_k`'s only occurrence is as an operand of the partition predicate's `==`, so the key's type could only arrive backwards through that comparison — making group-by key inference depend on an operator's internals. `Type::SharedHole(id)` lets lowering state the relation outright: a `Hole` with an identity, every occurrence of one id normalizing to the same inference variable. It is transient exactly as `Hole` is, and groups with it everywhere outside `normalize_annotation`. `groupby` stamps one id on the key application and on its own `data_fun` annotation's domain — the positions the claim is about, not the binder this desugaring invented. That also makes the edge directional for free: `bind_annotation` records `inferred <: ann` and a function is contravariant in its domain, so keys flow *into* the domain rather than being forced equal to it. `symbolic` does not render annotations, so `test_lower_groupby` cannot show the relation; `test_groupby_key_type_comes_from_the_key_function` pins it.
Sharing is what the marker is for, so over-sharing is its characteristic failure, and it has two shapes. A `def` is lowered once, so its body carries one id however many times it is called — nothing about the marker keeps the instantiations apart, ordinary generalization does, and only because `normalize_annotation` resolves the id to a variable minted at the current level (the level caveat on `InferCtx::shared_holes` is exactly this). Separately, the id → variable memo lives on the inference context, so every group-by in a program shares one table and ids minted per construct have to stay distinct within a lowering. `test_groupby_key_relation_is_per_occurrence` covers both: a polymorphic `def` wrapping `groupby`, called at an `Int` key and a `String` key, and two independent `groupby`s in one program. Either kind of over-sharing collapses the two key types into one variable, so neither shows up as a wrong key type — both reject the program with an `Int | String` collision. Confirmed by mutation: minting the shared variable at level 0 fails the `def` case, and returning a constant id from `fresh_shared_hole` fails the two-occurrence case. `test_groupby_lookup_at_wrong_key_type_rejected` covers the other half. The tests above pin what a key type *resolves to*; stating the relation on the `data_fun` annotation also makes the edge directional (`key_ty <: ⟨domain⟩`, by contravariance), and a directional edge can go slack without any resolution test noticing — every other case here would still pass if a lookup at an unrelated key type were quietly accepted.
dpmills
force-pushed
the
dmills/shared-hole
branch
from
August 12, 2026 00:09
ab58b46 to
17c31a1
Compare
This was referenced Aug 13, 2026
Close a commit store's keys individually, so an await waits only for its own variable's writers
#102
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
groupby's key type is its key function's codomain, and the lowered shape relates them nowhere:__gb_k's only occurrence is as an operand of the partition predicate's==, so the key's type could only arrive backwards through that comparison — making group-by key inference depend on an operator's internals.Type::SharedHole(id)lets lowering state the relation outright: aHolewith an identity, every occurrence of one id normalizing to the same inference variable. It is transient exactly asHoleis, and groups with it everywhere outsidenormalize_annotation.groupbystamps one id on the key application and on its owndata_funannotation's domain — the positions the claim is about, not the binder this desugaring invented. That also makes the edge directional for free:bind_annotationrecordsinferred <: annand a function is contravariant in its domain, so keys flow into the domain rather than being forced equal to it.symbolicdoes not render annotations, sotest_lower_groupbycannot show the relation;test_groupby_key_type_comes_from_the_key_functionpins it.