...

Package types

import "cmd/compile/internal/types"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func AllowsGoVersion(major, minor int) bool
func CalcSize(t *Type)
func CalcStructSize(t *Type)
func CheckSize(t *Type)
func DeferCheckSize()
func Identical(t1, t2 *Type) bool
func IdenticalIgnoreTags(t1, t2 *Type) bool
func IdenticalStrict(t1, t2 *Type) bool
func InitTypes(defTypeName func(sym *Sym, typ *Type) Object)
func InternString(b []byte) string
func IsComparable(t *Type) bool
func IsDirectIface(t *Type) bool
func IsExported(name string) bool
func IsInterfaceMethod(f *Type) bool
func IsMethodApplicable(t *Type, m *Field) bool
func IsNoInstrumentPkg(p *Pkg) bool
func IsNoRacePkg(p *Pkg) bool
func IsPaddedField(t *Type, i int) bool
func IsReflexive(t *Type) bool
func IsRuntimePkg(p *Pkg) bool
func ParseLangFlag()
func PkgMap() map[string]*Pkg
func PtrDataSize(t *Type) int64
func ReflectSymName(s *Sym) string
func ResumeCheckSize()
func RoundUp(o int64, r int64) int64
func RuntimeSymName(s *Sym) string
func SplitVargenSuffix(name string) (base, suffix string)
func TypeHasNoAlg(t *Type) bool
func TypeHash(t *Type) uint32
func TypeSymName(t *Type) string
type AlgKind
    func AlgType(t *Type) AlgKind
    func (i AlgKind) String() string
type Array
type Chan
type ChanArgs
type ChanDir
    func (c ChanDir) CanRecv() bool
    func (c ChanDir) CanSend() bool
type Cmp
type EmbeddedsByName
    func (x EmbeddedsByName) Len() int
    func (x EmbeddedsByName) Less(i, j int) bool
    func (x EmbeddedsByName) Swap(i, j int)
type Field
    func FakeRecv() *Field
    func IncomparableField(t *Type) *Field
    func NewField(pos src.XPos, sym *Sym, typ *Type) *Field
    func (f *Field) Copy() *Field
    func (f *Field) End() int64
    func (f *Field) IsDDD() bool
    func (f *Field) IsMethod() bool
    func (f *Field) Nointerface() bool
    func (f *Field) SetIsDDD(b bool)
    func (f *Field) SetNointerface(b bool)
type Forward
type Func
type FuncArgs
type Interface
type Kind
    func (i Kind) String() string
type Map
type MethodsByName
    func (x MethodsByName) Len() int
    func (x MethodsByName) Less(i, j int) bool
    func (x MethodsByName) Swap(i, j int)
type Object
type Pkg
    func NewPkg(path, name string) *Pkg
    func (pkg *Pkg) Lookup(name string) *Sym
    func (pkg *Pkg) LookupBytes(name []byte) *Sym
    func (pkg *Pkg) LookupNum(prefix string, n int) *Sym
    func (pkg *Pkg) LookupOK(name string) (s *Sym, existed bool)
    func (pkg *Pkg) Selector(name string) *Sym
type Ptr
type Results
type Slice
type Struct
type Sym
    func TypeSym(t *Type) *Sym
    func TypeSymLookup(name string) *Sym
    func (sym *Sym) Asm() bool
    func (s *Sym) Format(f fmt.State, verb rune)
    func (sym *Sym) Func() bool
    func (sym *Sym) IsBlank() bool
    func (a *Sym) Less(b *Sym) bool
    func (sym *Sym) Linksym() *obj.LSym
    func (sym *Sym) LinksymABI(abi obj.ABI) *obj.LSym
    func (sym *Sym) OnExportList() bool
    func (sym *Sym) SetAsm(b bool)
    func (sym *Sym) SetFunc(b bool)
    func (sym *Sym) SetOnExportList(b bool)
    func (sym *Sym) SetSiggen(b bool)
    func (sym *Sym) SetUniq(b bool)
    func (sym *Sym) Siggen() bool
    func (s *Sym) String() string
    func (sym *Sym) Uniq() bool
type Tuple
type Type
    func ComplexForFloat(t *Type) *Type
    func FakeRecvType() *Type
    func FloatForComplex(t *Type) *Type
    func NewArray(elem *Type, bound int64) *Type
    func NewChan(elem *Type, dir ChanDir) *Type
    func NewChanArgs(c *Type) *Type
    func NewFuncArgs(f *Type) *Type
    func NewInterface(methods []*Field) *Type
    func NewMap(k, v *Type) *Type
    func NewNamed(obj Object) *Type
    func NewPtr(elem *Type) *Type
    func NewResults(types []*Type) *Type
    func NewSignature(recv *Field, params, results []*Field) *Type
    func NewSlice(elem *Type) *Type
    func NewStruct(fields []*Field) *Type
    func NewTuple(t1, t2 *Type) *Type
    func ReceiverBaseType(t *Type) *Type
    func SubstAny(t *Type, types *[]*Type) *Type
    func (t *Type) Alignment() int64
    func (t *Type) AllMethods() []*Field
    func (t *Type) ArgWidth() int64
    func (*Type) CanBeAnSSAAux()
    func (t *Type) ChanArgs() *Type
    func (t *Type) ChanDir() ChanDir
    func (t *Type) Compare(x *Type) Cmp
    func (t *Type) Deferwidth() bool
    func (t *Type) Elem() *Type
    func (t *Type) Field(i int) *Field
    func (t *Type) FieldName(i int) string
    func (t *Type) FieldOff(i int) int64
    func (t *Type) FieldType(i int) *Type
    func (t *Type) Fields() []*Field
    func (t *Type) Format(s fmt.State, verb rune)
    func (t *Type) FuncArgs() *Type
    func (t *Type) HasNil() bool
    func (t *Type) HasPointers() bool
    func (t *Type) HasShape() bool
    func (t *Type) IsArray() bool
    func (t *Type) IsBoolean() bool
    func (t *Type) IsChan() bool
    func (t *Type) IsComplex() bool
    func (t *Type) IsEmptyInterface() bool
    func (t *Type) IsFlags() bool
    func (t *Type) IsFloat() bool
    func (t *Type) IsFullyInstantiated() bool
    func (t *Type) IsFuncArgStruct() bool
    func (t *Type) IsInteger() bool
    func (t *Type) IsInterface() bool
    func (t *Type) IsKind(et Kind) bool
    func (t *Type) IsMap() bool
    func (t *Type) IsMemory() bool
    func (t *Type) IsPtr() bool
    func (t *Type) IsPtrElem() bool
    func (t *Type) IsPtrShaped() bool
    func (t *Type) IsResults() bool
    func (t *Type) IsScalar() bool
    func (t *Type) IsShape() bool
    func (t *Type) IsSigned() bool
    func (t *Type) IsSlice() bool
    func (t *Type) IsString() bool
    func (t *Type) IsStruct() bool
    func (t *Type) IsTuple() bool
    func (t *Type) IsUintptr() bool
    func (t *Type) IsUnsafePtr() bool
    func (t *Type) IsUnsigned() bool
    func (t *Type) IsUntyped() bool
    func (t *Type) IsVariadic() bool
    func (t *Type) IsVoid() bool
    func (t *Type) Key() *Type
    func (t *Type) Kind() Kind
    func (t *Type) LinkString() string
    func (t *Type) MapType() *Map
    func (t *Type) Methods() []*Field
    func (t *Type) NameString() string
    func (t *Type) Noalg() bool
    func (t *Type) NotInHeap() bool
    func (t *Type) NumComponents(countBlank componentsIncludeBlankFields) int64
    func (t *Type) NumElem() int64
    func (t *Type) NumFields() int
    func (t *Type) NumParams() int
    func (t *Type) NumRecvs() int
    func (t *Type) NumResults() int
    func (t *Type) Obj() Object
    func (t *Type) OffsetOf(name string) int64
    func (t *Type) Param(i int) *Field
    func (t *Type) Params() []*Field
    func (t *Type) ParamsResults() []*Field
    func (t *Type) Pos() src.XPos
    func (t *Type) PtrTo() *Type
    func (t *Type) RParams() []*Type
    func (t *Type) Recur() bool
    func (t *Type) Recv() *Field
    func (t *Type) RecvParams() []*Field
    func (t *Type) RecvParamsResults() []*Field
    func (t *Type) Recvs() []*Field
    func (t *Type) Registers() (uint8, uint8)
    func (t *Type) Result(i int) *Field
    func (t *Type) Results() []*Field
    func (t *Type) ResultsTuple() *Type
    func (t *Type) SetAllMethods(fs []*Field)
    func (t *Type) SetDeferwidth(b bool)
    func (t *Type) SetHasShape(b bool)
    func (t *Type) SetInterface(methods []*Field)
    func (t *Type) SetIsShape(b bool)
    func (t *Type) SetMethods(fs []*Field)
    func (t *Type) SetNoalg(b bool)
    func (t *Type) SetNotInHeap(b bool)
    func (t *Type) SetRParams(rparams []*Type)
    func (t *Type) SetRecur(b bool)
    func (t *Type) SetUnderlying(underlying *Type)
    func (t *Type) SimpleString() string
    func (t *Type) Size() int64
    func (t *Type) SoleComponent() *Type
    func (t *Type) String() string
    func (t *Type) StructType() *Struct
    func (t *Type) Sym() *Sym
    func (t *Type) ToUnsigned() *Type
    func (t *Type) Underlying() *Type

Package files

alg.go algkind_string.go fmt.go goversion.go identity.go kind_string.go pkg.go size.go sort.go sym.go type.go universe.go utils.go

Constants

const (
    CMPlt = Cmp(-1)
    CMPeq = Cmp(0)
    CMPgt = Cmp(1)
)
const (
    IgnoreBlankFields componentsIncludeBlankFields = false
    CountBlankFields  componentsIncludeBlankFields = true
)
const BADWIDTH = -1000000000

Variables

Slices in the runtime are represented by three components:

type slice struct {
	ptr unsafe.Pointer
	len int
	cap int
}

Strings in the runtime are represented by two components:

type string struct {
	ptr unsafe.Pointer
	len int
}

These variables are the offsets of fields and sizes of these structs.

var (
    SlicePtrOffset int64
    SliceLenOffset int64
    SliceCapOffset int64

    SliceSize  int64
    StringSize int64
)
var (
    // Predeclared alias types. These are actually created as distinct
    // defined types for better error messages, but are then specially
    // treated as identical to their respective underlying types.
    AnyType  *Type
    ByteType *Type
    RuneType *Type

    // Predeclared error interface type.
    ErrorType *Type
    // Predeclared comparable interface type.
    ComparableType *Type

    // Types to represent untyped string and boolean constants.
    UntypedString = newType(TSTRING)
    UntypedBool   = newType(TBOOL)

    // Types to represent untyped numeric constants.
    UntypedInt     = newType(TIDEAL)
    UntypedRune    = newType(TIDEAL)
    UntypedFloat   = newType(TIDEAL)
    UntypedComplex = newType(TIDEAL)
)
var (
    // TSSA types. HasPointers assumes these are pointer-free.
    TypeInvalid   = newSSA("invalid")
    TypeMem       = newSSA("mem")
    TypeFlags     = newSSA("flags")
    TypeVoid      = newSSA("void")
    TypeInt128    = newSSA("int128")
    TypeResultMem = newResults([]*Type{TypeMem})
)
var (
    IsInt     [NTYPE]bool
    IsFloat   [NTYPE]bool
    IsComplex [NTYPE]bool
    IsSimple  [NTYPE]bool
)
var BasicTypeNames = []string{
    TINT:        "int",
    TUINT:       "uint",
    TINT8:       "int8",
    TUINT8:      "uint8",
    TINT16:      "int16",
    TUINT16:     "uint16",
    TINT32:      "int32",
    TUINT32:     "uint32",
    TINT64:      "int64",
    TUINT64:     "uint64",
    TUINTPTR:    "uintptr",
    TFLOAT32:    "float32",
    TFLOAT64:    "float64",
    TCOMPLEX64:  "complex64",
    TCOMPLEX128: "complex128",
    TBOOL:       "bool",
    TANY:        "any",
    TSTRING:     "string",
    TNIL:        "nil",
    TIDEAL:      "untyped number",
    TBLANK:      "blank",
}

CalcSizeDisabled indicates whether it is safe to calculate Types' widths and alignments. See CalcSize.

var CalcSizeDisabled bool

DefaultKinds maps from a constant.Kind to its default Kind.

var DefaultKinds = [...]Kind{
    constant.Bool:    TBOOL,
    constant.String:  TSTRING,
    constant.Int:     TINT,
    constant.Float:   TFLOAT64,
    constant.Complex: TCOMPLEX128,
}
var IsOrdered [NTYPE]bool

MaxWidth is the maximum size of a value on the target architecture.

var MaxWidth int64

NewPtrCacheEnabled controls whether *T Types are cached in T. Caching is disabled just before starting the backend. This allows the backend to run concurrently.

var NewPtrCacheEnabled = true

numImport tracks how often a package with a given name is imported. It is used to provide a better error message (by using the package path to disambiguate) if a package that appears multiple times with the same name appears in an error message.

var NumImport = make(map[string]int)
var PtrSize int
var RegSize int

Fake package for shape types (see typecheck.Shapify()).

var ShapePkg = NewPkg("go.shape", "go.shape")
var SimType [NTYPE]Kind
var SkipSizeForTracing bool

Types stores pointers to predeclared named types.

It also stores pointers to several special types:

var Types [NTYPE]*Type

UntypedTypes maps from a constant.Kind to its untyped Type representation.

var UntypedTypes = [...]*Type{
    constant.Bool:    UntypedBool,
    constant.String:  UntypedString,
    constant.Int:     UntypedInt,
    constant.Float:   UntypedFloat,
    constant.Complex: UntypedComplex,
}

func AllowsGoVersion

func AllowsGoVersion(major, minor int) bool

AllowsGoVersion reports whether local package is allowed to use Go version major.minor.

func CalcSize

func CalcSize(t *Type)

CalcSize calculates and stores the size, alignment, eq/hash algorithm, and ptrBytes for t. If CalcSizeDisabled is set, and the size/alignment have not already been calculated, it calls Fatal. This is used to prevent data races in the back end.

func CalcStructSize

func CalcStructSize(t *Type)

CalcStructSize calculates the size of t, filling in t.width, t.align, t.intRegs, and t.floatRegs, even if size calculation is otherwise disabled.

func CheckSize

func CheckSize(t *Type)

func DeferCheckSize

func DeferCheckSize()

func Identical

func Identical(t1, t2 *Type) bool

Identical reports whether t1 and t2 are identical types, following the spec rules. Receiver parameter types are ignored. Named (defined) types are only equal if they are pointer-equal - i.e. there must be a unique types.Type for each specific named type. Also, a type containing a shape type is considered identical to another type (shape or not) if their underlying types are the same, or they are both pointers.

func IdenticalIgnoreTags

func IdenticalIgnoreTags(t1, t2 *Type) bool

IdenticalIgnoreTags is like Identical, but it ignores struct tags for struct identity.

func IdenticalStrict

func IdenticalStrict(t1, t2 *Type) bool

IdenticalStrict is like Identical, but matches types exactly, without the exception for shapes.

func InitTypes

func InitTypes(defTypeName func(sym *Sym, typ *Type) Object)

func InternString

func InternString(b []byte) string

func IsComparable

func IsComparable(t *Type) bool

IsComparable reports whether t is a comparable type.

func IsDirectIface

func IsDirectIface(t *Type) bool

Can this type be stored directly in an interface word? Yes, if the representation is a single pointer.

func IsExported

func IsExported(name string) bool

IsExported reports whether name is an exported Go symbol (that is, whether it begins with an upper-case letter).

func IsInterfaceMethod

func IsInterfaceMethod(f *Type) bool

IsInterfaceMethod reports whether (field) m is an interface method. Such methods have the special receiver type types.FakeRecvType().

func IsMethodApplicable

func IsMethodApplicable(t *Type, m *Field) bool

IsMethodApplicable reports whether method m can be called on a value of type t. This is necessary because we compute a single method set for both T and *T, but some *T methods are not applicable to T receivers.

func IsNoInstrumentPkg

func IsNoInstrumentPkg(p *Pkg) bool

IsNoInstrumentPkg reports whether p is a package that should not be instrumented.

func IsNoRacePkg

func IsNoRacePkg(p *Pkg) bool

IsNoRacePkg reports whether p is a package that should not be race instrumented.

func IsPaddedField

func IsPaddedField(t *Type, i int) bool

IsPaddedField reports whether the i'th field of struct type t is followed by padding.

func IsReflexive

func IsReflexive(t *Type) bool

IsReflexive reports whether t has a reflexive equality operator. That is, if x==x for all x of type t.

func IsRuntimePkg

func IsRuntimePkg(p *Pkg) bool

IsRuntimePkg reports whether p is a runtime package.

func ParseLangFlag

func ParseLangFlag()

ParseLangFlag verifies that the -lang flag holds a valid value, and exits if not. It initializes data used by AllowsGoVersion.

func PkgMap

func PkgMap() map[string]*Pkg

func PtrDataSize

func PtrDataSize(t *Type) int64

PtrDataSize returns the length in bytes of the prefix of t containing pointer data. Anything after this offset is scalar data.

PtrDataSize is only defined for actual Go types. It's an error to use it on compiler-internal types (e.g., TSSA, TRESULTS).

func ReflectSymName

func ReflectSymName(s *Sym) string

ReflectSymName returns the name of s if it's in package "reflect"; otherwise it returns "".

func ResumeCheckSize

func ResumeCheckSize()

func RoundUp

func RoundUp(o int64, r int64) int64

RoundUp rounds o to a multiple of r, r is a power of 2.

func RuntimeSymName

func RuntimeSymName(s *Sym) string

RuntimeSymName returns the name of s if it's in package "runtime"; otherwise it returns "".

func SplitVargenSuffix

func SplitVargenSuffix(name string) (base, suffix string)

SplitVargenSuffix returns name split into a base string and a ·N suffix, if any.

func TypeHasNoAlg

func TypeHasNoAlg(t *Type) bool

TypeHasNoAlg reports whether t does not have any associated hash/eq algorithms because t, or some component of t, is marked Noalg.

func TypeHash

func TypeHash(t *Type) uint32

TypeHash computes a hash value for type t to use in type switch statements.

func TypeSymName

func TypeSymName(t *Type) string

type AlgKind

AlgKind describes the kind of algorithms used for comparing and hashing a Type.

type AlgKind int8
const (
    AUNK   AlgKind = iota
    ANOEQ          // Types cannot be compared
    ANOALG         // implies ANOEQ, and in addition has a part that is marked Noalg
    AMEM           // Type can be compared/hashed as regular memory.
    AMEM0          // Specific subvariants of AMEM (TODO: move to ../reflectdata?)
    AMEM8
    AMEM16
    AMEM32
    AMEM64
    AMEM128
    ASTRING
    AINTER
    ANILINTER
    AFLOAT32
    AFLOAT64
    ACPLX64
    ACPLX128
    ASPECIAL // Type needs special comparison/hashing functions.
)

func AlgType

func AlgType(t *Type) AlgKind

AlgType returns the AlgKind used for comparing and hashing Type t.

func (AlgKind) String

func (i AlgKind) String() string

type Array

Array contains Type fields specific to array types.

type Array struct {
    Elem  *Type // element type
    Bound int64 // number of elements; <0 if unknown yet
}

type Chan

Chan contains Type fields specific to channel types.

type Chan struct {
    Elem *Type   // element type
    Dir  ChanDir // channel direction
}

type ChanArgs

ChanArgs contains Type fields specific to TCHANARGS types.

type ChanArgs struct {
    T *Type // reference to a chan type whose elements need a width check
}

type ChanDir

ChanDir is whether a channel can send, receive, or both.

type ChanDir uint8
const (
    // types of channel
    // must match ../../../../reflect/type.go:/ChanDir
    Crecv ChanDir = 1 << 0
    Csend ChanDir = 1 << 1
    Cboth ChanDir = Crecv | Csend
)

func (ChanDir) CanRecv

func (c ChanDir) CanRecv() bool

func (ChanDir) CanSend

func (c ChanDir) CanSend() bool

type Cmp

Cmp is a comparison between values a and b.

-1 if a < b
 0 if a == b
 1 if a > b
type Cmp int8

type EmbeddedsByName

EmbeddedsByName sorts embedded types by name.

type EmbeddedsByName []*Field

func (EmbeddedsByName) Len

func (x EmbeddedsByName) Len() int

func (EmbeddedsByName) Less

func (x EmbeddedsByName) Less(i, j int) bool

func (EmbeddedsByName) Swap

func (x EmbeddedsByName) Swap(i, j int)

type Field

A Field is a (Sym, Type) pairing along with some other information, and, depending on the context, is used to represent:

type Field struct {
    Embedded uint8 // embedded field

    Pos src.XPos

    // Name of field/method/parameter. Can be nil for interface fields embedded
    // in interfaces and unnamed parameters.
    Sym  *Sym
    Type *Type  // field type
    Note string // literal string annotation

    // For fields that represent function parameters, Nname points to the
    // associated ONAME Node. For fields that represent methods, Nname points to
    // the function name node.
    Nname Object

    // Offset in bytes of this field or method within its enclosing struct
    // or interface Type. For parameters, this is BADWIDTH.
    Offset int64
    // contains filtered or unexported fields
}

func FakeRecv

func FakeRecv() *Field

func IncomparableField

func IncomparableField(t *Type) *Field

IncomparableField returns an incomparable Field of struct Type t, if any.

func NewField

func NewField(pos src.XPos, sym *Sym, typ *Type) *Field

func (*Field) Copy

func (f *Field) Copy() *Field

func (*Field) End

func (f *Field) End() int64

End returns the offset of the first byte immediately after this field.

func (*Field) IsDDD

func (f *Field) IsDDD() bool

func (*Field) IsMethod

func (f *Field) IsMethod() bool

IsMethod reports whether f represents a method rather than a struct field.

func (*Field) Nointerface

func (f *Field) Nointerface() bool

func (*Field) SetIsDDD

func (f *Field) SetIsDDD(b bool)

func (*Field) SetNointerface

func (f *Field) SetNointerface(b bool)

type Forward

Forward contains Type fields specific to forward types.

type Forward struct {
    Copyto      []*Type  // where to copy the eventual value to
    Embedlineno src.XPos // first use of this type as an embedded type
}

type Func

Func contains Type fields specific to func types.

type Func struct {

    // Argwid is the total width of the function receiver, params, and results.
    // It gets calculated via a temporary TFUNCARGS type.
    // Note that TFUNC's Width is Widthptr.
    Argwid int64
    // contains filtered or unexported fields
}

type FuncArgs

// FuncArgs contains Type fields specific to TFUNCARGS types.

type FuncArgs struct {
    T *Type // reference to a func type whose elements need a width check
}

type Interface

Interface contains Type fields specific to interface types.

type Interface struct {
}

type Kind

Kind describes a kind of type.

type Kind uint8
const (
    Txxx Kind = iota

    TINT8
    TUINT8
    TINT16
    TUINT16
    TINT32
    TUINT32
    TINT64
    TUINT64
    TINT
    TUINT
    TUINTPTR

    TCOMPLEX64
    TCOMPLEX128

    TFLOAT32
    TFLOAT64

    TBOOL

    TPTR
    TFUNC
    TSLICE
    TARRAY
    TSTRUCT
    TCHAN
    TMAP
    TINTER
    TFORW
    TANY
    TSTRING
    TUNSAFEPTR

    // pseudo-types for literals
    TIDEAL // untyped numeric constants
    TNIL
    TBLANK

    // pseudo-types used temporarily only during frame layout (CalcSize())
    TFUNCARGS
    TCHANARGS

    // SSA backend types
    TSSA     // internal types used by SSA backend (flags, memory, etc.)
    TTUPLE   // a pair of types, used by SSA backend
    TRESULTS // multiple types; the result of calling a function or method, with a memory at the end.

    NTYPE
)

func (Kind) String

func (i Kind) String() string

type Map

Map contains Type fields specific to maps.

type Map struct {
    Key  *Type // Key type
    Elem *Type // Val (elem) type

    Bucket *Type // internal struct type representing a hash bucket
}

type MethodsByName

MethodsByName sorts methods by name.

type MethodsByName []*Field

func (MethodsByName) Len

func (x MethodsByName) Len() int

func (MethodsByName) Less

func (x MethodsByName) Less(i, j int) bool

func (MethodsByName) Swap

func (x MethodsByName) Swap(i, j int)

type Object

Object represents an ir.Node, but without needing to import cmd/compile/internal/ir, which would cause an import cycle. The uses in other packages must type assert values of type Object to ir.Node or a more specific type.

type Object interface {
    Pos() src.XPos
    Sym() *Sym
    Type() *Type
}

type Pkg

type Pkg struct {
    Path    string // string literal used in import statement, e.g. "runtime/internal/sys"
    Name    string // package name, e.g. "sys"
    Prefix  string // escaped path for use in symbol table
    Syms    map[string]*Sym
    Pathsym *obj.LSym

    Direct bool // imported directly
}

BuiltinPkg is a fake package that declares the universe block.

var BuiltinPkg *Pkg

LocalPkg is the package being compiled.

var LocalPkg *Pkg

UnsafePkg is package unsafe.

var UnsafePkg *Pkg

func NewPkg

func NewPkg(path, name string) *Pkg

NewPkg returns a new Pkg for the given package path and name. Unless name is the empty string, if the package exists already, the existing package name and the provided name must match.

func (*Pkg) Lookup

func (pkg *Pkg) Lookup(name string) *Sym

func (*Pkg) LookupBytes

func (pkg *Pkg) LookupBytes(name []byte) *Sym

func (*Pkg) LookupNum

func (pkg *Pkg) LookupNum(prefix string, n int) *Sym

LookupNum looks up the symbol starting with prefix and ending with the decimal n. If prefix is too long, LookupNum panics.

func (*Pkg) LookupOK

func (pkg *Pkg) LookupOK(name string) (s *Sym, existed bool)

LookupOK looks up name in pkg and reports whether it previously existed.

func (*Pkg) Selector

func (pkg *Pkg) Selector(name string) *Sym

Selector looks up a selector identifier.

type Ptr

Ptr contains Type fields specific to pointer types.

type Ptr struct {
    Elem *Type // element type
}

type Results

Results are the output from calls that will be late-expanded.

type Results struct {
    Types []*Type // Last element is memory output from call.
}

type Slice

Slice contains Type fields specific to slice types.

type Slice struct {
    Elem *Type // element type
}

type Struct

StructType contains Type fields specific to struct types.

type Struct struct {

    // Maps have three associated internal structs (see struct MapType).
    // Map links such structs back to their map type.
    Map *Type

    ParamTuple bool // whether this struct is actually a tuple of signature parameters
    // contains filtered or unexported fields
}

type Sym

Sym represents an object name in a segmented (pkg, name) namespace. Most commonly, this is a Go identifier naming an object declared within a package, but Syms are also used to name internal synthesized objects.

As an exception, field and method names that are exported use the Sym associated with localpkg instead of the package that declared them. This allows using Sym pointer equality to test for Go identifier uniqueness when handling selector expressions.

Ideally, Sym should be used for representing Go language constructs, while cmd/internal/obj.LSym is used for representing emitted artifacts.

NOTE: In practice, things can be messier than the description above for various reasons (historical, convenience).

type Sym struct {
    Linkname string // link name

    Pkg  *Pkg
    Name string // object name

    // The unique ONAME, OTYPE, OPACK, or OLITERAL node that this symbol is
    // bound to within the current scope. (Most parts of the compiler should
    // prefer passing the Node directly, rather than relying on this field.)
    //
    // Deprecated: New code should avoid depending on Sym.Def. Add
    // mdempsky@ as a reviewer for any CLs involving Sym.Def.
    Def Object
    // contains filtered or unexported fields
}

BlankSym is the blank (_) symbol.

var BlankSym *Sym

func TypeSym

func TypeSym(t *Type) *Sym

func TypeSymLookup

func TypeSymLookup(name string) *Sym

func (*Sym) Asm

func (sym *Sym) Asm() bool

func (*Sym) Format

func (s *Sym) Format(f fmt.State, verb rune)

Format implements formatting for a Sym. The valid formats are:

%v	Go syntax: Name for symbols in the local package, PkgName.Name for imported symbols.
%+v	Debug syntax: always include PkgName. prefix even for local names.
%S	Short syntax: Name only, no matter what.

func (*Sym) Func

func (sym *Sym) Func() bool

func (*Sym) IsBlank

func (sym *Sym) IsBlank() bool

func (*Sym) Less

func (a *Sym) Less(b *Sym) bool

Less reports whether symbol a is ordered before symbol b.

Symbols are ordered exported before non-exported, then by name, and finally (for non-exported symbols) by package path.

func (*Sym) Linksym

func (sym *Sym) Linksym() *obj.LSym

Deprecated: This method should not be used directly. Instead, use a higher-level abstraction that directly returns the linker symbol for a named object. For example, reflectdata.TypeLinksym(t) instead of reflectdata.TypeSym(t).Linksym().

func (*Sym) LinksymABI

func (sym *Sym) LinksymABI(abi obj.ABI) *obj.LSym

Deprecated: This method should not be used directly. Instead, use a higher-level abstraction that directly returns the linker symbol for a named object. For example, (*ir.Name).LinksymABI(abi) instead of (*ir.Name).Sym().LinksymABI(abi).

func (*Sym) OnExportList

func (sym *Sym) OnExportList() bool

func (*Sym) SetAsm

func (sym *Sym) SetAsm(b bool)

func (*Sym) SetFunc

func (sym *Sym) SetFunc(b bool)

func (*Sym) SetOnExportList

func (sym *Sym) SetOnExportList(b bool)

func (*Sym) SetSiggen

func (sym *Sym) SetSiggen(b bool)

func (*Sym) SetUniq

func (sym *Sym) SetUniq(b bool)

func (*Sym) Siggen

func (sym *Sym) Siggen() bool

func (*Sym) String

func (s *Sym) String() string

func (*Sym) Uniq

func (sym *Sym) Uniq() bool

type Tuple

type Tuple struct {
    // contains filtered or unexported fields
}

type Type

A Type represents a Go type.

There may be multiple unnamed types with identical structure. However, there must be a unique Type object for each unique named (defined) type. After noding, a package-level type can be looked up by building its unique symbol sym (sym = package.Lookup(name)) and checking sym.Def. If sym.Def is non-nil, the type already exists at package scope and is available at sym.Def.(*ir.Name).Type(). Local types (which may have the same name as a package-level type) are distinguished by their vargen, which is embedded in their symbol name.

type Type struct {
    // contains filtered or unexported fields
}

func ComplexForFloat

func ComplexForFloat(t *Type) *Type

func FakeRecvType

func FakeRecvType() *Type

FakeRecvType returns the singleton type used for interface method receivers.

func FloatForComplex

func FloatForComplex(t *Type) *Type

func NewArray

func NewArray(elem *Type, bound int64) *Type

NewArray returns a new fixed-length array Type.

func NewChan

func NewChan(elem *Type, dir ChanDir) *Type

NewChan returns a new chan Type with direction dir.

func NewChanArgs

func NewChanArgs(c *Type) *Type

NewChanArgs returns a new TCHANARGS type for channel type c.

func NewFuncArgs

func NewFuncArgs(f *Type) *Type

NewFuncArgs returns a new TFUNCARGS type for func type f.

func NewInterface

func NewInterface(methods []*Field) *Type

NewInterface returns a new interface for the given methods and embedded types. Embedded types are specified as fields with no Sym.

func NewMap

func NewMap(k, v *Type) *Type

NewMap returns a new map Type with key type k and element (aka value) type v.

func NewNamed

func NewNamed(obj Object) *Type

NewNamed returns a new named type for the given type name. obj should be an ir.Name. The new type is incomplete (marked as TFORW kind), and the underlying type should be set later via SetUnderlying(). References to the type are maintained until the type is filled in, so those references can be updated when the type is complete.

func NewPtr

func NewPtr(elem *Type) *Type

NewPtr returns the pointer type pointing to t.

func NewResults

func NewResults(types []*Type) *Type

func NewSignature

func NewSignature(recv *Field, params, results []*Field) *Type

NewSignature returns a new function type for the given receiver, parameters, and results, any of which may be nil.

func NewSlice

func NewSlice(elem *Type) *Type

NewSlice returns the slice Type with element type elem.

func NewStruct

func NewStruct(fields []*Field) *Type

NewStruct returns a new struct with the given fields.

func NewTuple

func NewTuple(t1, t2 *Type) *Type

func ReceiverBaseType

func ReceiverBaseType(t *Type) *Type

ReceiverBaseType returns the underlying type, if any, that owns methods with receiver parameter t. The result is either a named type or an anonymous struct.

func SubstAny

func SubstAny(t *Type, types *[]*Type) *Type

SubstAny walks t, replacing instances of "any" with successive elements removed from types. It returns the substituted type.

func (*Type) Alignment

func (t *Type) Alignment() int64

func (*Type) AllMethods

func (t *Type) AllMethods() []*Field

AllMethods returns a pointer to all the methods (including embedding) for type t. For an interface type, this is the set of methods that are typically iterated over. For non-interface types, AllMethods() only returns a valid result after CalcMethods() has been called at least once.

func (*Type) ArgWidth

func (t *Type) ArgWidth() int64

ArgWidth returns the total aligned argument size for a function. It includes the receiver, parameters, and results.

func (*Type) CanBeAnSSAAux

func (*Type) CanBeAnSSAAux()

func (*Type) ChanArgs

func (t *Type) ChanArgs() *Type

ChanArgs returns the channel type for TCHANARGS type t.

func (*Type) ChanDir

func (t *Type) ChanDir() ChanDir

ChanDir returns the direction of a channel type t. The direction will be one of Crecv, Csend, or Cboth.

func (*Type) Compare

func (t *Type) Compare(x *Type) Cmp

Compare compares types for purposes of the SSA back end, returning a Cmp (one of CMPlt, CMPeq, CMPgt). The answers are correct for an optimizer or code generator, but not necessarily typechecking. The order chosen is arbitrary, only consistency and division into equivalence classes (Types that compare CMPeq) matters.

func (*Type) Deferwidth

func (t *Type) Deferwidth() bool

func (*Type) Elem

func (t *Type) Elem() *Type

Elem returns the type of elements of t. Usable with pointers, channels, arrays, slices, and maps.

func (*Type) Field

func (t *Type) Field(i int) *Field

Field returns the i'th field of struct type t.

func (*Type) FieldName

func (t *Type) FieldName(i int) string

func (*Type) FieldOff

func (t *Type) FieldOff(i int) int64

func (*Type) FieldType

func (t *Type) FieldType(i int) *Type

func (*Type) Fields

func (t *Type) Fields() []*Field

Fields returns a slice of containing all fields of a struct type t.

func (*Type) Format

func (t *Type) Format(s fmt.State, verb rune)

Format implements formatting for a Type. The valid formats are:

%v	Go syntax
%+v	Debug syntax: Go syntax with a KIND- prefix for all but builtins.
%L	Go syntax for underlying type if t is named
%S	short Go syntax: drop leading "func" in function type
%-S	special case for method receiver symbol

func (*Type) FuncArgs

func (t *Type) FuncArgs() *Type

FuncArgs returns the func type for TFUNCARGS type t.

func (*Type) HasNil

func (t *Type) HasNil() bool

HasNil reports whether the set of values determined by t includes nil.

func (*Type) HasPointers

func (t *Type) HasPointers() bool

HasPointers reports whether t contains a heap pointer. Note that this function ignores pointers to not-in-heap types.

func (*Type) HasShape

func (t *Type) HasShape() bool

func (*Type) IsArray

func (t *Type) IsArray() bool

func (*Type) IsBoolean

func (t *Type) IsBoolean() bool

func (*Type) IsChan

func (t *Type) IsChan() bool

func (*Type) IsComplex

func (t *Type) IsComplex() bool

func (*Type) IsEmptyInterface

func (t *Type) IsEmptyInterface() bool

IsEmptyInterface reports whether t is an empty interface type.

func (*Type) IsFlags

func (t *Type) IsFlags() bool

func (*Type) IsFloat

func (t *Type) IsFloat() bool

func (*Type) IsFullyInstantiated

func (t *Type) IsFullyInstantiated() bool

IsFullyInstantiated reports whether t is a fully instantiated generic type; i.e. an instantiated generic type where all type arguments are non-generic or fully instantiated generic types.

func (*Type) IsFuncArgStruct

func (t *Type) IsFuncArgStruct() bool

IsFuncArgStruct reports whether t is a struct representing function parameters or results.

func (*Type) IsInteger

func (t *Type) IsInteger() bool

func (*Type) IsInterface

func (t *Type) IsInterface() bool

func (*Type) IsKind

func (t *Type) IsKind(et Kind) bool

IsKind reports whether t is a Type of the specified kind.

func (*Type) IsMap

func (t *Type) IsMap() bool

func (*Type) IsMemory

func (t *Type) IsMemory() bool

func (*Type) IsPtr

func (t *Type) IsPtr() bool

IsPtr reports whether t is a regular Go pointer type. This does not include unsafe.Pointer.

func (*Type) IsPtrElem

func (t *Type) IsPtrElem() bool

IsPtrElem reports whether t is the element of a pointer (to t).

func (*Type) IsPtrShaped

func (t *Type) IsPtrShaped() bool

IsPtrShaped reports whether t is represented by a single machine pointer. In addition to regular Go pointer types, this includes map, channel, and function types and unsafe.Pointer. It does not include array or struct types that consist of a single pointer shaped type. TODO(mdempsky): Should it? See golang.org/issue/15028.

func (*Type) IsResults

func (t *Type) IsResults() bool

func (*Type) IsScalar

func (t *Type) IsScalar() bool

IsScalar reports whether 't' is a scalar Go type, e.g. bool/int/float/complex. Note that struct and array types consisting of a single scalar element are not considered scalar, likewise pointer types are also not considered scalar.

func (*Type) IsShape

func (t *Type) IsShape() bool

func (*Type) IsSigned

func (t *Type) IsSigned() bool

func (*Type) IsSlice

func (t *Type) IsSlice() bool

func (*Type) IsString

func (t *Type) IsString() bool

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) IsTuple

func (t *Type) IsTuple() bool

func (*Type) IsUintptr

func (t *Type) IsUintptr() bool

IsUintptr reports whether t is a uintptr.

func (*Type) IsUnsafePtr

func (t *Type) IsUnsafePtr() bool

IsUnsafePtr reports whether t is an unsafe pointer.

func (*Type) IsUnsigned

func (t *Type) IsUnsigned() bool

func (*Type) IsUntyped

func (t *Type) IsUntyped() bool

IsUntyped reports whether t is an untyped type.

func (*Type) IsVariadic

func (t *Type) IsVariadic() bool

IsVariadic reports whether function type t is variadic.

func (*Type) IsVoid

func (t *Type) IsVoid() bool

func (*Type) Key

func (t *Type) Key() *Type

Key returns the key type of map type t.

func (*Type) Kind

func (t *Type) Kind() Kind

Kind returns the kind of type t.

func (*Type) LinkString

func (t *Type) LinkString() string

LinkString returns a string description of t, suitable for use in link symbols.

The description corresponds to type identity. That is, for any pair of types t1 and t2, Identical(t1, t2) == (t1.LinkString() == t2.LinkString()) is true. Thus it's safe to use as a map key to implement a type-identity-keyed map.

func (*Type) MapType

func (t *Type) MapType() *Map

MapType returns t's extra map-specific fields.

func (*Type) Methods

func (t *Type) Methods() []*Field

Methods returns a pointer to the base methods (excluding embedding) for type t. These can either be concrete methods (for non-interface types) or interface methods (for interface types).

func (*Type) NameString

func (t *Type) NameString() string

NameString generates a user-readable, mostly unique string description of t. NameString always returns the same description for identical types, even across compilation units.

NameString qualifies identifiers by package name, so it has collisions when different packages share the same names and identifiers. It also does not distinguish function-scope defined types from package-scoped defined types or from each other.

func (*Type) Noalg

func (t *Type) Noalg() bool

func (*Type) NotInHeap

func (t *Type) NotInHeap() bool

func (*Type) NumComponents

func (t *Type) NumComponents(countBlank componentsIncludeBlankFields) int64

NumComponents returns the number of primitive elements that compose t. Struct and array types are flattened for the purpose of counting. All other types (including string, slice, and interface types) count as one element. If countBlank is IgnoreBlankFields, then blank struct fields (and their comprised elements) are excluded from the count. struct { x, y [3]int } has six components; [10]struct{ x, y string } has twenty.

func (*Type) NumElem

func (t *Type) NumElem() int64

func (*Type) NumFields

func (t *Type) NumFields() int

func (*Type) NumParams

func (t *Type) NumParams() int

func (*Type) NumRecvs

func (t *Type) NumRecvs() int

func (*Type) NumResults

func (t *Type) NumResults() int

func (*Type) Obj

func (t *Type) Obj() Object

Obj returns the canonical type name node for a named type t, nil for an unnamed type.

func (*Type) OffsetOf

func (t *Type) OffsetOf(name string) int64

OffsetOf reports the offset of the field of a struct. The field is looked up by name.

func (*Type) Param

func (t *Type) Param(i int) *Field

Param returns the i'th parameter of signature type t.

func (*Type) Params

func (t *Type) Params() []*Field

Params returns a slice of regular parameters of signature type t.

func (*Type) ParamsResults

func (t *Type) ParamsResults() []*Field

ParamsResults returns a slice containing the signature's (normal) parameters followed by its results.

func (*Type) Pos

func (t *Type) Pos() src.XPos

Pos returns a position associated with t, if any. This should only be used for diagnostics.

func (*Type) PtrTo

func (t *Type) PtrTo() *Type

func (*Type) RParams

func (t *Type) RParams() []*Type

func (*Type) Recur

func (t *Type) Recur() bool

func (*Type) Recv

func (t *Type) Recv() *Field

Recv returns the receiver of function type t, if any.

func (*Type) RecvParams

func (t *Type) RecvParams() []*Field

RecvParams returns a slice containing the signature's receiver (if any) followed by its (normal) parameters.

func (*Type) RecvParamsResults

func (t *Type) RecvParamsResults() []*Field

RecvParamsResults returns a slice containing all of the signature's parameters in receiver (if any), (normal) parameters, and then results.

func (*Type) Recvs

func (t *Type) Recvs() []*Field

Recvs returns a slice of receiver parameters of signature type t. The returned slice always has length 0 or 1.

func (*Type) Registers

func (t *Type) Registers() (uint8, uint8)

Registers returns the number of integer and floating-point registers required to represent a parameter of this type under the ABIInternal calling conventions.

If t must be passed by memory, Registers returns (math.MaxUint8, math.MaxUint8).

func (*Type) Result

func (t *Type) Result(i int) *Field

Result returns the i'th result of signature type t.

func (*Type) Results

func (t *Type) Results() []*Field

Results returns a slice of result parameters of signature type t.

func (*Type) ResultsTuple

func (t *Type) ResultsTuple() *Type

ResultsTuple returns the result type of signature type t as a tuple. This can be used as the type of multi-valued call expressions.

func (*Type) SetAllMethods

func (t *Type) SetAllMethods(fs []*Field)

SetAllMethods sets the set of all methods for type t (i.e., including promoted methods from embedded types).

func (*Type) SetDeferwidth

func (t *Type) SetDeferwidth(b bool)

func (*Type) SetHasShape

func (t *Type) SetHasShape(b bool)

func (*Type) SetInterface

func (t *Type) SetInterface(methods []*Field)

SetInterface sets the base methods of an interface type t.

func (*Type) SetIsShape

func (t *Type) SetIsShape(b bool)

Should always do SetHasShape(true) when doing SetIsShape(true).

func (*Type) SetMethods

func (t *Type) SetMethods(fs []*Field)

SetMethods sets the direct method set for type t (i.e., *not* including promoted methods from embedded types).

func (*Type) SetNoalg

func (t *Type) SetNoalg(b bool)

func (*Type) SetNotInHeap

func (t *Type) SetNotInHeap(b bool)

func (*Type) SetRParams

func (t *Type) SetRParams(rparams []*Type)

func (*Type) SetRecur

func (t *Type) SetRecur(b bool)

func (*Type) SetUnderlying

func (t *Type) SetUnderlying(underlying *Type)

SetUnderlying sets the underlying type of an incomplete type (i.e. type whose kind is currently TFORW). SetUnderlying automatically updates any types that were waiting for this type to be completed.

func (*Type) SimpleString

func (t *Type) SimpleString() string

func (*Type) Size

func (t *Type) Size() int64

func (*Type) SoleComponent

func (t *Type) SoleComponent() *Type

SoleComponent returns the only primitive component in t, if there is exactly one. Otherwise, it returns nil. Components are counted as in NumComponents, including blank fields. Keep in sync with cmd/compile/internal/walk/convert.go:soleComponent.

func (*Type) String

func (t *Type) String() string

String returns the Go syntax for the type t.

func (*Type) StructType

func (t *Type) StructType() *Struct

StructType returns t's extra struct-specific fields.

func (*Type) Sym

func (t *Type) Sym() *Sym

Sym returns the name of type t.

func (*Type) ToUnsigned

func (t *Type) ToUnsigned() *Type

ToUnsigned returns the unsigned equivalent of integer type t.

func (*Type) Underlying

func (t *Type) Underlying() *Type

Underlying returns the underlying type of type t.