-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: x/tools/go/types/typeutil: add TypeMap[V] #67161
Comments
Change https://go.dev/cl/581435 mentions this issue: |
Nice, this would be handy. Though I think we should either have |
Good point. Since I think All is the right name. Generally the pattern seems to be that iterators describe the sequence, they don't just say "iterator". |
Hmm, I just considered the following:
Therefore, what if we instead promoted this proposal to |
I could get behind that. We'd have to scrutinize the API extra carefully, but I think typeutil.Map has proven itself by now. |
@adonovan independent of promoting this to the standard library, I think we should reconsider the API:
|
Agreed.
Agreed. And it's only a matter of time before the
Quite possibly, but IIRC it was motivated by profiling go/ssa and the observation that several Maps had highly correlated key sets. In particular, Program.RuntimeTypes did (still does) a lot of transitive reachability accumulation. (I would like to change that, by making the transitive step lazy and factoring ssa.forEachReachable in common with rta.addRuntimeType.) We should measure then decide. Remember that even read-only operations on a typeutil.Map require a read-write change to the hasher, which complicates the locking story for the |
I'm ok with a go/types.TypeMap if we have a stable API. |
I don't see the connection. TypeMap is a hashtable with custom hash/equivalence operators. Unique is about a global interning pool. We definitely don't want to mingle types.Objects from different "realms". |
We may be able to benefit from the internal map implementation of |
This proposal has been added to the active column of the proposals project |
Regarding moving this to go/types and eliminating the Hasher API: even if performance doesn't suffer (which we haven't shown yet), this won't work because go/ssa's support for generics needs a way to canonicalize a tuple of Types (not Vars, so types.Tuple won't do). Today it does this externally, making Hasher calls directly. So we would need to either expose the Hasher, or make the new TypeMap allow tuples of types as keys. (go/types defines TypeList as a tuple of types, but it's not a Type, and they can't be created externally.) I think this needs more thought than than the go1.23 freeze allows. Let's put this on hold (both parts, typeutil and go/types). |
This proposal has been added to the active column of the proposals project |
Sorry, not sure why my bot moved it to active. Back to hold. |
Change https://go.dev/cl/612217 mentions this issue: |
Withdrawing this proposal in favor of #69420, which adds the new API direct to go/types. |
This proposal has been declined as retracted. |
[EDIT: withdrawn in favor of this proposal:]
We propose to add a generic wrapper around
typeutil.Map
. The obvious name isTypeMap[V]
. Only the necessary methods need to be parameterized; the remainder will be promoted from a non-exported embedding of Map.(Aside: this technique seems quite general. If in future Map should ever sprout a method that we don't want promoted to TypeMap, but nor do we want to shadow it with a parameterized variant, it's possible for TypeMap to embed another field, of size zero, that defines a conflicting method, so the two annihilate.)
[Update: I changed the declaration of All to use iter.Seq2, requiring a go1.23 build tag.]
@findleyr @griesemer
The text was updated successfully, but these errors were encountered: