Comments (11)
@adonovan independent of promoting this to the standard library, I think we should reconsider the API:
- There's no need for
Iterate
, since it is not generic and redundant withAll
. - I don't think we should include the
KeysString
andKeys
methods, as they have resp. 0 and 1 non-test usages in x/tools, and don't seem to fit. If we want, we can later haveTypeSet
which behaves likes a set. SetHasher
seems like it may be a premature optimization (to me). I could be convinced otherwise. If we move this proposal togo/types
, I'd feel more strongly that we should leave outSetHasher
.
from go.
Change https://go.dev/cl/581435 mentions this issue: go/types/typeutil: TypeMap, a generic wrapper with go1.23 iterator
from go.
Nice, this would be handy.
Though I think we should either have All
return an iter.Seq2
, or hold off on this API addition until the idiom has stabilized. I'm also not sure whether the All
naming convention will win out over, say, Iter
. IMO, no particular reason to bundle this with the proposal for a generic API.
from go.
Good point. Since iter.Seq
(which I think @rsc may merge this week) is not an alias, we can't spell out the func
type for now in the declaration of All
, and then replace it with iter.Seq
later once go1.23 is assured, as that would be a breaking change. The All
method would need to either be go1.23-tagged, or else permanently forgo the use of the informative type Seq
. So, I propose to do that (tag it), as part of this proposal.
I think All is the right name. Generally the pattern seems to be that iterators describe the sequence, they don't just say "iterator".
from go.
Hmm, I just considered the following:
- It's unfortunate that
typeutil.{Map, TypeMap}
both exist. - I've always thought it would be nice to use
typeutil.Map
as a better implementation oftypes.Context
. The current implementation ofContext
overloads the traversal ofTypeString
, which is tangled and can't be efficient. - In general, this is a very useful helper type.
Therefore, what if we instead promoted this proposal to go/types.TypeMap
, with a generic API?
from go.
Therefore, what if we instead promoted this proposal to go/types.TypeMap, with a generic API?
I could get behind that. We'd have to scrutinize the API extra carefully, but I think typeutil.Map has proven itself by now.
from go.
There's no need for Iterate, since it is not generic and redundant with All.
Agreed.
I don't think we should include the KeysString and Keys methods, as they have resp. 0 and 1 non-test usages in x/tools, and don't seem to fit. If we want, we can later have TypeSet which behaves likes a set.
Agreed. And it's only a matter of time before the iter
package (or some other std one) provides iter.ToKeysSlice(Seq2[K,V]) []K
.
SetHasher seems like it may be a premature optimization (to me). I could be convinced otherwise. If we move this proposal to go/types, I'd feel more strongly that we should leave out SetHasher.
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 At
accessor: RLock is not sufficient. That wouldn't change if we made the hasher private.
from go.
I'm ok with a go/types.TypeMap if we have a stable API.
But we should also consider if we can make use of the upcoming package unique
(#62483) and that way get process-wide unique type identifiers.
from go.
consider if we can make use of the upcoming package unique (#62483) and that way get process-wide unique type identifiers.
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".
from go.
We definitely don't want to mingle types.Objects from different "realms".
We may be able to benefit from the internal map implementation of unique
, since it shares similar concerns. But we won't be able to use unique
directly.
from go.
This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group
from go.
Related Issues (20)
- proposal: cmd/go: add go mod tidy -diff HOT 1
- proposal: runtime: surface silent panic-recovers
- x/telemetry/config: initial cmd/go and cmd/compile counters HOT 5
- path/filepath: COM0 and LPT0 are now reserved on Windows HOT 6
- x/tools/gopls: add end of line commas during completion
- proposal: flag: add slice flag HOT 2
- x/text/cmd/gotext: gotext extract panic: runtime error: invalid memory address or nil pointer dereference HOT 2
- proposal: Go2: error handling with #err suffix HOT 1
- x/website: doc/tutorial/handle-errors: `too many return values` HOT 2
- cmd/go: TestScript/gotoolchain_net failures HOT 2
- runtime: unexpected fault address 0 HOT 13
- x/tools/gopls: References: bug.Report in expandMethodSearch (via telemetry)
- runtime: unexpected fault address 0 [1.22 backport] HOT 3
- cmd/compile/internal/types2: TestStdlib failures HOT 31
- cmd/link: corrupted pclntab created by binutils strip for PIE binary HOT 2
- x/tools/gopls: reenable tests suppressed due to lack of build{ssa,ir} support for range-over-func or gotypesalias=1 HOT 2
- go/types, x/tools: help tool authors support the new go/types.Alias node
- net: Use Port 53 instead of Port 9 for routability tests in DNS. HOT 2
- proposal: structs: add NoUnkeyedLiterals, DoNotImplement, DoNotCompare, DoNotCopy HOT 10
- crypto/rand: Read violates condition `n == len(b) if and only if err == nil` for `len(b) == 0` HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go.