Source file src/cmd/compile/internal/types/type.go

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package types
     6  
     7  import (
     8  	"cmd/compile/internal/base"
     9  	"cmd/internal/objabi"
    10  	"cmd/internal/src"
    11  	"fmt"
    12  	"go/constant"
    13  	"internal/types/errors"
    14  	"sync"
    15  )
    16  
    17  // Object represents an ir.Node, but without needing to import cmd/compile/internal/ir,
    18  // which would cause an import cycle. The uses in other packages must type assert
    19  // values of type Object to ir.Node or a more specific type.
    20  type Object interface {
    21  	Pos() src.XPos
    22  	Sym() *Sym
    23  	Type() *Type
    24  }
    25  
    26  //go:generate stringer -type Kind -trimprefix T type.go
    27  
    28  // Kind describes a kind of type.
    29  type Kind uint8
    30  
    31  const (
    32  	Txxx Kind = iota
    33  
    34  	TINT8
    35  	TUINT8
    36  	TINT16
    37  	TUINT16
    38  	TINT32
    39  	TUINT32
    40  	TINT64
    41  	TUINT64
    42  	TINT
    43  	TUINT
    44  	TUINTPTR
    45  
    46  	TCOMPLEX64
    47  	TCOMPLEX128
    48  
    49  	TFLOAT32
    50  	TFLOAT64
    51  
    52  	TBOOL
    53  
    54  	TPTR
    55  	TFUNC
    56  	TSLICE
    57  	TARRAY
    58  	TSTRUCT
    59  	TCHAN
    60  	TMAP
    61  	TINTER
    62  	TFORW
    63  	TANY
    64  	TSTRING
    65  	TUNSAFEPTR
    66  
    67  	// pseudo-types for literals
    68  	TIDEAL // untyped numeric constants
    69  	TNIL
    70  	TBLANK
    71  
    72  	// pseudo-types used temporarily only during frame layout (CalcSize())
    73  	TFUNCARGS
    74  	TCHANARGS
    75  
    76  	// SSA backend types
    77  	TSSA     // internal types used by SSA backend (flags, memory, etc.)
    78  	TTUPLE   // a pair of types, used by SSA backend
    79  	TRESULTS // multiple types; the result of calling a function or method, with a memory at the end.
    80  
    81  	NTYPE
    82  )
    83  
    84  // ChanDir is whether a channel can send, receive, or both.
    85  type ChanDir uint8
    86  
    87  func (c ChanDir) CanRecv() bool { return c&Crecv != 0 }
    88  func (c ChanDir) CanSend() bool { return c&Csend != 0 }
    89  
    90  const (
    91  	// types of channel
    92  	// must match ../../../../reflect/type.go:/ChanDir
    93  	Crecv ChanDir = 1 << 0
    94  	Csend ChanDir = 1 << 1
    95  	Cboth ChanDir = Crecv | Csend
    96  )
    97  
    98  // Types stores pointers to predeclared named types.
    99  //
   100  // It also stores pointers to several special types:
   101  //   - Types[TANY] is the placeholder "any" type recognized by SubstArgTypes.
   102  //   - Types[TBLANK] represents the blank variable's type.
   103  //   - Types[TINTER] is the canonical "interface{}" type.
   104  //   - Types[TNIL] represents the predeclared "nil" value's type.
   105  //   - Types[TUNSAFEPTR] is package unsafe's Pointer type.
   106  var Types [NTYPE]*Type
   107  
   108  var (
   109  	// Predeclared alias types. These are actually created as distinct
   110  	// defined types for better error messages, but are then specially
   111  	// treated as identical to their respective underlying types.
   112  	AnyType  *Type
   113  	ByteType *Type
   114  	RuneType *Type
   115  
   116  	// Predeclared error interface type.
   117  	ErrorType *Type
   118  	// Predeclared comparable interface type.
   119  	ComparableType *Type
   120  
   121  	// Types to represent untyped string and boolean constants.
   122  	UntypedString = newType(TSTRING)
   123  	UntypedBool   = newType(TBOOL)
   124  
   125  	// Types to represent untyped numeric constants.
   126  	UntypedInt     = newType(TIDEAL)
   127  	UntypedRune    = newType(TIDEAL)
   128  	UntypedFloat   = newType(TIDEAL)
   129  	UntypedComplex = newType(TIDEAL)
   130  )
   131  
   132  // UntypedTypes maps from a constant.Kind to its untyped Type
   133  // representation.
   134  var UntypedTypes = [...]*Type{
   135  	constant.Bool:    UntypedBool,
   136  	constant.String:  UntypedString,
   137  	constant.Int:     UntypedInt,
   138  	constant.Float:   UntypedFloat,
   139  	constant.Complex: UntypedComplex,
   140  }
   141  
   142  // DefaultKinds maps from a constant.Kind to its default Kind.
   143  var DefaultKinds = [...]Kind{
   144  	constant.Bool:    TBOOL,
   145  	constant.String:  TSTRING,
   146  	constant.Int:     TINT,
   147  	constant.Float:   TFLOAT64,
   148  	constant.Complex: TCOMPLEX128,
   149  }
   150  
   151  // A Type represents a Go type.
   152  //
   153  // There may be multiple unnamed types with identical structure. However, there must
   154  // be a unique Type object for each unique named (defined) type. After noding, a
   155  // package-level type can be looked up by building its unique symbol sym (sym =
   156  // package.Lookup(name)) and checking sym.Def. If sym.Def is non-nil, the type
   157  // already exists at package scope and is available at sym.Def.(*ir.Name).Type().
   158  // Local types (which may have the same name as a package-level type) are
   159  // distinguished by their vargen, which is embedded in their symbol name.
   160  type Type struct {
   161  	// extra contains extra etype-specific fields.
   162  	// As an optimization, those etype-specific structs which contain exactly
   163  	// one pointer-shaped field are stored as values rather than pointers when possible.
   164  	//
   165  	// TMAP: *Map
   166  	// TFORW: *Forward
   167  	// TFUNC: *Func
   168  	// TSTRUCT: *Struct
   169  	// TINTER: *Interface
   170  	// TFUNCARGS: FuncArgs
   171  	// TCHANARGS: ChanArgs
   172  	// TCHAN: *Chan
   173  	// TPTR: Ptr
   174  	// TARRAY: *Array
   175  	// TSLICE: Slice
   176  	// TSSA: string
   177  	extra any
   178  
   179  	// width is the width of this Type in bytes.
   180  	width int64 // valid if Align > 0
   181  
   182  	// list of base methods (excluding embedding)
   183  	methods fields
   184  	// list of all methods (including embedding)
   185  	allMethods fields
   186  
   187  	// canonical OTYPE node for a named type (should be an ir.Name node with same sym)
   188  	obj Object
   189  	// the underlying type (type literal or predeclared type) for a defined type
   190  	underlying *Type
   191  
   192  	// Cache of composite types, with this type being the element type.
   193  	cache struct {
   194  		ptr   *Type // *T, or nil
   195  		slice *Type // []T, or nil
   196  	}
   197  
   198  	kind  Kind  // kind of type
   199  	align uint8 // the required alignment of this type, in bytes (0 means Width and Align have not yet been computed)
   200  
   201  	intRegs, floatRegs uint8 // registers needed for ABIInternal
   202  
   203  	flags bitset16
   204  	alg   AlgKind // valid if Align > 0
   205  
   206  	// size of prefix of object that contains all pointers. valid if Align > 0.
   207  	// Note that for pointers, this is always PtrSize even if the element type
   208  	// is NotInHeap. See size.go:PtrDataSize for details.
   209  	ptrBytes int64
   210  }
   211  
   212  // Registers returns the number of integer and floating-point
   213  // registers required to represent a parameter of this type under the
   214  // ABIInternal calling conventions.
   215  //
   216  // If t must be passed by memory, Registers returns (math.MaxUint8,
   217  // math.MaxUint8).
   218  func (t *Type) Registers() (uint8, uint8) {
   219  	CalcSize(t)
   220  	return t.intRegs, t.floatRegs
   221  }
   222  
   223  func (*Type) CanBeAnSSAAux() {}
   224  
   225  const (
   226  	typeNotInHeap  = 1 << iota // type cannot be heap allocated
   227  	typeNoalg                  // suppress hash and eq algorithm generation
   228  	typeDeferwidth             // width computation has been deferred and type is on deferredTypeStack
   229  	typeRecur
   230  	typeIsShape  // represents a set of closely related types, for generics
   231  	typeHasShape // there is a shape somewhere in the type
   232  	// typeIsFullyInstantiated reports whether a type is fully instantiated generic type; i.e.
   233  	// an instantiated generic type where all type arguments are non-generic or fully instantiated generic types.
   234  	typeIsFullyInstantiated
   235  	typeIsSIMDTag // type is the SIMD marker type
   236  	typeIsSIMD    // type contains the SIMD marker type
   237  )
   238  
   239  func (t *Type) NotInHeap() bool           { return t.flags&typeNotInHeap != 0 }
   240  func (t *Type) Noalg() bool               { return t.flags&typeNoalg != 0 }
   241  func (t *Type) Deferwidth() bool          { return t.flags&typeDeferwidth != 0 }
   242  func (t *Type) Recur() bool               { return t.flags&typeRecur != 0 }
   243  func (t *Type) IsShape() bool             { return t.flags&typeIsShape != 0 }
   244  func (t *Type) HasShape() bool            { return t.flags&typeHasShape != 0 }
   245  func (t *Type) IsFullyInstantiated() bool { return t.flags&typeIsFullyInstantiated != 0 }
   246  
   247  func (t *Type) SetNotInHeap(b bool)           { t.flags.set(typeNotInHeap, b) }
   248  func (t *Type) SetNoalg(b bool)               { t.flags.set(typeNoalg, b) }
   249  func (t *Type) SetDeferwidth(b bool)          { t.flags.set(typeDeferwidth, b) }
   250  func (t *Type) SetRecur(b bool)               { t.flags.set(typeRecur, b) }
   251  func (t *Type) SetIsFullyInstantiated(b bool) { t.flags.set(typeIsFullyInstantiated, b) }
   252  
   253  // Should always do SetHasShape(true) when doing SetIsShape(true).
   254  func (t *Type) SetIsShape(b bool)  { t.flags.set(typeIsShape, b) }
   255  func (t *Type) SetHasShape(b bool) { t.flags.set(typeHasShape, b) }
   256  
   257  // Kind returns the kind of type t.
   258  func (t *Type) Kind() Kind { return t.kind }
   259  
   260  // Sym returns the name of type t.
   261  func (t *Type) Sym() *Sym {
   262  	if t.obj != nil {
   263  		return t.obj.Sym()
   264  	}
   265  	return nil
   266  }
   267  
   268  // Underlying returns the underlying type of type t.
   269  func (t *Type) Underlying() *Type { return t.underlying }
   270  
   271  // Pos returns a position associated with t, if any.
   272  // This should only be used for diagnostics.
   273  func (t *Type) Pos() src.XPos {
   274  	if t.obj != nil {
   275  		return t.obj.Pos()
   276  	}
   277  	return src.NoXPos
   278  }
   279  
   280  // Map contains Type fields specific to maps.
   281  type Map struct {
   282  	Key  *Type // Key type
   283  	Elem *Type // Val (elem) type
   284  
   285  	Group *Type // internal struct type representing a slot group
   286  }
   287  
   288  // MapType returns t's extra map-specific fields.
   289  func (t *Type) MapType() *Map {
   290  	t.wantEtype(TMAP)
   291  	return t.extra.(*Map)
   292  }
   293  
   294  // Forward contains Type fields specific to forward types.
   295  type Forward struct {
   296  	Copyto      []*Type  // where to copy the eventual value to
   297  	Embedlineno src.XPos // first use of this type as an embedded type
   298  }
   299  
   300  // forwardType returns t's extra forward-type-specific fields.
   301  func (t *Type) forwardType() *Forward {
   302  	t.wantEtype(TFORW)
   303  	return t.extra.(*Forward)
   304  }
   305  
   306  // Func contains Type fields specific to func types.
   307  type Func struct {
   308  	allParams []*Field // slice of all parameters, in receiver/params/results order
   309  
   310  	startParams  int // index of the start of the (regular) parameters section
   311  	startResults int // index of the start of the results section
   312  
   313  	resultsTuple *Type // struct-like type representing multi-value results
   314  
   315  	// Argwid is the total width of the function receiver, params, and results.
   316  	// It gets calculated via a temporary TFUNCARGS type.
   317  	// Note that TFUNC's Width is Widthptr.
   318  	Argwid int64
   319  }
   320  
   321  func (ft *Func) recvs() []*Field         { return ft.allParams[:ft.startParams] }
   322  func (ft *Func) params() []*Field        { return ft.allParams[ft.startParams:ft.startResults] }
   323  func (ft *Func) results() []*Field       { return ft.allParams[ft.startResults:] }
   324  func (ft *Func) recvParams() []*Field    { return ft.allParams[:ft.startResults] }
   325  func (ft *Func) paramsResults() []*Field { return ft.allParams[ft.startParams:] }
   326  
   327  // funcType returns t's extra func-specific fields.
   328  func (t *Type) funcType() *Func {
   329  	t.wantEtype(TFUNC)
   330  	return t.extra.(*Func)
   331  }
   332  
   333  // Struct contains Type fields specific to struct types.
   334  type Struct struct {
   335  	fields fields
   336  
   337  	// Maps have three associated internal structs (see struct MapType).
   338  	// Map links such structs back to their map type.
   339  	Map *Type
   340  
   341  	ParamTuple bool // whether this struct is actually a tuple of signature parameters
   342  }
   343  
   344  // StructType returns t's extra struct-specific fields.
   345  func (t *Type) StructType() *Struct {
   346  	t.wantEtype(TSTRUCT)
   347  	return t.extra.(*Struct)
   348  }
   349  
   350  // Interface contains Type fields specific to interface types.
   351  type Interface struct {
   352  }
   353  
   354  // Ptr contains Type fields specific to pointer types.
   355  type Ptr struct {
   356  	Elem *Type // element type
   357  }
   358  
   359  // ChanArgs contains Type fields specific to TCHANARGS types.
   360  type ChanArgs struct {
   361  	T *Type // reference to a chan type whose elements need a width check
   362  }
   363  
   364  // FuncArgs contains Type fields specific to TFUNCARGS types.
   365  type FuncArgs struct {
   366  	T *Type // reference to a func type whose elements need a width check
   367  }
   368  
   369  // Chan contains Type fields specific to channel types.
   370  type Chan struct {
   371  	Elem *Type   // element type
   372  	Dir  ChanDir // channel direction
   373  }
   374  
   375  // chanType returns t's extra channel-specific fields.
   376  func (t *Type) chanType() *Chan {
   377  	t.wantEtype(TCHAN)
   378  	return t.extra.(*Chan)
   379  }
   380  
   381  type Tuple struct {
   382  	first  *Type
   383  	second *Type
   384  	// Any tuple with a memory type must put that memory type second.
   385  }
   386  
   387  // Results are the output from calls that will be late-expanded.
   388  type Results struct {
   389  	Types []*Type // Last element is memory output from call.
   390  }
   391  
   392  // Array contains Type fields specific to array types.
   393  type Array struct {
   394  	Elem  *Type // element type
   395  	Bound int64 // number of elements; <0 if unknown yet
   396  }
   397  
   398  // Slice contains Type fields specific to slice types.
   399  type Slice struct {
   400  	Elem *Type // element type
   401  }
   402  
   403  // A Field is a (Sym, Type) pairing along with some other information, and,
   404  // depending on the context, is used to represent:
   405  //   - a field in a struct
   406  //   - a method in an interface or associated with a named type
   407  //   - a function parameter
   408  type Field struct {
   409  	flags bitset8
   410  
   411  	Embedded uint8 // embedded field
   412  
   413  	Pos src.XPos
   414  
   415  	// Name of field/method/parameter. Can be nil for interface fields embedded
   416  	// in interfaces and unnamed parameters.
   417  	Sym  *Sym
   418  	Type *Type  // field type
   419  	Note string // literal string annotation
   420  
   421  	// For fields that represent function parameters, Nname points to the
   422  	// associated ONAME Node. For fields that represent methods, Nname points to
   423  	// the function name node.
   424  	Nname Object
   425  
   426  	// Offset in bytes of this field or method within its enclosing struct
   427  	// or interface Type. For parameters, this is BADWIDTH.
   428  	Offset int64
   429  }
   430  
   431  const (
   432  	fieldIsDDD = 1 << iota // field is ... argument
   433  	fieldNointerface
   434  )
   435  
   436  func (f *Field) IsDDD() bool       { return f.flags&fieldIsDDD != 0 }
   437  func (f *Field) Nointerface() bool { return f.flags&fieldNointerface != 0 }
   438  
   439  func (f *Field) SetIsDDD(b bool)       { f.flags.set(fieldIsDDD, b) }
   440  func (f *Field) SetNointerface(b bool) { f.flags.set(fieldNointerface, b) }
   441  
   442  // End returns the offset of the first byte immediately after this field.
   443  func (f *Field) End() int64 {
   444  	return f.Offset + f.Type.width
   445  }
   446  
   447  // IsMethod reports whether f represents a method rather than a struct field.
   448  func (f *Field) IsMethod() bool {
   449  	return f.Type.kind == TFUNC && f.Type.Recv() != nil
   450  }
   451  
   452  // CompareFields compares two Field values by name.
   453  func CompareFields(a, b *Field) int {
   454  	return CompareSyms(a.Sym, b.Sym)
   455  }
   456  
   457  // fields is a pointer to a slice of *Field.
   458  // This saves space in Types that do not have fields or methods
   459  // compared to a simple slice of *Field.
   460  type fields struct {
   461  	s *[]*Field
   462  }
   463  
   464  // Slice returns the entries in f as a slice.
   465  // Changes to the slice entries will be reflected in f.
   466  func (f *fields) Slice() []*Field {
   467  	if f.s == nil {
   468  		return nil
   469  	}
   470  	return *f.s
   471  }
   472  
   473  // Set sets f to a slice.
   474  // This takes ownership of the slice.
   475  func (f *fields) Set(s []*Field) {
   476  	if len(s) == 0 {
   477  		f.s = nil
   478  	} else {
   479  		// Copy s and take address of t rather than s to avoid
   480  		// allocation in the case where len(s) == 0.
   481  		t := s
   482  		f.s = &t
   483  	}
   484  }
   485  
   486  // newType returns a new Type of the specified kind.
   487  func newType(et Kind) *Type {
   488  	t := &Type{
   489  		kind:  et,
   490  		width: BADWIDTH,
   491  	}
   492  	t.underlying = t
   493  	// TODO(josharian): lazily initialize some of these?
   494  	switch t.kind {
   495  	case TMAP:
   496  		t.extra = new(Map)
   497  	case TFORW:
   498  		t.extra = new(Forward)
   499  	case TFUNC:
   500  		t.extra = new(Func)
   501  	case TSTRUCT:
   502  		t.extra = new(Struct)
   503  	case TINTER:
   504  		t.extra = new(Interface)
   505  	case TPTR:
   506  		t.extra = Ptr{}
   507  	case TCHANARGS:
   508  		t.extra = ChanArgs{}
   509  	case TFUNCARGS:
   510  		t.extra = FuncArgs{}
   511  	case TCHAN:
   512  		t.extra = new(Chan)
   513  	case TTUPLE:
   514  		t.extra = new(Tuple)
   515  	case TRESULTS:
   516  		t.extra = new(Results)
   517  	}
   518  	return t
   519  }
   520  
   521  // NewArray returns a new fixed-length array Type.
   522  func NewArray(elem *Type, bound int64) *Type {
   523  	if bound < 0 {
   524  		base.Fatalf("NewArray: invalid bound %v", bound)
   525  	}
   526  	t := newType(TARRAY)
   527  	t.extra = &Array{Elem: elem, Bound: bound}
   528  	if elem.HasShape() {
   529  		t.SetHasShape(true)
   530  	}
   531  	if elem.NotInHeap() {
   532  		t.SetNotInHeap(true)
   533  	}
   534  	return t
   535  }
   536  
   537  // NewSlice returns the slice Type with element type elem.
   538  func NewSlice(elem *Type) *Type {
   539  	if t := elem.cache.slice; t != nil {
   540  		if t.Elem() != elem {
   541  			base.Fatalf("elem mismatch")
   542  		}
   543  		if elem.HasShape() != t.HasShape() {
   544  			base.Fatalf("Incorrect HasShape flag for cached slice type")
   545  		}
   546  		return t
   547  	}
   548  
   549  	t := newType(TSLICE)
   550  	t.extra = Slice{Elem: elem}
   551  	elem.cache.slice = t
   552  	if elem.HasShape() {
   553  		t.SetHasShape(true)
   554  	}
   555  	return t
   556  }
   557  
   558  // NewChan returns a new chan Type with direction dir.
   559  func NewChan(elem *Type, dir ChanDir) *Type {
   560  	t := newType(TCHAN)
   561  	ct := t.chanType()
   562  	ct.Elem = elem
   563  	ct.Dir = dir
   564  	if elem.HasShape() {
   565  		t.SetHasShape(true)
   566  	}
   567  	return t
   568  }
   569  
   570  func NewTuple(t1, t2 *Type) *Type {
   571  	t := newType(TTUPLE)
   572  	t.extra.(*Tuple).first = t1
   573  	t.extra.(*Tuple).second = t2
   574  	if t1.HasShape() || t2.HasShape() {
   575  		t.SetHasShape(true)
   576  	}
   577  	return t
   578  }
   579  
   580  func newResults(types []*Type) *Type {
   581  	t := newType(TRESULTS)
   582  	t.extra.(*Results).Types = types
   583  	return t
   584  }
   585  
   586  func NewResults(types []*Type) *Type {
   587  	if len(types) == 1 && types[0] == TypeMem {
   588  		return TypeResultMem
   589  	}
   590  	return newResults(types)
   591  }
   592  
   593  func newSSA(name string) *Type {
   594  	t := newType(TSSA)
   595  	t.extra = name
   596  	return t
   597  }
   598  
   599  func newSIMD(name string) *Type {
   600  	t := newSSA(name)
   601  	t.flags |= typeIsSIMD
   602  	return t
   603  }
   604  
   605  // NewMap returns a new map Type with key type k and element (aka value) type v.
   606  func NewMap(k, v *Type) *Type {
   607  	t := newType(TMAP)
   608  	mt := t.MapType()
   609  	mt.Key = k
   610  	mt.Elem = v
   611  	if k.HasShape() || v.HasShape() {
   612  		t.SetHasShape(true)
   613  	}
   614  	return t
   615  }
   616  
   617  // NewPtrCacheEnabled controls whether *T Types are cached in T.
   618  // Caching is disabled just before starting the backend.
   619  // This allows the backend to run concurrently.
   620  var NewPtrCacheEnabled = true
   621  
   622  // NewPtr returns the pointer type pointing to t.
   623  func NewPtr(elem *Type) *Type {
   624  	if elem == nil {
   625  		base.Fatalf("NewPtr: pointer to elem Type is nil")
   626  	}
   627  
   628  	if t := elem.cache.ptr; t != nil {
   629  		if t.Elem() != elem {
   630  			base.Fatalf("NewPtr: elem mismatch")
   631  		}
   632  		if elem.HasShape() != t.HasShape() {
   633  			base.Fatalf("Incorrect HasShape flag for cached pointer type")
   634  		}
   635  		return t
   636  	}
   637  
   638  	t := newType(TPTR)
   639  	t.extra = Ptr{Elem: elem}
   640  	t.width = int64(PtrSize)
   641  	t.align = uint8(PtrSize)
   642  	t.intRegs = 1
   643  	if NewPtrCacheEnabled {
   644  		elem.cache.ptr = t
   645  	}
   646  	if elem.HasShape() {
   647  		t.SetHasShape(true)
   648  	}
   649  	t.alg = AMEM
   650  	if elem.Noalg() {
   651  		t.SetNoalg(true)
   652  		t.alg = ANOALG
   653  	}
   654  	// Note: we can't check elem.NotInHeap here because it might
   655  	// not be set yet. See size.go:PtrDataSize.
   656  	t.ptrBytes = int64(PtrSize)
   657  	return t
   658  }
   659  
   660  // NewChanArgs returns a new TCHANARGS type for channel type c.
   661  func NewChanArgs(c *Type) *Type {
   662  	t := newType(TCHANARGS)
   663  	t.extra = ChanArgs{T: c}
   664  	return t
   665  }
   666  
   667  // NewFuncArgs returns a new TFUNCARGS type for func type f.
   668  func NewFuncArgs(f *Type) *Type {
   669  	t := newType(TFUNCARGS)
   670  	t.extra = FuncArgs{T: f}
   671  	return t
   672  }
   673  
   674  func NewField(pos src.XPos, sym *Sym, typ *Type) *Field {
   675  	f := &Field{
   676  		Pos:    pos,
   677  		Sym:    sym,
   678  		Type:   typ,
   679  		Offset: BADWIDTH,
   680  	}
   681  	if typ == nil {
   682  		base.Fatalf("typ is nil")
   683  	}
   684  	return f
   685  }
   686  
   687  // SubstAny walks t, replacing instances of "any" with successive
   688  // elements removed from types.  It returns the substituted type.
   689  func SubstAny(t *Type, types *[]*Type) *Type {
   690  	if t == nil {
   691  		return nil
   692  	}
   693  
   694  	switch t.kind {
   695  	default:
   696  		// Leave the type unchanged.
   697  
   698  	case TANY:
   699  		if len(*types) == 0 {
   700  			base.Fatalf("SubstArgTypes: not enough argument types")
   701  		}
   702  		t = (*types)[0]
   703  		*types = (*types)[1:]
   704  
   705  	case TPTR:
   706  		elem := SubstAny(t.Elem(), types)
   707  		if elem != t.Elem() {
   708  			t = t.copy()
   709  			t.extra = Ptr{Elem: elem}
   710  		}
   711  
   712  	case TARRAY:
   713  		elem := SubstAny(t.Elem(), types)
   714  		if elem != t.Elem() {
   715  			t = t.copy()
   716  			t.extra.(*Array).Elem = elem
   717  		}
   718  
   719  	case TSLICE:
   720  		elem := SubstAny(t.Elem(), types)
   721  		if elem != t.Elem() {
   722  			t = t.copy()
   723  			t.extra = Slice{Elem: elem}
   724  		}
   725  
   726  	case TCHAN:
   727  		elem := SubstAny(t.Elem(), types)
   728  		if elem != t.Elem() {
   729  			t = t.copy()
   730  			t.extra.(*Chan).Elem = elem
   731  		}
   732  
   733  	case TMAP:
   734  		key := SubstAny(t.Key(), types)
   735  		elem := SubstAny(t.Elem(), types)
   736  		if key != t.Key() || elem != t.Elem() {
   737  			t = t.copy()
   738  			t.extra.(*Map).Key = key
   739  			t.extra.(*Map).Elem = elem
   740  		}
   741  
   742  	case TFUNC:
   743  		ft := t.funcType()
   744  		allParams := substFields(ft.allParams, types)
   745  
   746  		t = t.copy()
   747  		ft = t.funcType()
   748  		ft.allParams = allParams
   749  
   750  		rt := ft.resultsTuple
   751  		rt = rt.copy()
   752  		ft.resultsTuple = rt
   753  		rt.setFields(t.Results())
   754  
   755  	case TSTRUCT:
   756  		// Make a copy of all fields, including ones whose type does not change.
   757  		// This prevents aliasing across functions, which can lead to later
   758  		// fields getting their Offset incorrectly overwritten.
   759  		nfs := substFields(t.Fields(), types)
   760  		t = t.copy()
   761  		t.setFields(nfs)
   762  	}
   763  
   764  	return t
   765  }
   766  
   767  func substFields(fields []*Field, types *[]*Type) []*Field {
   768  	nfs := make([]*Field, len(fields))
   769  	for i, f := range fields {
   770  		nft := SubstAny(f.Type, types)
   771  		nfs[i] = f.Copy()
   772  		nfs[i].Type = nft
   773  	}
   774  	return nfs
   775  }
   776  
   777  // copy returns a shallow copy of the Type.
   778  func (t *Type) copy() *Type {
   779  	if t == nil {
   780  		return nil
   781  	}
   782  	nt := *t
   783  	// copy any *T Extra fields, to avoid aliasing
   784  	switch t.kind {
   785  	case TMAP:
   786  		x := *t.extra.(*Map)
   787  		nt.extra = &x
   788  	case TFORW:
   789  		x := *t.extra.(*Forward)
   790  		nt.extra = &x
   791  	case TFUNC:
   792  		x := *t.extra.(*Func)
   793  		nt.extra = &x
   794  	case TSTRUCT:
   795  		x := *t.extra.(*Struct)
   796  		nt.extra = &x
   797  	case TINTER:
   798  		x := *t.extra.(*Interface)
   799  		nt.extra = &x
   800  	case TCHAN:
   801  		x := *t.extra.(*Chan)
   802  		nt.extra = &x
   803  	case TARRAY:
   804  		x := *t.extra.(*Array)
   805  		nt.extra = &x
   806  	case TTUPLE, TSSA, TRESULTS:
   807  		base.Fatalf("ssa types cannot be copied")
   808  	}
   809  	// TODO(mdempsky): Find out why this is necessary and explain.
   810  	if t.underlying == t {
   811  		nt.underlying = &nt
   812  	}
   813  	return &nt
   814  }
   815  
   816  func (f *Field) Copy() *Field {
   817  	nf := *f
   818  	return &nf
   819  }
   820  
   821  func (t *Type) wantEtype(et Kind) {
   822  	if t.kind != et {
   823  		base.Fatalf("want %v, but have %v", et, t)
   824  	}
   825  }
   826  
   827  // ResultsTuple returns the result type of signature type t as a tuple.
   828  // This can be used as the type of multi-valued call expressions.
   829  func (t *Type) ResultsTuple() *Type { return t.funcType().resultsTuple }
   830  
   831  // Recvs returns a slice of receiver parameters of signature type t.
   832  // The returned slice always has length 0 or 1.
   833  func (t *Type) Recvs() []*Field { return t.funcType().recvs() }
   834  
   835  // Params returns a slice of regular parameters of signature type t.
   836  func (t *Type) Params() []*Field { return t.funcType().params() }
   837  
   838  // Results returns a slice of result parameters of signature type t.
   839  func (t *Type) Results() []*Field { return t.funcType().results() }
   840  
   841  // RecvParamsResults returns a slice containing all of the
   842  // signature's parameters in receiver (if any), (normal) parameters,
   843  // and then results.
   844  func (t *Type) RecvParamsResults() []*Field { return t.funcType().allParams }
   845  
   846  // RecvParams returns a slice containing the signature's receiver (if
   847  // any) followed by its (normal) parameters.
   848  func (t *Type) RecvParams() []*Field { return t.funcType().recvParams() }
   849  
   850  // ParamsResults returns a slice containing the signature's (normal)
   851  // parameters followed by its results.
   852  func (t *Type) ParamsResults() []*Field { return t.funcType().paramsResults() }
   853  
   854  func (t *Type) NumRecvs() int   { return len(t.Recvs()) }
   855  func (t *Type) NumParams() int  { return len(t.Params()) }
   856  func (t *Type) NumResults() int { return len(t.Results()) }
   857  
   858  // IsVariadic reports whether function type t is variadic.
   859  func (t *Type) IsVariadic() bool {
   860  	n := t.NumParams()
   861  	return n > 0 && t.Param(n-1).IsDDD()
   862  }
   863  
   864  // Recv returns the receiver of function type t, if any.
   865  func (t *Type) Recv() *Field {
   866  	if s := t.Recvs(); len(s) == 1 {
   867  		return s[0]
   868  	}
   869  	return nil
   870  }
   871  
   872  // Param returns the i'th parameter of signature type t.
   873  func (t *Type) Param(i int) *Field { return t.Params()[i] }
   874  
   875  // Result returns the i'th result of signature type t.
   876  func (t *Type) Result(i int) *Field { return t.Results()[i] }
   877  
   878  // Key returns the key type of map type t.
   879  func (t *Type) Key() *Type {
   880  	t.wantEtype(TMAP)
   881  	return t.extra.(*Map).Key
   882  }
   883  
   884  // Elem returns the type of elements of t.
   885  // Usable with pointers, channels, arrays, slices, and maps.
   886  func (t *Type) Elem() *Type {
   887  	switch t.kind {
   888  	case TPTR:
   889  		return t.extra.(Ptr).Elem
   890  	case TARRAY:
   891  		return t.extra.(*Array).Elem
   892  	case TSLICE:
   893  		return t.extra.(Slice).Elem
   894  	case TCHAN:
   895  		return t.extra.(*Chan).Elem
   896  	case TMAP:
   897  		return t.extra.(*Map).Elem
   898  	}
   899  	base.Fatalf("Type.Elem %s", t.kind)
   900  	return nil
   901  }
   902  
   903  // ChanArgs returns the channel type for TCHANARGS type t.
   904  func (t *Type) ChanArgs() *Type {
   905  	t.wantEtype(TCHANARGS)
   906  	return t.extra.(ChanArgs).T
   907  }
   908  
   909  // FuncArgs returns the func type for TFUNCARGS type t.
   910  func (t *Type) FuncArgs() *Type {
   911  	t.wantEtype(TFUNCARGS)
   912  	return t.extra.(FuncArgs).T
   913  }
   914  
   915  // IsFuncArgStruct reports whether t is a struct representing function parameters or results.
   916  func (t *Type) IsFuncArgStruct() bool {
   917  	return t.kind == TSTRUCT && t.extra.(*Struct).ParamTuple
   918  }
   919  
   920  // Methods returns a pointer to the base methods (excluding embedding) for type t.
   921  // These can either be concrete methods (for non-interface types) or interface
   922  // methods (for interface types).
   923  func (t *Type) Methods() []*Field {
   924  	return t.methods.Slice()
   925  }
   926  
   927  // AllMethods returns a pointer to all the methods (including embedding) for type t.
   928  // For an interface type, this is the set of methods that are typically iterated
   929  // over. For non-interface types, AllMethods() only returns a valid result after
   930  // CalcMethods() has been called at least once.
   931  func (t *Type) AllMethods() []*Field {
   932  	if t.kind == TINTER {
   933  		// Calculate the full method set of an interface type on the fly
   934  		// now, if not done yet.
   935  		CalcSize(t)
   936  	}
   937  	return t.allMethods.Slice()
   938  }
   939  
   940  // SetMethods sets the direct method set for type t (i.e., *not*
   941  // including promoted methods from embedded types).
   942  func (t *Type) SetMethods(fs []*Field) {
   943  	t.methods.Set(fs)
   944  }
   945  
   946  // SetAllMethods sets the set of all methods for type t (i.e.,
   947  // including promoted methods from embedded types).
   948  func (t *Type) SetAllMethods(fs []*Field) {
   949  	t.allMethods.Set(fs)
   950  }
   951  
   952  // fields returns the fields of struct type t.
   953  func (t *Type) fields() *fields {
   954  	t.wantEtype(TSTRUCT)
   955  	return &t.extra.(*Struct).fields
   956  }
   957  
   958  // Field returns the i'th field of struct type t.
   959  func (t *Type) Field(i int) *Field { return t.Fields()[i] }
   960  
   961  // Fields returns a slice of containing all fields of
   962  // a struct type t.
   963  func (t *Type) Fields() []*Field { return t.fields().Slice() }
   964  
   965  // setFields sets struct type t's fields to fields.
   966  func (t *Type) setFields(fields []*Field) {
   967  	// If we've calculated the width of t before,
   968  	// then some other type such as a function signature
   969  	// might now have the wrong type.
   970  	// Rather than try to track and invalidate those,
   971  	// enforce that SetFields cannot be called once
   972  	// t's width has been calculated.
   973  	if t.widthCalculated() {
   974  		base.Fatalf("SetFields of %v: width previously calculated", t)
   975  	}
   976  	t.wantEtype(TSTRUCT)
   977  	t.fields().Set(fields)
   978  }
   979  
   980  // SetInterface sets the base methods of an interface type t.
   981  func (t *Type) SetInterface(methods []*Field) {
   982  	t.wantEtype(TINTER)
   983  	t.methods.Set(methods)
   984  }
   985  
   986  // ArgWidth returns the total aligned argument size for a function.
   987  // It includes the receiver, parameters, and results.
   988  func (t *Type) ArgWidth() int64 {
   989  	t.wantEtype(TFUNC)
   990  	return t.extra.(*Func).Argwid
   991  }
   992  
   993  // Size returns the width of t in bytes.
   994  func (t *Type) Size() int64 {
   995  	if t.kind == TSSA {
   996  		return t.width
   997  	}
   998  	CalcSize(t)
   999  	return t.width
  1000  }
  1001  
  1002  // Alignment returns the alignment of t in bytes.
  1003  func (t *Type) Alignment() int64 {
  1004  	CalcSize(t)
  1005  	return int64(t.align)
  1006  }
  1007  
  1008  func (t *Type) SimpleString() string {
  1009  	return t.kind.String()
  1010  }
  1011  
  1012  // Cmp is a comparison between values a and b.
  1013  //
  1014  //	-1 if a < b
  1015  //	 0 if a == b
  1016  //	 1 if a > b
  1017  type Cmp int8
  1018  
  1019  const (
  1020  	CMPlt = Cmp(-1)
  1021  	CMPeq = Cmp(0)
  1022  	CMPgt = Cmp(1)
  1023  )
  1024  
  1025  // Compare compares types for purposes of the SSA back
  1026  // end, returning a Cmp (one of CMPlt, CMPeq, CMPgt).
  1027  // The answers are correct for an optimizer
  1028  // or code generator, but not necessarily typechecking.
  1029  // The order chosen is arbitrary, only consistency and division
  1030  // into equivalence classes (Types that compare CMPeq) matters.
  1031  func (t *Type) Compare(x *Type) Cmp {
  1032  	if x == t {
  1033  		return CMPeq
  1034  	}
  1035  	return t.cmp(x)
  1036  }
  1037  
  1038  func cmpForNe(x bool) Cmp {
  1039  	if x {
  1040  		return CMPlt
  1041  	}
  1042  	return CMPgt
  1043  }
  1044  
  1045  func (r *Sym) cmpsym(s *Sym) Cmp {
  1046  	if r == s {
  1047  		return CMPeq
  1048  	}
  1049  	if r == nil {
  1050  		return CMPlt
  1051  	}
  1052  	if s == nil {
  1053  		return CMPgt
  1054  	}
  1055  	// Fast sort, not pretty sort
  1056  	if len(r.Name) != len(s.Name) {
  1057  		return cmpForNe(len(r.Name) < len(s.Name))
  1058  	}
  1059  	if r.Pkg != s.Pkg {
  1060  		if len(r.Pkg.Prefix) != len(s.Pkg.Prefix) {
  1061  			return cmpForNe(len(r.Pkg.Prefix) < len(s.Pkg.Prefix))
  1062  		}
  1063  		if r.Pkg.Prefix != s.Pkg.Prefix {
  1064  			return cmpForNe(r.Pkg.Prefix < s.Pkg.Prefix)
  1065  		}
  1066  	}
  1067  	if r.Name != s.Name {
  1068  		return cmpForNe(r.Name < s.Name)
  1069  	}
  1070  	return CMPeq
  1071  }
  1072  
  1073  // cmp compares two *Types t and x, returning CMPlt,
  1074  // CMPeq, CMPgt as t<x, t==x, t>x, for an arbitrary
  1075  // and optimizer-centric notion of comparison.
  1076  // TODO(josharian): make this safe for recursive interface types
  1077  // and use in signatlist sorting. See issue 19869.
  1078  func (t *Type) cmp(x *Type) Cmp {
  1079  	// This follows the structure of function identical in identity.go
  1080  	// with two exceptions.
  1081  	// 1. Symbols are compared more carefully because a <,=,> result is desired.
  1082  	// 2. Maps are treated specially to avoid endless recursion -- maps
  1083  	//    contain an internal data type not expressible in Go source code.
  1084  	if t == x {
  1085  		return CMPeq
  1086  	}
  1087  	if t == nil {
  1088  		return CMPlt
  1089  	}
  1090  	if x == nil {
  1091  		return CMPgt
  1092  	}
  1093  
  1094  	if t.kind != x.kind {
  1095  		return cmpForNe(t.kind < x.kind)
  1096  	}
  1097  
  1098  	if t.obj != nil || x.obj != nil {
  1099  		// Special case: we keep byte and uint8 separate
  1100  		// for error messages. Treat them as equal.
  1101  		switch t.kind {
  1102  		case TUINT8:
  1103  			if (t == Types[TUINT8] || t == ByteType) && (x == Types[TUINT8] || x == ByteType) {
  1104  				return CMPeq
  1105  			}
  1106  
  1107  		case TINT32:
  1108  			if (t == Types[RuneType.kind] || t == RuneType) && (x == Types[RuneType.kind] || x == RuneType) {
  1109  				return CMPeq
  1110  			}
  1111  
  1112  		case TINTER:
  1113  			// Make sure named any type matches any empty interface.
  1114  			if t == AnyType && x.IsEmptyInterface() || x == AnyType && t.IsEmptyInterface() {
  1115  				return CMPeq
  1116  			}
  1117  		}
  1118  	}
  1119  
  1120  	if c := t.Sym().cmpsym(x.Sym()); c != CMPeq {
  1121  		return c
  1122  	}
  1123  
  1124  	if x.obj != nil {
  1125  		return CMPeq
  1126  	}
  1127  	// both syms nil, look at structure below.
  1128  
  1129  	switch t.kind {
  1130  	case TBOOL, TFLOAT32, TFLOAT64, TCOMPLEX64, TCOMPLEX128, TUNSAFEPTR, TUINTPTR,
  1131  		TINT8, TINT16, TINT32, TINT64, TINT, TUINT8, TUINT16, TUINT32, TUINT64, TUINT:
  1132  		return CMPeq
  1133  
  1134  	case TSSA:
  1135  		tname := t.extra.(string)
  1136  		xname := x.extra.(string)
  1137  		// desire fast sorting, not pretty sorting.
  1138  		if len(tname) == len(xname) {
  1139  			if tname == xname {
  1140  				return CMPeq
  1141  			}
  1142  			if tname < xname {
  1143  				return CMPlt
  1144  			}
  1145  			return CMPgt
  1146  		}
  1147  		if len(tname) > len(xname) {
  1148  			return CMPgt
  1149  		}
  1150  		return CMPlt
  1151  
  1152  	case TTUPLE:
  1153  		xtup := x.extra.(*Tuple)
  1154  		ttup := t.extra.(*Tuple)
  1155  		if c := ttup.first.Compare(xtup.first); c != CMPeq {
  1156  			return c
  1157  		}
  1158  		return ttup.second.Compare(xtup.second)
  1159  
  1160  	case TRESULTS:
  1161  		xResults := x.extra.(*Results)
  1162  		tResults := t.extra.(*Results)
  1163  		xl, tl := len(xResults.Types), len(tResults.Types)
  1164  		if tl != xl {
  1165  			if tl < xl {
  1166  				return CMPlt
  1167  			}
  1168  			return CMPgt
  1169  		}
  1170  		for i := 0; i < tl; i++ {
  1171  			if c := tResults.Types[i].Compare(xResults.Types[i]); c != CMPeq {
  1172  				return c
  1173  			}
  1174  		}
  1175  		return CMPeq
  1176  
  1177  	case TMAP:
  1178  		if c := t.Key().cmp(x.Key()); c != CMPeq {
  1179  			return c
  1180  		}
  1181  		return t.Elem().cmp(x.Elem())
  1182  
  1183  	case TPTR, TSLICE:
  1184  		// No special cases for these, they are handled
  1185  		// by the general code after the switch.
  1186  
  1187  	case TSTRUCT:
  1188  		// Is this a map group type?
  1189  		if t.StructType().Map == nil {
  1190  			if x.StructType().Map != nil {
  1191  				return CMPlt // nil < non-nil
  1192  			}
  1193  			// to the general case
  1194  		} else if x.StructType().Map == nil {
  1195  			return CMPgt // nil > non-nil
  1196  		}
  1197  		// Both have non-nil Map, fallthrough to the general
  1198  		// case. Note that the map type does not directly refer
  1199  		// to the group type (it uses unsafe.Pointer). If it
  1200  		// did, this would need special handling to avoid
  1201  		// infinite recursion.
  1202  
  1203  		tfs := t.Fields()
  1204  		xfs := x.Fields()
  1205  		for i := 0; i < len(tfs) && i < len(xfs); i++ {
  1206  			t1, x1 := tfs[i], xfs[i]
  1207  			if t1.Embedded != x1.Embedded {
  1208  				return cmpForNe(t1.Embedded < x1.Embedded)
  1209  			}
  1210  			if t1.Note != x1.Note {
  1211  				return cmpForNe(t1.Note < x1.Note)
  1212  			}
  1213  			if c := t1.Sym.cmpsym(x1.Sym); c != CMPeq {
  1214  				return c
  1215  			}
  1216  			if c := t1.Type.cmp(x1.Type); c != CMPeq {
  1217  				return c
  1218  			}
  1219  		}
  1220  		if len(tfs) != len(xfs) {
  1221  			return cmpForNe(len(tfs) < len(xfs))
  1222  		}
  1223  		return CMPeq
  1224  
  1225  	case TINTER:
  1226  		tfs := t.AllMethods()
  1227  		xfs := x.AllMethods()
  1228  		for i := 0; i < len(tfs) && i < len(xfs); i++ {
  1229  			t1, x1 := tfs[i], xfs[i]
  1230  			if c := t1.Sym.cmpsym(x1.Sym); c != CMPeq {
  1231  				return c
  1232  			}
  1233  			if c := t1.Type.cmp(x1.Type); c != CMPeq {
  1234  				return c
  1235  			}
  1236  		}
  1237  		if len(tfs) != len(xfs) {
  1238  			return cmpForNe(len(tfs) < len(xfs))
  1239  		}
  1240  		return CMPeq
  1241  
  1242  	case TFUNC:
  1243  		if tn, xn := t.NumRecvs(), x.NumRecvs(); tn != xn {
  1244  			return cmpForNe(tn < xn)
  1245  		}
  1246  		if tn, xn := t.NumParams(), x.NumParams(); tn != xn {
  1247  			return cmpForNe(tn < xn)
  1248  		}
  1249  		if tn, xn := t.NumResults(), x.NumResults(); tn != xn {
  1250  			return cmpForNe(tn < xn)
  1251  		}
  1252  		if tv, xv := t.IsVariadic(), x.IsVariadic(); tv != xv {
  1253  			return cmpForNe(!tv)
  1254  		}
  1255  
  1256  		tfs := t.RecvParamsResults()
  1257  		xfs := x.RecvParamsResults()
  1258  		for i, tf := range tfs {
  1259  			if c := tf.Type.cmp(xfs[i].Type); c != CMPeq {
  1260  				return c
  1261  			}
  1262  		}
  1263  		return CMPeq
  1264  
  1265  	case TARRAY:
  1266  		if t.NumElem() != x.NumElem() {
  1267  			return cmpForNe(t.NumElem() < x.NumElem())
  1268  		}
  1269  
  1270  	case TCHAN:
  1271  		if t.ChanDir() != x.ChanDir() {
  1272  			return cmpForNe(t.ChanDir() < x.ChanDir())
  1273  		}
  1274  
  1275  	default:
  1276  		e := fmt.Sprintf("Do not know how to compare %v with %v", t, x)
  1277  		panic(e)
  1278  	}
  1279  
  1280  	// Common element type comparison for TARRAY, TCHAN, TPTR, and TSLICE.
  1281  	return t.Elem().cmp(x.Elem())
  1282  }
  1283  
  1284  // IsKind reports whether t is a Type of the specified kind.
  1285  func (t *Type) IsKind(et Kind) bool {
  1286  	return t != nil && t.kind == et
  1287  }
  1288  
  1289  func (t *Type) IsBoolean() bool {
  1290  	return t.kind == TBOOL
  1291  }
  1292  
  1293  var unsignedEType = [...]Kind{
  1294  	TINT8:    TUINT8,
  1295  	TUINT8:   TUINT8,
  1296  	TINT16:   TUINT16,
  1297  	TUINT16:  TUINT16,
  1298  	TINT32:   TUINT32,
  1299  	TUINT32:  TUINT32,
  1300  	TINT64:   TUINT64,
  1301  	TUINT64:  TUINT64,
  1302  	TINT:     TUINT,
  1303  	TUINT:    TUINT,
  1304  	TUINTPTR: TUINTPTR,
  1305  }
  1306  
  1307  // ToUnsigned returns the unsigned equivalent of integer type t.
  1308  func (t *Type) ToUnsigned() *Type {
  1309  	if !t.IsInteger() {
  1310  		base.Fatalf("unsignedType(%v)", t)
  1311  	}
  1312  	return Types[unsignedEType[t.kind]]
  1313  }
  1314  
  1315  func (t *Type) IsInteger() bool {
  1316  	switch t.kind {
  1317  	case TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64, TUINT64, TINT, TUINT, TUINTPTR:
  1318  		return true
  1319  	}
  1320  	return t == UntypedInt || t == UntypedRune
  1321  }
  1322  
  1323  func (t *Type) IsSigned() bool {
  1324  	switch t.kind {
  1325  	case TINT8, TINT16, TINT32, TINT64, TINT:
  1326  		return true
  1327  	}
  1328  	return false
  1329  }
  1330  
  1331  func (t *Type) IsUnsigned() bool {
  1332  	switch t.kind {
  1333  	case TUINT8, TUINT16, TUINT32, TUINT64, TUINT, TUINTPTR:
  1334  		return true
  1335  	}
  1336  	return false
  1337  }
  1338  
  1339  func (t *Type) IsFloat() bool {
  1340  	return t.kind == TFLOAT32 || t.kind == TFLOAT64 || t == UntypedFloat
  1341  }
  1342  
  1343  func (t *Type) IsComplex() bool {
  1344  	return t.kind == TCOMPLEX64 || t.kind == TCOMPLEX128 || t == UntypedComplex
  1345  }
  1346  
  1347  // IsPtr reports whether t is a regular Go pointer type.
  1348  // This does not include unsafe.Pointer.
  1349  func (t *Type) IsPtr() bool {
  1350  	return t.kind == TPTR
  1351  }
  1352  
  1353  // IsPtrElem reports whether t is the element of a pointer (to t).
  1354  func (t *Type) IsPtrElem() bool {
  1355  	return t.cache.ptr != nil
  1356  }
  1357  
  1358  // IsUnsafePtr reports whether t is an unsafe pointer.
  1359  func (t *Type) IsUnsafePtr() bool {
  1360  	return t.kind == TUNSAFEPTR
  1361  }
  1362  
  1363  // IsUintptr reports whether t is a uintptr.
  1364  func (t *Type) IsUintptr() bool {
  1365  	return t.kind == TUINTPTR
  1366  }
  1367  
  1368  // IsPtrShaped reports whether t is represented by a single machine pointer.
  1369  // In addition to regular Go pointer types, this includes map, channel, and
  1370  // function types and unsafe.Pointer. It does not include array or struct types
  1371  // that consist of a single pointer shaped type.
  1372  // TODO(mdempsky): Should it? See golang.org/issue/15028.
  1373  func (t *Type) IsPtrShaped() bool {
  1374  	return t.kind == TPTR || t.kind == TUNSAFEPTR ||
  1375  		t.kind == TMAP || t.kind == TCHAN || t.kind == TFUNC
  1376  }
  1377  
  1378  // HasNil reports whether the set of values determined by t includes nil.
  1379  func (t *Type) HasNil() bool {
  1380  	switch t.kind {
  1381  	case TCHAN, TFUNC, TINTER, TMAP, TNIL, TPTR, TSLICE, TUNSAFEPTR:
  1382  		return true
  1383  	}
  1384  	return false
  1385  }
  1386  
  1387  func (t *Type) IsString() bool {
  1388  	return t.kind == TSTRING
  1389  }
  1390  
  1391  func (t *Type) IsMap() bool {
  1392  	return t.kind == TMAP
  1393  }
  1394  
  1395  func (t *Type) IsChan() bool {
  1396  	return t.kind == TCHAN
  1397  }
  1398  
  1399  func (t *Type) IsSlice() bool {
  1400  	return t.kind == TSLICE
  1401  }
  1402  
  1403  func (t *Type) IsArray() bool {
  1404  	return t.kind == TARRAY
  1405  }
  1406  
  1407  func (t *Type) IsStruct() bool {
  1408  	return t.kind == TSTRUCT
  1409  }
  1410  
  1411  func (t *Type) IsInterface() bool {
  1412  	return t.kind == TINTER
  1413  }
  1414  
  1415  // IsEmptyInterface reports whether t is an empty interface type.
  1416  func (t *Type) IsEmptyInterface() bool {
  1417  	return t.IsInterface() && len(t.AllMethods()) == 0
  1418  }
  1419  
  1420  // IsScalar reports whether 't' is a scalar Go type, e.g.
  1421  // bool/int/float/complex. Note that struct and array types consisting
  1422  // of a single scalar element are not considered scalar, likewise
  1423  // pointer types are also not considered scalar.
  1424  func (t *Type) IsScalar() bool {
  1425  	switch t.kind {
  1426  	case TBOOL, TINT8, TUINT8, TINT16, TUINT16, TINT32,
  1427  		TUINT32, TINT64, TUINT64, TINT, TUINT,
  1428  		TUINTPTR, TCOMPLEX64, TCOMPLEX128, TFLOAT32, TFLOAT64:
  1429  		return true
  1430  	}
  1431  	return false
  1432  }
  1433  
  1434  func (t *Type) PtrTo() *Type {
  1435  	return NewPtr(t)
  1436  }
  1437  
  1438  func (t *Type) NumFields() int {
  1439  	if t.kind == TRESULTS {
  1440  		return len(t.extra.(*Results).Types)
  1441  	}
  1442  	return len(t.Fields())
  1443  }
  1444  func (t *Type) FieldType(i int) *Type {
  1445  	if t.kind == TTUPLE {
  1446  		switch i {
  1447  		case 0:
  1448  			return t.extra.(*Tuple).first
  1449  		case 1:
  1450  			return t.extra.(*Tuple).second
  1451  		default:
  1452  			panic("bad tuple index")
  1453  		}
  1454  	}
  1455  	if t.kind == TRESULTS {
  1456  		return t.extra.(*Results).Types[i]
  1457  	}
  1458  	return t.Field(i).Type
  1459  }
  1460  func (t *Type) FieldOff(i int) int64 {
  1461  	return t.Field(i).Offset
  1462  }
  1463  func (t *Type) FieldName(i int) string {
  1464  	return t.Field(i).Sym.Name
  1465  }
  1466  
  1467  // OffsetOf reports the offset of the field of a struct.
  1468  // The field is looked up by name.
  1469  func (t *Type) OffsetOf(name string) int64 {
  1470  	if t.kind != TSTRUCT {
  1471  		base.Fatalf("can't call OffsetOf on non-struct %v", t)
  1472  	}
  1473  	for _, f := range t.Fields() {
  1474  		if f.Sym.Name == name {
  1475  			return f.Offset
  1476  		}
  1477  	}
  1478  	base.Fatalf("couldn't find field %s in %v", name, t)
  1479  	return -1
  1480  }
  1481  
  1482  func (t *Type) NumElem() int64 {
  1483  	t.wantEtype(TARRAY)
  1484  	return t.extra.(*Array).Bound
  1485  }
  1486  
  1487  type componentsIncludeBlankFields bool
  1488  
  1489  const (
  1490  	IgnoreBlankFields componentsIncludeBlankFields = false
  1491  	CountBlankFields  componentsIncludeBlankFields = true
  1492  )
  1493  
  1494  // NumComponents returns the number of primitive elements that compose t.
  1495  // Struct and array types are flattened for the purpose of counting.
  1496  // All other types (including string, slice, and interface types) count as one element.
  1497  // If countBlank is IgnoreBlankFields, then blank struct fields
  1498  // (and their comprised elements) are excluded from the count.
  1499  // struct { x, y [3]int } has six components; [10]struct{ x, y string } has twenty.
  1500  func (t *Type) NumComponents(countBlank componentsIncludeBlankFields) int64 {
  1501  	switch t.kind {
  1502  	case TSTRUCT:
  1503  		if t.IsFuncArgStruct() {
  1504  			base.Fatalf("NumComponents func arg struct")
  1505  		}
  1506  		var n int64
  1507  		for _, f := range t.Fields() {
  1508  			if countBlank == IgnoreBlankFields && f.Sym.IsBlank() {
  1509  				continue
  1510  			}
  1511  			n += f.Type.NumComponents(countBlank)
  1512  		}
  1513  		return n
  1514  	case TARRAY:
  1515  		return t.NumElem() * t.Elem().NumComponents(countBlank)
  1516  	}
  1517  	return 1
  1518  }
  1519  
  1520  // SoleComponent returns the only primitive component in t,
  1521  // if there is exactly one. Otherwise, it returns nil.
  1522  // Components are counted as in NumComponents, including blank fields.
  1523  // Keep in sync with cmd/compile/internal/walk/convert.go:soleComponent.
  1524  func (t *Type) SoleComponent() *Type {
  1525  	switch t.kind {
  1526  	case TSTRUCT:
  1527  		if t.IsFuncArgStruct() {
  1528  			base.Fatalf("SoleComponent func arg struct")
  1529  		}
  1530  		if t.NumFields() != 1 {
  1531  			return nil
  1532  		}
  1533  		return t.Field(0).Type.SoleComponent()
  1534  	case TARRAY:
  1535  		if t.NumElem() != 1 {
  1536  			return nil
  1537  		}
  1538  		return t.Elem().SoleComponent()
  1539  	}
  1540  	return t
  1541  }
  1542  
  1543  // ChanDir returns the direction of a channel type t.
  1544  // The direction will be one of Crecv, Csend, or Cboth.
  1545  func (t *Type) ChanDir() ChanDir {
  1546  	t.wantEtype(TCHAN)
  1547  	return t.extra.(*Chan).Dir
  1548  }
  1549  
  1550  func (t *Type) IsMemory() bool {
  1551  	if t == TypeMem || t.kind == TTUPLE && t.extra.(*Tuple).second == TypeMem {
  1552  		return true
  1553  	}
  1554  	if t.kind == TRESULTS {
  1555  		if types := t.extra.(*Results).Types; len(types) > 0 && types[len(types)-1] == TypeMem {
  1556  			return true
  1557  		}
  1558  	}
  1559  	return false
  1560  }
  1561  func (t *Type) IsFlags() bool   { return t == TypeFlags }
  1562  func (t *Type) IsVoid() bool    { return t == TypeVoid }
  1563  func (t *Type) IsTuple() bool   { return t.kind == TTUPLE }
  1564  func (t *Type) IsResults() bool { return t.kind == TRESULTS }
  1565  
  1566  // IsUntyped reports whether t is an untyped type.
  1567  func (t *Type) IsUntyped() bool {
  1568  	if t == nil {
  1569  		return false
  1570  	}
  1571  	if t == UntypedString || t == UntypedBool {
  1572  		return true
  1573  	}
  1574  	switch t.kind {
  1575  	case TNIL, TIDEAL:
  1576  		return true
  1577  	}
  1578  	return false
  1579  }
  1580  
  1581  // HasPointers reports whether t contains a heap pointer.
  1582  // Note that this function ignores pointers to not-in-heap types.
  1583  func (t *Type) HasPointers() bool {
  1584  	return PtrDataSize(t) > 0
  1585  }
  1586  
  1587  var recvType *Type
  1588  
  1589  // FakeRecvType returns the singleton type used for interface method receivers.
  1590  func FakeRecvType() *Type {
  1591  	if recvType == nil {
  1592  		recvType = NewPtr(newType(TSTRUCT))
  1593  	}
  1594  	return recvType
  1595  }
  1596  
  1597  func FakeRecv() *Field {
  1598  	return NewField(base.AutogeneratedPos, nil, FakeRecvType())
  1599  }
  1600  
  1601  var (
  1602  	// TSSA types. HasPointers assumes these are pointer-free.
  1603  	TypeInvalid   = newSSA("invalid")
  1604  	TypeMem       = newSSA("mem")
  1605  	TypeFlags     = newSSA("flags")
  1606  	TypeVoid      = newSSA("void")
  1607  	TypeInt128    = newSSA("int128")
  1608  	TypeVec128    = newSIMD("vec128")
  1609  	TypeVec256    = newSIMD("vec256")
  1610  	TypeVec512    = newSIMD("vec512")
  1611  	TypeMask      = newSIMD("mask") // not a vector, not 100% sure what this should be.
  1612  	TypeResultMem = newResults([]*Type{TypeMem})
  1613  )
  1614  
  1615  func init() {
  1616  	TypeInt128.width = 16
  1617  	TypeInt128.align = 8
  1618  
  1619  	TypeVec128.width = 16
  1620  	TypeVec128.align = 8
  1621  	TypeVec256.width = 32
  1622  	TypeVec256.align = 8
  1623  	TypeVec512.width = 64
  1624  	TypeVec512.align = 8
  1625  
  1626  	TypeMask.width = 8 // This will depend on the architecture; spilling will be "interesting".
  1627  	TypeMask.align = 8
  1628  }
  1629  
  1630  // NewNamed returns a new named type for the given type name. obj should be an
  1631  // ir.Name. The new type is incomplete (marked as TFORW kind), and the underlying
  1632  // type should be set later via SetUnderlying(). References to the type are
  1633  // maintained until the type is filled in, so those references can be updated when
  1634  // the type is complete.
  1635  func NewNamed(obj Object) *Type {
  1636  	t := newType(TFORW)
  1637  	t.obj = obj
  1638  	sym := obj.Sym()
  1639  	if sym.Pkg == ShapePkg {
  1640  		t.SetIsShape(true)
  1641  		t.SetHasShape(true)
  1642  	}
  1643  	if sym.Pkg.Path == "internal/runtime/sys" && sym.Name == "nih" {
  1644  		// Recognize the special not-in-heap type. Any type including
  1645  		// this type will also be not-in-heap.
  1646  		// This logic is duplicated in go/types and
  1647  		// cmd/compile/internal/types2.
  1648  		t.SetNotInHeap(true)
  1649  	}
  1650  	return t
  1651  }
  1652  
  1653  // Obj returns the canonical type name node for a named type t, nil for an unnamed type.
  1654  func (t *Type) Obj() Object {
  1655  	return t.obj
  1656  }
  1657  
  1658  // SetUnderlying sets the underlying type of an incomplete type (i.e. type whose kind
  1659  // is currently TFORW). SetUnderlying automatically updates any types that were waiting
  1660  // for this type to be completed.
  1661  func (t *Type) SetUnderlying(underlying *Type) {
  1662  	if underlying.kind == TFORW {
  1663  		// This type isn't computed yet; when it is, update n.
  1664  		underlying.forwardType().Copyto = append(underlying.forwardType().Copyto, t)
  1665  		return
  1666  	}
  1667  
  1668  	ft := t.forwardType()
  1669  
  1670  	// TODO(mdempsky): Fix Type rekinding.
  1671  	t.kind = underlying.kind
  1672  	t.extra = underlying.extra
  1673  	t.width = underlying.width
  1674  	t.align = underlying.align
  1675  	t.alg = underlying.alg
  1676  	t.ptrBytes = underlying.ptrBytes
  1677  	t.intRegs = underlying.intRegs
  1678  	t.floatRegs = underlying.floatRegs
  1679  	t.underlying = underlying.underlying
  1680  
  1681  	if underlying.NotInHeap() {
  1682  		t.SetNotInHeap(true)
  1683  	}
  1684  	if underlying.HasShape() {
  1685  		t.SetHasShape(true)
  1686  	}
  1687  	if underlying.flags&typeIsSIMD != 0 {
  1688  		simdify(t, underlying.flags&typeIsSIMDTag != 0)
  1689  	}
  1690  
  1691  	// spec: "The declared type does not inherit any methods bound
  1692  	// to the existing type, but the method set of an interface
  1693  	// type [...] remains unchanged."
  1694  	if t.IsInterface() {
  1695  		t.methods = underlying.methods
  1696  		t.allMethods = underlying.allMethods
  1697  	}
  1698  
  1699  	// Update types waiting on this type.
  1700  	for _, w := range ft.Copyto {
  1701  		w.SetUnderlying(t)
  1702  	}
  1703  
  1704  	// Double-check use of type as embedded type.
  1705  	if ft.Embedlineno.IsKnown() {
  1706  		if t.IsPtr() || t.IsUnsafePtr() {
  1707  			base.ErrorfAt(ft.Embedlineno, errors.InvalidPtrEmbed, "embedded type cannot be a pointer")
  1708  		}
  1709  	}
  1710  }
  1711  
  1712  func fieldsHasShape(fields []*Field) bool {
  1713  	for _, f := range fields {
  1714  		if f.Type != nil && f.Type.HasShape() {
  1715  			return true
  1716  		}
  1717  	}
  1718  	return false
  1719  }
  1720  
  1721  // NewInterface returns a new interface for the given methods and
  1722  // embedded types. Embedded types are specified as fields with no Sym.
  1723  func NewInterface(methods []*Field) *Type {
  1724  	t := newType(TINTER)
  1725  	t.SetInterface(methods)
  1726  	for _, f := range methods {
  1727  		// f.Type could be nil for a broken interface declaration
  1728  		if f.Type != nil && f.Type.HasShape() {
  1729  			t.SetHasShape(true)
  1730  			break
  1731  		}
  1732  	}
  1733  	return t
  1734  }
  1735  
  1736  // NewSignature returns a new function type for the given receiver,
  1737  // parameters, and results, any of which may be nil.
  1738  func NewSignature(recv *Field, params, results []*Field) *Type {
  1739  	startParams := 0
  1740  	if recv != nil {
  1741  		startParams = 1
  1742  	}
  1743  	startResults := startParams + len(params)
  1744  
  1745  	allParams := make([]*Field, startResults+len(results))
  1746  	if recv != nil {
  1747  		allParams[0] = recv
  1748  	}
  1749  	copy(allParams[startParams:], params)
  1750  	copy(allParams[startResults:], results)
  1751  
  1752  	t := newType(TFUNC)
  1753  	ft := t.funcType()
  1754  
  1755  	funargs := func(fields []*Field) *Type {
  1756  		s := NewStruct(fields)
  1757  		s.StructType().ParamTuple = true
  1758  		return s
  1759  	}
  1760  
  1761  	ft.allParams = allParams
  1762  	ft.startParams = startParams
  1763  	ft.startResults = startResults
  1764  
  1765  	ft.resultsTuple = funargs(allParams[startResults:])
  1766  
  1767  	if fieldsHasShape(allParams) {
  1768  		t.SetHasShape(true)
  1769  	}
  1770  
  1771  	return t
  1772  }
  1773  
  1774  // NewStruct returns a new struct with the given fields.
  1775  func NewStruct(fields []*Field) *Type {
  1776  	t := newType(TSTRUCT)
  1777  	t.setFields(fields)
  1778  	if fieldsHasShape(fields) {
  1779  		t.SetHasShape(true)
  1780  	}
  1781  	for _, f := range fields {
  1782  		if f.Type.NotInHeap() {
  1783  			t.SetNotInHeap(true)
  1784  			break
  1785  		}
  1786  	}
  1787  
  1788  	return t
  1789  }
  1790  
  1791  var (
  1792  	IsInt     [NTYPE]bool
  1793  	IsFloat   [NTYPE]bool
  1794  	IsComplex [NTYPE]bool
  1795  	IsSimple  [NTYPE]bool
  1796  )
  1797  
  1798  var IsOrdered [NTYPE]bool
  1799  
  1800  // IsReflexive reports whether t has a reflexive equality operator.
  1801  // That is, if x==x for all x of type t.
  1802  func IsReflexive(t *Type) bool {
  1803  	switch t.Kind() {
  1804  	case TBOOL,
  1805  		TINT,
  1806  		TUINT,
  1807  		TINT8,
  1808  		TUINT8,
  1809  		TINT16,
  1810  		TUINT16,
  1811  		TINT32,
  1812  		TUINT32,
  1813  		TINT64,
  1814  		TUINT64,
  1815  		TUINTPTR,
  1816  		TPTR,
  1817  		TUNSAFEPTR,
  1818  		TSTRING,
  1819  		TCHAN:
  1820  		return true
  1821  
  1822  	case TFLOAT32,
  1823  		TFLOAT64,
  1824  		TCOMPLEX64,
  1825  		TCOMPLEX128,
  1826  		TINTER:
  1827  		return false
  1828  
  1829  	case TARRAY:
  1830  		return IsReflexive(t.Elem())
  1831  
  1832  	case TSTRUCT:
  1833  		for _, t1 := range t.Fields() {
  1834  			if !IsReflexive(t1.Type) {
  1835  				return false
  1836  			}
  1837  		}
  1838  		return true
  1839  
  1840  	default:
  1841  		base.Fatalf("bad type for map key: %v", t)
  1842  		return false
  1843  	}
  1844  }
  1845  
  1846  // Can this type be stored directly in an interface word?
  1847  // Yes, if the representation is a single pointer.
  1848  func IsDirectIface(t *Type) bool {
  1849  	return t.Size() == int64(PtrSize) && PtrDataSize(t) == int64(PtrSize)
  1850  }
  1851  
  1852  // IsInterfaceMethod reports whether (field) m is
  1853  // an interface method. Such methods have the
  1854  // special receiver type types.FakeRecvType().
  1855  func IsInterfaceMethod(f *Type) bool {
  1856  	return f.Recv().Type == FakeRecvType()
  1857  }
  1858  
  1859  // IsMethodApplicable reports whether method m can be called on a
  1860  // value of type t. This is necessary because we compute a single
  1861  // method set for both T and *T, but some *T methods are not
  1862  // applicable to T receivers.
  1863  func IsMethodApplicable(t *Type, m *Field) bool {
  1864  	return t.IsPtr() || !m.Type.Recv().Type.IsPtr() || IsInterfaceMethod(m.Type) || m.Embedded == 2
  1865  }
  1866  
  1867  // RuntimeSymName returns the name of s if it's in package "runtime"; otherwise
  1868  // it returns "".
  1869  func RuntimeSymName(s *Sym) string {
  1870  	if s.Pkg.Path == "runtime" {
  1871  		return s.Name
  1872  	}
  1873  	return ""
  1874  }
  1875  
  1876  // ReflectSymName returns the name of s if it's in package "reflect"; otherwise
  1877  // it returns "".
  1878  func ReflectSymName(s *Sym) string {
  1879  	if s.Pkg.Path == "reflect" {
  1880  		return s.Name
  1881  	}
  1882  	return ""
  1883  }
  1884  
  1885  // IsNoInstrumentPkg reports whether p is a package that
  1886  // should not be instrumented.
  1887  func IsNoInstrumentPkg(p *Pkg) bool {
  1888  	return objabi.LookupPkgSpecial(p.Path).NoInstrument
  1889  }
  1890  
  1891  // IsNoRacePkg reports whether p is a package that
  1892  // should not be race instrumented.
  1893  func IsNoRacePkg(p *Pkg) bool {
  1894  	return objabi.LookupPkgSpecial(p.Path).NoRaceFunc
  1895  }
  1896  
  1897  // IsRuntimePkg reports whether p is a runtime package.
  1898  func IsRuntimePkg(p *Pkg) bool {
  1899  	return objabi.LookupPkgSpecial(p.Path).Runtime
  1900  }
  1901  
  1902  // ReceiverBaseType returns the underlying type, if any,
  1903  // that owns methods with receiver parameter t.
  1904  // The result is either a named type or an anonymous struct.
  1905  func ReceiverBaseType(t *Type) *Type {
  1906  	if t == nil {
  1907  		return nil
  1908  	}
  1909  
  1910  	// Strip away pointer if it's there.
  1911  	if t.IsPtr() {
  1912  		if t.Sym() != nil {
  1913  			return nil
  1914  		}
  1915  		t = t.Elem()
  1916  		if t == nil {
  1917  			return nil
  1918  		}
  1919  	}
  1920  
  1921  	// Must be a named type or anonymous struct.
  1922  	if t.Sym() == nil && !t.IsStruct() {
  1923  		return nil
  1924  	}
  1925  
  1926  	// Check types.
  1927  	if IsSimple[t.Kind()] {
  1928  		return t
  1929  	}
  1930  	switch t.Kind() {
  1931  	case TARRAY, TCHAN, TFUNC, TMAP, TSLICE, TSTRING, TSTRUCT:
  1932  		return t
  1933  	}
  1934  	return nil
  1935  }
  1936  
  1937  func FloatForComplex(t *Type) *Type {
  1938  	switch t.Kind() {
  1939  	case TCOMPLEX64:
  1940  		return Types[TFLOAT32]
  1941  	case TCOMPLEX128:
  1942  		return Types[TFLOAT64]
  1943  	}
  1944  	base.Fatalf("unexpected type: %v", t)
  1945  	return nil
  1946  }
  1947  
  1948  func ComplexForFloat(t *Type) *Type {
  1949  	switch t.Kind() {
  1950  	case TFLOAT32:
  1951  		return Types[TCOMPLEX64]
  1952  	case TFLOAT64:
  1953  		return Types[TCOMPLEX128]
  1954  	}
  1955  	base.Fatalf("unexpected type: %v", t)
  1956  	return nil
  1957  }
  1958  
  1959  func TypeSym(t *Type) *Sym {
  1960  	return TypeSymLookup(TypeSymName(t))
  1961  }
  1962  
  1963  func TypeSymLookup(name string) *Sym {
  1964  	typepkgmu.Lock()
  1965  	s := typepkg.Lookup(name)
  1966  	typepkgmu.Unlock()
  1967  	return s
  1968  }
  1969  
  1970  func TypeSymName(t *Type) string {
  1971  	name := t.LinkString()
  1972  	// Use a separate symbol name for Noalg types for #17752.
  1973  	if TypeHasNoAlg(t) {
  1974  		name = "noalg." + name
  1975  	}
  1976  	return name
  1977  }
  1978  
  1979  // Fake package for runtime type info (headers)
  1980  // Don't access directly, use typeLookup below.
  1981  var (
  1982  	typepkgmu sync.Mutex // protects typepkg lookups
  1983  	typepkg   = NewPkg("type", "type")
  1984  )
  1985  
  1986  var SimType [NTYPE]Kind
  1987  
  1988  // Fake package for shape types (see typecheck.Shapify()).
  1989  var ShapePkg = NewPkg("go.shape", "go.shape")
  1990  
  1991  func (t *Type) IsSIMD() bool {
  1992  	return t.flags&typeIsSIMD != 0
  1993  }
  1994  

View as plain text