Skip to content

Commit 6b8b782

Browse files
griesemergopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> Run-TryBot: Robert Griesemer <[email protected]>
1 parent 21b4e01 commit 6b8b782

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

src/cmd/compile/internal/types2/infer.go

+15
Original file line numberDiff line numberDiff line change
@@ -775,3 +775,18 @@ func (w *cycleFinder) varList(list []*Var) {
775775
w.typ(v.typ)
776776
}
777777
}
778+
779+
// If tpar is a type parameter in list, tparamIndex returns the type parameter index.
780+
// Otherwise, the result is < 0. tpar must not be nil.
781+
func tparamIndex(list []*TypeParam, tpar *TypeParam) int {
782+
// Once a type parameter is bound its index is >= 0. However, there are some
783+
// code paths (namely tracing and type hashing) by which it is possible to
784+
// arrive here with a type parameter that has not been bound, hence the check
785+
// for 0 <= i below.
786+
// TODO(rfindley): investigate a better approach for guarding against using
787+
// unbound type parameters.
788+
if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar {
789+
return i
790+
}
791+
return -1
792+
}

src/cmd/compile/internal/types2/unify.go

-15
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,6 @@ func (u *unifier) index(typ Type) int {
156156
return -1
157157
}
158158

159-
// If tpar is a type parameter in list, tparamIndex returns the type parameter index.
160-
// Otherwise, the result is < 0. tpar must not be nil.
161-
func tparamIndex(list []*TypeParam, tpar *TypeParam) int {
162-
// Once a type parameter is bound its index is >= 0. However, there are some
163-
// code paths (namely tracing and type hashing) by which it is possible to
164-
// arrive here with a type parameter that has not been bound, hence the check
165-
// for 0 <= i below.
166-
// TODO(rfindley): investigate a better approach for guarding against using
167-
// unbound type parameters.
168-
if i := tpar.index; 0 <= i && i < len(list) && list[i] == tpar {
169-
return i
170-
}
171-
return -1
172-
}
173-
174159
// setIndex sets the type slot index for the i'th type parameter
175160
// (and all its joined parameters) to tj. The type parameter
176161
// must have a (possibly nil) type slot associated with it.

src/go/types/infer.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/go/types/unify.go

-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)