Skip to content

Commit 8f9869c

Browse files
Tim KingGo LUCI
Tim King
authored and
Go LUCI
committed
go/ssa: use NormalTerms
Use typeparams.NormalTerms in go/ssa. Adjusts NormalTerms to preserve names and aliases. As a part of this, NormalTerms now no longer uses the Underlying() on *types.TypeParams. Change-Id: Ic09c0fba46982b81066b396f11a5b0ea48739819 Reviewed-on: https://go-review.googlesource.com/c/tools/+/642155 Reviewed-by: Robert Findley <[email protected]> Commit-Queue: Tim King <[email protected]> Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Tim King <[email protected]>
1 parent 8912752 commit 8f9869c

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

go/ssa/typeset.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,7 @@ func typeset(typ types.Type, yield func(t, u types.Type) bool) {
4848

4949
// termListOf returns the type set of typ as a normalized term set. Returns an empty set on an error.
5050
func termListOf(typ types.Type) []*types.Term {
51-
// This is a adaptation of x/exp/typeparams.NormalTerms which x/tools cannot depend on.
52-
var terms []*types.Term
53-
var err error
54-
// typeSetOf(t) == typeSetOf(Unalias(t))
55-
switch typ := types.Unalias(typ).(type) {
56-
case *types.TypeParam:
57-
terms, err = typeparams.StructuralTerms(typ)
58-
case *types.Union:
59-
terms, err = typeparams.UnionTermSet(typ)
60-
case *types.Interface:
61-
terms, err = typeparams.InterfaceTermSet(typ)
62-
default:
63-
// Common case.
64-
// Specializing the len=1 case to avoid a slice
65-
// had no measurable space/time benefit.
66-
terms = []*types.Term{types.NewTerm(false, typ)}
67-
}
68-
51+
terms, err := typeparams.NormalTerms(typ)
6952
if err != nil {
7053
return nil
7154
}

internal/typeparams/coretype.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,21 @@ func CoreType(T types.Type) types.Type {
109109
//
110110
// NormalTerms makes no guarantees about the order of terms, except that it
111111
// is deterministic.
112-
func NormalTerms(typ types.Type) ([]*types.Term, error) {
113-
switch typ := typ.Underlying().(type) {
112+
func NormalTerms(T types.Type) ([]*types.Term, error) {
113+
// typeSetOf(T) == typeSetOf(Unalias(T))
114+
typ := types.Unalias(T)
115+
if named, ok := typ.(*types.Named); ok {
116+
typ = named.Underlying()
117+
}
118+
switch typ := typ.(type) {
114119
case *types.TypeParam:
115120
return StructuralTerms(typ)
116121
case *types.Union:
117122
return UnionTermSet(typ)
118123
case *types.Interface:
119124
return InterfaceTermSet(typ)
120125
default:
121-
return []*types.Term{types.NewTerm(false, typ)}, nil
126+
return []*types.Term{types.NewTerm(false, T)}, nil
122127
}
123128
}
124129

0 commit comments

Comments
 (0)