]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: generalize tparamIndex to arbitrary type parameter lists
authorRobert Griesemer <gri@golang.org>
Wed, 12 Apr 2023 16:43:41 +0000 (09:43 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 13 Apr 2023 14:44:42 +0000 (14:44 +0000)
commitf05c1941dd386217bd7c199c13be35a806fdd514
tree006e20770e4db1d0ec7a15edb850de233fbd6910
parentc38d122fd4df8481a5b57a696945d65b7d4fc28e
go/types, types2: generalize tparamIndex to arbitrary type parameter lists

tparamIndex returns the index of a type parameter given the type
parameter and a list of type parameters. If an index >= 0 is returned,
it is the index assigned to the type parameter (TypeParam.index), and
the index of the type parameter in the provided list of parameters.
For it to work correctly, the type parameter list must be from a single
type parameter declaration.

To allow for lists of arbitrary type parameters (from different generic
signatures), change the implementation to do a linear search. The result
is the index of the type parameter in the provided type parameter list,
which may be different from the index assigned to the type parameter.

The linear search is likely fast enough since type parameter lists tend
to be very short.

Change-Id: I913f97fa4c042abeb535ee86ca6657241a4cf796
Reviewed-on: https://go-review.googlesource.com/c/go/+/483995
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/types2/infer.go
src/go/types/infer.go