cmd/compile/internal/types: unexport Type.Extra

Not used outside of package types anymore. Let's keep it that.

Change-Id: I69b464ac94edaacd219da4210f7b8618e2beaf70
Reviewed-on: https://go-review.googlesource.com/c/go/+/345413
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2021-08-26 11:46:24 -07:00
parent 1f8d4562de
commit 3836983779
4 changed files with 103 additions and 104 deletions

View file

@ -298,7 +298,7 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
return return
} }
if t.Kind() == TSSA { if t.Kind() == TSSA {
b.WriteString(t.Extra.(string)) b.WriteString(t.extra.(string))
return return
} }
if t.Kind() == TTUPLE { if t.Kind() == TTUPLE {
@ -309,7 +309,7 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
} }
if t.Kind() == TRESULTS { if t.Kind() == TRESULTS {
tys := t.Extra.(*Results).Types tys := t.extra.(*Results).Types
for i, et := range tys { for i, et := range tys {
if i > 0 { if i > 0 {
b.WriteByte(',') b.WriteByte(',')

View file

@ -526,7 +526,7 @@ func CalcSize(t *Type) {
w = calcStructOffset(t1, t1.Recvs(), 0, 0) w = calcStructOffset(t1, t1.Recvs(), 0, 0)
w = calcStructOffset(t1, t1.Params(), w, RegSize) w = calcStructOffset(t1, t1.Params(), w, RegSize)
w = calcStructOffset(t1, t1.Results(), w, RegSize) w = calcStructOffset(t1, t1.Results(), w, RegSize)
t1.Extra.(*Func).Argwid = w t1.extra.(*Func).Argwid = w
if w%int64(RegSize) != 0 { if w%int64(RegSize) != 0 {
base.Warn("bad type %v %d\n", t1, w) base.Warn("bad type %v %d\n", t1, w)
} }

View file

@ -139,7 +139,7 @@ var (
// A Type represents a Go type. // A Type represents a Go type.
type Type struct { type Type struct {
// Extra contains extra etype-specific fields. // extra contains extra etype-specific fields.
// As an optimization, those etype-specific structs which contain exactly // As an optimization, those etype-specific structs which contain exactly
// one pointer-shaped field are stored as values rather than pointers when possible. // one pointer-shaped field are stored as values rather than pointers when possible.
// //
@ -156,7 +156,7 @@ type Type struct {
// TSLICE: Slice // TSLICE: Slice
// TSSA: string // TSSA: string
// TTYPEPARAM: *Typeparam // TTYPEPARAM: *Typeparam
Extra interface{} extra interface{}
// Width is the width of this Type in bytes. // Width is the width of this Type in bytes.
Width int64 // valid if Align > 0 Width int64 // valid if Align > 0
@ -325,11 +325,11 @@ var NoPkg *Pkg = nil
func (t *Type) Pkg() *Pkg { func (t *Type) Pkg() *Pkg {
switch t.kind { switch t.kind {
case TFUNC: case TFUNC:
return t.Extra.(*Func).pkg return t.extra.(*Func).pkg
case TSTRUCT: case TSTRUCT:
return t.Extra.(*Struct).pkg return t.extra.(*Struct).pkg
case TINTER: case TINTER:
return t.Extra.(*Interface).pkg return t.extra.(*Interface).pkg
default: default:
base.Fatalf("Pkg: unexpected kind: %v", t) base.Fatalf("Pkg: unexpected kind: %v", t)
return nil return nil
@ -349,7 +349,7 @@ type Map struct {
// MapType returns t's extra map-specific fields. // MapType returns t's extra map-specific fields.
func (t *Type) MapType() *Map { func (t *Type) MapType() *Map {
t.wantEtype(TMAP) t.wantEtype(TMAP)
return t.Extra.(*Map) return t.extra.(*Map)
} }
// Forward contains Type fields specific to forward types. // Forward contains Type fields specific to forward types.
@ -361,7 +361,7 @@ type Forward struct {
// ForwardType returns t's extra forward-type-specific fields. // ForwardType returns t's extra forward-type-specific fields.
func (t *Type) ForwardType() *Forward { func (t *Type) ForwardType() *Forward {
t.wantEtype(TFORW) t.wantEtype(TFORW)
return t.Extra.(*Forward) return t.extra.(*Forward)
} }
// Func contains Type fields specific to func types. // Func contains Type fields specific to func types.
@ -382,7 +382,7 @@ type Func struct {
// FuncType returns t's extra func-specific fields. // FuncType returns t's extra func-specific fields.
func (t *Type) FuncType() *Func { func (t *Type) FuncType() *Func {
t.wantEtype(TFUNC) t.wantEtype(TFUNC)
return t.Extra.(*Func) return t.extra.(*Func)
} }
// StructType contains Type fields specific to struct types. // StructType contains Type fields specific to struct types.
@ -411,7 +411,7 @@ const (
// StructType returns t's extra struct-specific fields. // StructType returns t's extra struct-specific fields.
func (t *Type) StructType() *Struct { func (t *Type) StructType() *Struct {
t.wantEtype(TSTRUCT) t.wantEtype(TSTRUCT)
return t.Extra.(*Struct) return t.extra.(*Struct)
} }
// Interface contains Type fields specific to interface types. // Interface contains Type fields specific to interface types.
@ -455,7 +455,7 @@ type Chan struct {
// ChanType returns t's extra channel-specific fields. // ChanType returns t's extra channel-specific fields.
func (t *Type) ChanType() *Chan { func (t *Type) ChanType() *Chan {
t.wantEtype(TCHAN) t.wantEtype(TCHAN)
return t.Extra.(*Chan) return t.extra.(*Chan)
} }
type Tuple struct { type Tuple struct {
@ -590,31 +590,31 @@ func New(et Kind) *Type {
// TODO(josharian): lazily initialize some of these? // TODO(josharian): lazily initialize some of these?
switch t.kind { switch t.kind {
case TMAP: case TMAP:
t.Extra = new(Map) t.extra = new(Map)
case TFORW: case TFORW:
t.Extra = new(Forward) t.extra = new(Forward)
case TFUNC: case TFUNC:
t.Extra = new(Func) t.extra = new(Func)
case TSTRUCT: case TSTRUCT:
t.Extra = new(Struct) t.extra = new(Struct)
case TINTER: case TINTER:
t.Extra = new(Interface) t.extra = new(Interface)
case TPTR: case TPTR:
t.Extra = Ptr{} t.extra = Ptr{}
case TCHANARGS: case TCHANARGS:
t.Extra = ChanArgs{} t.extra = ChanArgs{}
case TFUNCARGS: case TFUNCARGS:
t.Extra = FuncArgs{} t.extra = FuncArgs{}
case TCHAN: case TCHAN:
t.Extra = new(Chan) t.extra = new(Chan)
case TTUPLE: case TTUPLE:
t.Extra = new(Tuple) t.extra = new(Tuple)
case TRESULTS: case TRESULTS:
t.Extra = new(Results) t.extra = new(Results)
case TTYPEPARAM: case TTYPEPARAM:
t.Extra = new(Typeparam) t.extra = new(Typeparam)
case TUNION: case TUNION:
t.Extra = new(Union) t.extra = new(Union)
} }
return t return t
} }
@ -625,7 +625,7 @@ func NewArray(elem *Type, bound int64) *Type {
base.Fatalf("NewArray: invalid bound %v", bound) base.Fatalf("NewArray: invalid bound %v", bound)
} }
t := New(TARRAY) t := New(TARRAY)
t.Extra = &Array{Elem: elem, Bound: bound} t.extra = &Array{Elem: elem, Bound: bound}
t.SetNotInHeap(elem.NotInHeap()) t.SetNotInHeap(elem.NotInHeap())
if elem.HasTParam() { if elem.HasTParam() {
t.SetHasTParam(true) t.SetHasTParam(true)
@ -646,7 +646,7 @@ func NewSlice(elem *Type) *Type {
} }
t := New(TSLICE) t := New(TSLICE)
t.Extra = Slice{Elem: elem} t.extra = Slice{Elem: elem}
elem.cache.slice = t elem.cache.slice = t
if elem.HasTParam() { if elem.HasTParam() {
t.SetHasTParam(true) t.SetHasTParam(true)
@ -674,8 +674,8 @@ func NewChan(elem *Type, dir ChanDir) *Type {
func NewTuple(t1, t2 *Type) *Type { func NewTuple(t1, t2 *Type) *Type {
t := New(TTUPLE) t := New(TTUPLE)
t.Extra.(*Tuple).first = t1 t.extra.(*Tuple).first = t1
t.Extra.(*Tuple).second = t2 t.extra.(*Tuple).second = t2
if t1.HasTParam() || t2.HasTParam() { if t1.HasTParam() || t2.HasTParam() {
t.SetHasTParam(true) t.SetHasTParam(true)
} }
@ -687,7 +687,7 @@ func NewTuple(t1, t2 *Type) *Type {
func newResults(types []*Type) *Type { func newResults(types []*Type) *Type {
t := New(TRESULTS) t := New(TRESULTS)
t.Extra.(*Results).Types = types t.extra.(*Results).Types = types
return t return t
} }
@ -700,7 +700,7 @@ func NewResults(types []*Type) *Type {
func newSSA(name string) *Type { func newSSA(name string) *Type {
t := New(TSSA) t := New(TSSA)
t.Extra = name t.extra = name
return t return t
} }
@ -747,7 +747,7 @@ func NewPtr(elem *Type) *Type {
} }
t := New(TPTR) t := New(TPTR)
t.Extra = Ptr{Elem: elem} t.extra = Ptr{Elem: elem}
t.Width = int64(PtrSize) t.Width = int64(PtrSize)
t.Align = uint8(PtrSize) t.Align = uint8(PtrSize)
if NewPtrCacheEnabled { if NewPtrCacheEnabled {
@ -765,14 +765,14 @@ func NewPtr(elem *Type) *Type {
// NewChanArgs returns a new TCHANARGS type for channel type c. // NewChanArgs returns a new TCHANARGS type for channel type c.
func NewChanArgs(c *Type) *Type { func NewChanArgs(c *Type) *Type {
t := New(TCHANARGS) t := New(TCHANARGS)
t.Extra = ChanArgs{T: c} t.extra = ChanArgs{T: c}
return t return t
} }
// NewFuncArgs returns a new TFUNCARGS type for func type f. // NewFuncArgs returns a new TFUNCARGS type for func type f.
func NewFuncArgs(f *Type) *Type { func NewFuncArgs(f *Type) *Type {
t := New(TFUNCARGS) t := New(TFUNCARGS)
t.Extra = FuncArgs{T: f} t.extra = FuncArgs{T: f}
return t return t
} }
@ -811,28 +811,28 @@ func SubstAny(t *Type, types *[]*Type) *Type {
elem := SubstAny(t.Elem(), types) elem := SubstAny(t.Elem(), types)
if elem != t.Elem() { if elem != t.Elem() {
t = t.copy() t = t.copy()
t.Extra = Ptr{Elem: elem} t.extra = Ptr{Elem: elem}
} }
case TARRAY: case TARRAY:
elem := SubstAny(t.Elem(), types) elem := SubstAny(t.Elem(), types)
if elem != t.Elem() { if elem != t.Elem() {
t = t.copy() t = t.copy()
t.Extra.(*Array).Elem = elem t.extra.(*Array).Elem = elem
} }
case TSLICE: case TSLICE:
elem := SubstAny(t.Elem(), types) elem := SubstAny(t.Elem(), types)
if elem != t.Elem() { if elem != t.Elem() {
t = t.copy() t = t.copy()
t.Extra = Slice{Elem: elem} t.extra = Slice{Elem: elem}
} }
case TCHAN: case TCHAN:
elem := SubstAny(t.Elem(), types) elem := SubstAny(t.Elem(), types)
if elem != t.Elem() { if elem != t.Elem() {
t = t.copy() t = t.copy()
t.Extra.(*Chan).Elem = elem t.extra.(*Chan).Elem = elem
} }
case TMAP: case TMAP:
@ -840,8 +840,8 @@ func SubstAny(t *Type, types *[]*Type) *Type {
elem := SubstAny(t.Elem(), types) elem := SubstAny(t.Elem(), types)
if key != t.Key() || elem != t.Elem() { if key != t.Key() || elem != t.Elem() {
t = t.copy() t = t.copy()
t.Extra.(*Map).Key = key t.extra.(*Map).Key = key
t.Extra.(*Map).Elem = elem t.extra.(*Map).Elem = elem
} }
case TFUNC: case TFUNC:
@ -882,26 +882,26 @@ func (t *Type) copy() *Type {
// copy any *T Extra fields, to avoid aliasing // copy any *T Extra fields, to avoid aliasing
switch t.kind { switch t.kind {
case TMAP: case TMAP:
x := *t.Extra.(*Map) x := *t.extra.(*Map)
nt.Extra = &x nt.extra = &x
case TFORW: case TFORW:
x := *t.Extra.(*Forward) x := *t.extra.(*Forward)
nt.Extra = &x nt.extra = &x
case TFUNC: case TFUNC:
x := *t.Extra.(*Func) x := *t.extra.(*Func)
nt.Extra = &x nt.extra = &x
case TSTRUCT: case TSTRUCT:
x := *t.Extra.(*Struct) x := *t.extra.(*Struct)
nt.Extra = &x nt.extra = &x
case TINTER: case TINTER:
x := *t.Extra.(*Interface) x := *t.extra.(*Interface)
nt.Extra = &x nt.extra = &x
case TCHAN: case TCHAN:
x := *t.Extra.(*Chan) x := *t.extra.(*Chan)
nt.Extra = &x nt.extra = &x
case TARRAY: case TARRAY:
x := *t.Extra.(*Array) x := *t.extra.(*Array)
nt.Extra = &x nt.extra = &x
case TTYPEPARAM: case TTYPEPARAM:
base.Fatalf("typeparam types cannot be copied") base.Fatalf("typeparam types cannot be copied")
case TTUPLE, TSSA, TRESULTS: case TTUPLE, TSSA, TRESULTS:
@ -970,7 +970,7 @@ var ParamsResults = [2]func(*Type) *Type{
// Key returns the key type of map type t. // Key returns the key type of map type t.
func (t *Type) Key() *Type { func (t *Type) Key() *Type {
t.wantEtype(TMAP) t.wantEtype(TMAP)
return t.Extra.(*Map).Key return t.extra.(*Map).Key
} }
// Elem returns the type of elements of t. // Elem returns the type of elements of t.
@ -978,15 +978,15 @@ func (t *Type) Key() *Type {
func (t *Type) Elem() *Type { func (t *Type) Elem() *Type {
switch t.kind { switch t.kind {
case TPTR: case TPTR:
return t.Extra.(Ptr).Elem return t.extra.(Ptr).Elem
case TARRAY: case TARRAY:
return t.Extra.(*Array).Elem return t.extra.(*Array).Elem
case TSLICE: case TSLICE:
return t.Extra.(Slice).Elem return t.extra.(Slice).Elem
case TCHAN: case TCHAN:
return t.Extra.(*Chan).Elem return t.extra.(*Chan).Elem
case TMAP: case TMAP:
return t.Extra.(*Map).Elem return t.extra.(*Map).Elem
} }
base.Fatalf("Type.Elem %s", t.kind) base.Fatalf("Type.Elem %s", t.kind)
return nil return nil
@ -995,18 +995,18 @@ func (t *Type) Elem() *Type {
// ChanArgs returns the channel type for TCHANARGS type t. // ChanArgs returns the channel type for TCHANARGS type t.
func (t *Type) ChanArgs() *Type { func (t *Type) ChanArgs() *Type {
t.wantEtype(TCHANARGS) t.wantEtype(TCHANARGS)
return t.Extra.(ChanArgs).T return t.extra.(ChanArgs).T
} }
// FuncArgs returns the func type for TFUNCARGS type t. // FuncArgs returns the func type for TFUNCARGS type t.
func (t *Type) FuncArgs() *Type { func (t *Type) FuncArgs() *Type {
t.wantEtype(TFUNCARGS) t.wantEtype(TFUNCARGS)
return t.Extra.(FuncArgs).T return t.extra.(FuncArgs).T
} }
// IsFuncArgStruct reports whether t is a struct representing function parameters or results. // IsFuncArgStruct reports whether t is a struct representing function parameters or results.
func (t *Type) IsFuncArgStruct() bool { func (t *Type) IsFuncArgStruct() bool {
return t.kind == TSTRUCT && t.Extra.(*Struct).Funarg != FunargNone return t.kind == TSTRUCT && t.extra.(*Struct).Funarg != FunargNone
} }
// Methods returns a pointer to the base methods (excluding embedding) for type t. // Methods returns a pointer to the base methods (excluding embedding) for type t.
@ -1037,7 +1037,7 @@ func (t *Type) SetAllMethods(fs []*Field) {
// Fields returns the fields of struct type t. // Fields returns the fields of struct type t.
func (t *Type) Fields() *Fields { func (t *Type) Fields() *Fields {
t.wantEtype(TSTRUCT) t.wantEtype(TSTRUCT)
return &t.Extra.(*Struct).fields return &t.extra.(*Struct).fields
} }
// Field returns the i'th field of struct type t. // Field returns the i'th field of struct type t.
@ -1091,7 +1091,7 @@ func (t *Type) WidthCalculated() bool {
// It includes the receiver, parameters, and results. // It includes the receiver, parameters, and results.
func (t *Type) ArgWidth() int64 { func (t *Type) ArgWidth() int64 {
t.wantEtype(TFUNC) t.wantEtype(TFUNC)
return t.Extra.(*Func).Argwid return t.extra.(*Func).Argwid
} }
func (t *Type) Size() int64 { func (t *Type) Size() int64 {
@ -1234,8 +1234,8 @@ func (t *Type) cmp(x *Type) Cmp {
return CMPeq return CMPeq
case TSSA: case TSSA:
tname := t.Extra.(string) tname := t.extra.(string)
xname := x.Extra.(string) xname := x.extra.(string)
// desire fast sorting, not pretty sorting. // desire fast sorting, not pretty sorting.
if len(tname) == len(xname) { if len(tname) == len(xname) {
if tname == xname { if tname == xname {
@ -1252,16 +1252,16 @@ func (t *Type) cmp(x *Type) Cmp {
return CMPlt return CMPlt
case TTUPLE: case TTUPLE:
xtup := x.Extra.(*Tuple) xtup := x.extra.(*Tuple)
ttup := t.Extra.(*Tuple) ttup := t.extra.(*Tuple)
if c := ttup.first.Compare(xtup.first); c != CMPeq { if c := ttup.first.Compare(xtup.first); c != CMPeq {
return c return c
} }
return ttup.second.Compare(xtup.second) return ttup.second.Compare(xtup.second)
case TRESULTS: case TRESULTS:
xResults := x.Extra.(*Results) xResults := x.extra.(*Results)
tResults := t.Extra.(*Results) tResults := t.extra.(*Results)
xl, tl := len(xResults.Types), len(tResults.Types) xl, tl := len(xResults.Types), len(tResults.Types)
if tl != xl { if tl != xl {
if tl < xl { if tl < xl {
@ -1548,7 +1548,7 @@ func (t *Type) PtrTo() *Type {
func (t *Type) NumFields() int { func (t *Type) NumFields() int {
if t.kind == TRESULTS { if t.kind == TRESULTS {
return len(t.Extra.(*Results).Types) return len(t.extra.(*Results).Types)
} }
return t.Fields().Len() return t.Fields().Len()
} }
@ -1556,15 +1556,15 @@ func (t *Type) FieldType(i int) *Type {
if t.kind == TTUPLE { if t.kind == TTUPLE {
switch i { switch i {
case 0: case 0:
return t.Extra.(*Tuple).first return t.extra.(*Tuple).first
case 1: case 1:
return t.Extra.(*Tuple).second return t.extra.(*Tuple).second
default: default:
panic("bad tuple index") panic("bad tuple index")
} }
} }
if t.kind == TRESULTS { if t.kind == TRESULTS {
return t.Extra.(*Results).Types[i] return t.extra.(*Results).Types[i]
} }
return t.Field(i).Type return t.Field(i).Type
} }
@ -1577,7 +1577,7 @@ func (t *Type) FieldName(i int) string {
func (t *Type) NumElem() int64 { func (t *Type) NumElem() int64 {
t.wantEtype(TARRAY) t.wantEtype(TARRAY)
return t.Extra.(*Array).Bound return t.extra.(*Array).Bound
} }
type componentsIncludeBlankFields bool type componentsIncludeBlankFields bool
@ -1639,15 +1639,15 @@ func (t *Type) SoleComponent() *Type {
// The direction will be one of Crecv, Csend, or Cboth. // The direction will be one of Crecv, Csend, or Cboth.
func (t *Type) ChanDir() ChanDir { func (t *Type) ChanDir() ChanDir {
t.wantEtype(TCHAN) t.wantEtype(TCHAN)
return t.Extra.(*Chan).Dir return t.extra.(*Chan).Dir
} }
func (t *Type) IsMemory() bool { func (t *Type) IsMemory() bool {
if t == TypeMem || t.kind == TTUPLE && t.Extra.(*Tuple).second == TypeMem { if t == TypeMem || t.kind == TTUPLE && t.extra.(*Tuple).second == TypeMem {
return true return true
} }
if t.kind == TRESULTS { if t.kind == TRESULTS {
if types := t.Extra.(*Results).Types; len(types) > 0 && types[len(types)-1] == TypeMem { if types := t.extra.(*Results).Types; len(types) > 0 && types[len(types)-1] == TypeMem {
return true return true
} }
} }
@ -1699,11 +1699,11 @@ func (t *Type) HasPointers() bool {
return !t.Elem().NotInHeap() return !t.Elem().NotInHeap()
case TTUPLE: case TTUPLE:
ttup := t.Extra.(*Tuple) ttup := t.extra.(*Tuple)
return ttup.first.HasPointers() || ttup.second.HasPointers() return ttup.first.HasPointers() || ttup.second.HasPointers()
case TRESULTS: case TRESULTS:
types := t.Extra.(*Results).Types types := t.extra.(*Results).Types
for _, et := range types { for _, et := range types {
if et.HasPointers() { if et.HasPointers() {
return true return true
@ -1781,7 +1781,7 @@ func (t *Type) SetUnderlying(underlying *Type) {
// TODO(mdempsky): Fix Type rekinding. // TODO(mdempsky): Fix Type rekinding.
t.kind = underlying.kind t.kind = underlying.kind
t.Extra = underlying.Extra t.extra = underlying.extra
t.Width = underlying.Width t.Width = underlying.Width
t.Align = underlying.Align t.Align = underlying.Align
t.underlying = underlying.underlying t.underlying = underlying.underlying
@ -1865,7 +1865,7 @@ func NewInterface(pkg *Pkg, methods []*Field) *Type {
if anyBroke(methods) { if anyBroke(methods) {
t.SetBroke(true) t.SetBroke(true)
} }
t.Extra.(*Interface).pkg = pkg t.extra.(*Interface).pkg = pkg
return t return t
} }
@ -1874,7 +1874,7 @@ func NewInterface(pkg *Pkg, methods []*Field) *Type {
func NewTypeParam(sym *Sym, index int) *Type { func NewTypeParam(sym *Sym, index int) *Type {
t := New(TTYPEPARAM) t := New(TTYPEPARAM)
t.sym = sym t.sym = sym
t.Extra.(*Typeparam).index = index t.extra.(*Typeparam).index = index
t.SetHasTParam(true) t.SetHasTParam(true)
return t return t
} }
@ -1882,25 +1882,25 @@ func NewTypeParam(sym *Sym, index int) *Type {
// Index returns the index of the type param within its param list. // Index returns the index of the type param within its param list.
func (t *Type) Index() int { func (t *Type) Index() int {
t.wantEtype(TTYPEPARAM) t.wantEtype(TTYPEPARAM)
return t.Extra.(*Typeparam).index return t.extra.(*Typeparam).index
} }
// SetIndex sets the index of the type param within its param list. // SetIndex sets the index of the type param within its param list.
func (t *Type) SetIndex(i int) { func (t *Type) SetIndex(i int) {
t.wantEtype(TTYPEPARAM) t.wantEtype(TTYPEPARAM)
t.Extra.(*Typeparam).index = i t.extra.(*Typeparam).index = i
} }
// SetBound sets the bound of a typeparam. // SetBound sets the bound of a typeparam.
func (t *Type) SetBound(bound *Type) { func (t *Type) SetBound(bound *Type) {
t.wantEtype(TTYPEPARAM) t.wantEtype(TTYPEPARAM)
t.Extra.(*Typeparam).bound = bound t.extra.(*Typeparam).bound = bound
} }
// Bound returns the bound of a typeparam. // Bound returns the bound of a typeparam.
func (t *Type) Bound() *Type { func (t *Type) Bound() *Type {
t.wantEtype(TTYPEPARAM) t.wantEtype(TTYPEPARAM)
return t.Extra.(*Typeparam).bound return t.extra.(*Typeparam).bound
} }
// NewUnion returns a new union with the specified set of terms (types). If // NewUnion returns a new union with the specified set of terms (types). If
@ -1910,8 +1910,8 @@ func NewUnion(terms []*Type, tildes []bool) *Type {
if len(terms) != len(tildes) { if len(terms) != len(tildes) {
base.Fatalf("Mismatched terms and tildes for NewUnion") base.Fatalf("Mismatched terms and tildes for NewUnion")
} }
t.Extra.(*Union).terms = terms t.extra.(*Union).terms = terms
t.Extra.(*Union).tildes = tildes t.extra.(*Union).tildes = tildes
nt := len(terms) nt := len(terms)
for i := 0; i < nt; i++ { for i := 0; i < nt; i++ {
if terms[i].HasTParam() { if terms[i].HasTParam() {
@ -1927,14 +1927,14 @@ func NewUnion(terms []*Type, tildes []bool) *Type {
// NumTerms returns the number of terms in a union type. // NumTerms returns the number of terms in a union type.
func (t *Type) NumTerms() int { func (t *Type) NumTerms() int {
t.wantEtype(TUNION) t.wantEtype(TUNION)
return len(t.Extra.(*Union).terms) return len(t.extra.(*Union).terms)
} }
// Term returns ith term of a union type as (term, tilde). If tilde is true, term // Term returns ith term of a union type as (term, tilde). If tilde is true, term
// represents ~T, rather than just T. // represents ~T, rather than just T.
func (t *Type) Term(i int) (*Type, bool) { func (t *Type) Term(i int) (*Type, bool) {
t.wantEtype(TUNION) t.wantEtype(TUNION)
u := t.Extra.(*Union) u := t.extra.(*Union)
return u.terms[i], u.tildes[i] return u.terms[i], u.tildes[i]
} }
@ -1995,7 +1995,7 @@ func NewStruct(pkg *Pkg, fields []*Field) *Type {
if anyBroke(fields) { if anyBroke(fields) {
t.SetBroke(true) t.SetBroke(true)
} }
t.Extra.(*Struct).pkg = pkg t.extra.(*Struct).pkg = pkg
if fieldsHasTParam(fields) { if fieldsHasTParam(fields) {
t.SetHasTParam(true) t.SetHasTParam(true)
} }

View file

@ -2,26 +2,25 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package types_test package types
import ( import (
"cmd/compile/internal/types"
"testing" "testing"
) )
func TestSSACompare(t *testing.T) { func TestSSACompare(t *testing.T) {
a := []*types.Type{ a := []*Type{
types.TypeInvalid, TypeInvalid,
types.TypeMem, TypeMem,
types.TypeFlags, TypeFlags,
types.TypeVoid, TypeVoid,
types.TypeInt128, TypeInt128,
} }
for _, x := range a { for _, x := range a {
for _, y := range a { for _, y := range a {
c := x.Compare(y) c := x.Compare(y)
if x == y && c != types.CMPeq || x != y && c == types.CMPeq { if x == y && c != CMPeq || x != y && c == CMPeq {
t.Errorf("%s compare %s == %d\n", x.Extra, y.Extra, c) t.Errorf("%s compare %s == %d\n", x.extra, y.extra, c)
} }
} }
} }