From 6b8b7823c7fd9f3f2317f657120dc2e965d97b77 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 26 Jan 2023 17:21:51 -0800 Subject: [PATCH] go/types, types2: move tparamIndex from unify.go into infer.go Minor code reorganization: the next version of unify.go doesn't need this function anymore, so move it where it is still used. Change-Id: I6744a2361b5dfe2564ec73787a7a110e85ac9f1d Reviewed-on: https://go-review.googlesource.com/c/go/+/463230 TryBot-Result: Gopher Robot Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer Reviewed-by: Robert Findley Run-TryBot: Robert Griesemer --- src/cmd/compile/internal/types2/infer.go | 15 +++++++++++++++ src/cmd/compile/internal/types2/unify.go | 15 --------------- src/go/types/infer.go | 15 +++++++++++++++ src/go/types/unify.go | 15 --------------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go index 24a71367c5..55ee916fdb 100644 --- a/src/cmd/compile/internal/types2/infer.go +++ b/src/cmd/compile/internal/types2/infer.go @@ -775,3 +775,18 @@ func (w *cycleFinder) varList(list []*Var) { w.typ(v.typ) } } + +// If tpar is a type parameter in list, tparamIndex returns the type parameter index. +// Otherwise, the result is < 0. tpar must not be nil. +func tparamIndex(list []*TypeParam, tpar *TypeParam) int { + // Once a type parameter is bound its index is >= 0. However, there are some + // code paths (namely tracing and type hashing) by which it is possible to + // arrive here with a type parameter that has not been bound, hence the check + // for 0 <= i below. + // TODO(rfindley): investigate a better approach for guarding against using + // unbound type parameters. + if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar { + return i + } + return -1 +} diff --git a/src/cmd/compile/internal/types2/unify.go b/src/cmd/compile/internal/types2/unify.go index bca7231bbb..836db5b76b 100644 --- a/src/cmd/compile/internal/types2/unify.go +++ b/src/cmd/compile/internal/types2/unify.go @@ -156,21 +156,6 @@ func (u *unifier) index(typ Type) int { return -1 } -// If tpar is a type parameter in list, tparamIndex returns the type parameter index. -// Otherwise, the result is < 0. tpar must not be nil. -func tparamIndex(list []*TypeParam, tpar *TypeParam) int { - // Once a type parameter is bound its index is >= 0. However, there are some - // code paths (namely tracing and type hashing) by which it is possible to - // arrive here with a type parameter that has not been bound, hence the check - // for 0 <= i below. - // TODO(rfindley): investigate a better approach for guarding against using - // unbound type parameters. - if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar { - return i - } - return -1 -} - // setIndex sets the type slot index for the i'th type parameter // (and all its joined parameters) to tj. The type parameter // must have a (possibly nil) type slot associated with it. diff --git a/src/go/types/infer.go b/src/go/types/infer.go index 7b921c3b94..2e6fc7f16f 100644 --- a/src/go/types/infer.go +++ b/src/go/types/infer.go @@ -777,3 +777,18 @@ func (w *cycleFinder) varList(list []*Var) { w.typ(v.typ) } } + +// If tpar is a type parameter in list, tparamIndex returns the type parameter index. +// Otherwise, the result is < 0. tpar must not be nil. +func tparamIndex(list []*TypeParam, tpar *TypeParam) int { + // Once a type parameter is bound its index is >= 0. However, there are some + // code paths (namely tracing and type hashing) by which it is possible to + // arrive here with a type parameter that has not been bound, hence the check + // for 0 <= i below. + // TODO(rfindley): investigate a better approach for guarding against using + // unbound type parameters. + if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar { + return i + } + return -1 +} diff --git a/src/go/types/unify.go b/src/go/types/unify.go index a83757f2a4..d281420268 100644 --- a/src/go/types/unify.go +++ b/src/go/types/unify.go @@ -158,21 +158,6 @@ func (u *unifier) index(typ Type) int { return -1 } -// If tpar is a type parameter in list, tparamIndex returns the type parameter index. -// Otherwise, the result is < 0. tpar must not be nil. -func tparamIndex(list []*TypeParam, tpar *TypeParam) int { - // Once a type parameter is bound its index is >= 0. However, there are some - // code paths (namely tracing and type hashing) by which it is possible to - // arrive here with a type parameter that has not been bound, hence the check - // for 0 <= i below. - // TODO(rfindley): investigate a better approach for guarding against using - // unbound type parameters. - if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar { - return i - } - return -1 -} - // setIndex sets the type slot index for the i'th type parameter // (and all its joined parameters) to tj. The type parameter // must have a (possibly nil) type slot associated with it. -- 2.48.1