abi

package
v0.0.0-...-8e03cb5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 1 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MapBucketCountBits = 3 // log2 of number of elements in a bucket.
	MapBucketCount     = 1 << MapBucketCountBits
	MapMaxKeyBytes     = 128 // Must fit in a uint8.
	MapMaxElemBytes    = 128 // Must fit in a uint8.
)

Map constants common to several packages runtime/runtime-gdb.py:MapTypePrinter contains its own copy

View Source
const (
	// TODO (khr, drchase) why aren't these in TFlag?  Investigate, fix if possible.
	KindDirectIface = 1 << 5
	KindGCProg      = 1 << 6 // Type.gc points to GC program
	// KindStdcall records the calling convention of a native function value.
	// It is independent of the callback convention selected by NewCallback.
	KindStdcall = 1 << 7
	// On a Go function, the same bit marks a signature with ABI-qualified
	// function arguments or results and a public signature descriptor suffix.
	KindFuncPublic = KindStdcall
	KindMask       = (1 << 5) - 1
)
View Source
const MaxPtrmaskBytes = 2048

MaxPtrmaskBytes is the maximum length of a GC ptrmask bitmap, which holds 1-bit entries describing where pointers are in a given type. Above this length, the GC information is recorded as a GC program, which can express repetition compactly. In either form, the information is used by the runtime to initialize the heap bitmap, and for large types (like 128 or more words), they are roughly the same speed. GC programs are never much larger and often more compact. (If large arrays are involved, they can be arbitrarily more compact.)

The cutoff must be large enough that any allocation large enough to use a GC program is large enough that it does not share heap bitmap bytes with any other objects, allowing the GC program execution to assume an aligned start and not use atomic operations. In the current runtime, this means all malloc size classes larger than the cutoff must be multiples of four words. On 32-bit systems that's 16 bytes, and all size classes >= 16 bytes are 16-byte aligned, so no real constraint. On 64-bit systems, that's 32 bytes, and 32-byte alignment is guaranteed for size classes >= 256 bytes. On a 64-bit system, 256 bytes allocated is 32 pointers, the bits for which fit in 4 bytes. So MaxPtrmaskBytes must be >= 4.

We used to use 16 because the GC programs do have some constant overhead to get started, and processing 128 pointers seems to be enough to amortize that overhead well.

To make sure that the runtime's chansend can call typeBitsBulkBarrier, we raised the limit to 2048, so that even 32-bit systems are guaranteed to use bitmaps for objects up to 64 kB in size.

View Source
const SmallStackBufferSize = 32

SmallStackBufferSize is the shared compiler/runtime contract for caller-owned temporary buffers: bytes for slices/strings, rune slots for UTF-8 decoding.

View Source
const ZeroValSize = 1024

ZeroValSize is the size in bytes of runtime.zeroVal.

Variables

This section is empty.

Functions

func EscapeNonString

func EscapeNonString[T any](v T)

EscapeNonString is modeled by the compiler.

func EscapeToResultNonString

func EscapeToResultNonString[T any](v T) T

EscapeToResultNonString models a data-flow edge to the result.

func IsExported

func IsExported(name string) bool

IsExported reports whether name starts with an upper-case letter.

func NoEscape

func NoEscape(p unsafe.Pointer) unsafe.Pointer

Types

type ArrayType

type ArrayType struct {
	Type
	Elem  *Type // array element type
	Slice *Type // slice type
	Len   uintptr
}

ArrayType represents a fixed array type.

type ChanDir

type ChanDir int
const (
	RecvDir    ChanDir = 1 << iota         // <-chan
	SendDir                                // chan<-
	BothDir            = RecvDir | SendDir // chan
	InvalidDir ChanDir = 0
)

type ChanType

type ChanType struct {
	Type
	Elem *Type
	Dir  ChanDir
}

ChanType represents a channel type

type EmptyInterface

type EmptyInterface struct {
	Type *Type
	Data unsafe.Pointer
}

type FuncType

type FuncType struct {
	Type
	In  []*Type
	Out []*Type
}

FuncType represents a function type on targets that use libffi.

func (*FuncType) Variadic

func (p *FuncType) Variadic() bool

Variadic reports whether the function type is variadic.

type Imethod

type Imethod struct {
	Name_ string    // name of method
	Typ_  *FuncType // .(*FuncType) underneath
}

Imethod represents a method on an interface type

func (*Imethod) Exported

func (p *Imethod) Exported() bool

Exported reports whether the imethod is exported.

func (*Imethod) Name

func (p *Imethod) Name() string

Name returns the tag string for imethod.

func (*Imethod) PkgPath

func (p *Imethod) PkgPath() string

PkgPath returns the pkgpath string for imethod, or empty if there is none.

type InterfaceType

type InterfaceType struct {
	Type
	PkgPath_ string    // import path
	Methods  []Imethod // sorted by hash
}

type Kind

type Kind uint

A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.

const (
	Invalid Kind = iota
	Bool
	Int
	Int8
	Int16
	Int32
	Int64
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Uintptr
	Float32
	Float64
	Complex64
	Complex128
	Array
	Chan
	Func
	Interface
	Map
	Pointer
	Slice
	String
	Struct
	UnsafePointer
)

func (Kind) String

func (k Kind) String() string

String returns the name of k.

type MapType

type MapType struct {
	Type
	Key    *Type
	Elem   *Type
	Bucket *Type // internal type representing a hash bucket
	// function for hashing keys (ptr to key, seed) -> hash
	Hasher     func(unsafe.Pointer, uintptr) uintptr
	KeySize    uint8  // size of key slot
	ValueSize  uint8  // size of elem slot
	BucketSize uint16 // size of bucket
	Flags      uint32
}

func (*MapType) HashMightPanic

func (mt *MapType) HashMightPanic() bool

func (*MapType) IndirectElem

func (mt *MapType) IndirectElem() bool

func (*MapType) IndirectKey

func (mt *MapType) IndirectKey() bool

Note: flag values must match those used in the TMAP case in ../cmd/compile/internal/reflectdata/reflect.go:writeType.

func (*MapType) NeedKeyUpdate

func (mt *MapType) NeedKeyUpdate() bool

func (*MapType) ReflexiveKey

func (mt *MapType) ReflexiveKey() bool

type Method

type Method struct {
	Name_ string    // name of method
	Mtyp_ *FuncType // method type (without receiver)
	Ifn_  Text      // fn used in interface call (one-word receiver)
	Tfn_  Text      // fn used for normal method call
}

Method on non-interface type

func (*Method) Exported

func (p *Method) Exported() bool

Exported reports whether the method is exported.

func (*Method) Name

func (p *Method) Name() string

Name returns the tag string for method.

func (*Method) PkgPath

func (p *Method) PkgPath() string

PkgPath returns the pkgpath string for method, or empty if there is none.

type PtrType

type PtrType struct {
	Type
	Elem *Type // pointer element (pointed at) type
}

type QualifiedFuncType

type QualifiedFuncType struct {
	FuncType
	Public  *Type
	GoEntry unsafe.Pointer
}

QualifiedFuncType adds the public Go signature to an ABI-qualified function alias or a Go function whose frame contains such callbacks. GoEntry adapts a native pointer in a Go funcval's environment when the entry ABI differs.

type SliceType

type SliceType struct {
	Type
	Elem *Type // slice element type
}

type StructField

type StructField struct {
	Name_  string  // name is always non-empty
	Typ    *Type   // type of field
	Offset uintptr // byte offset of field

	Tag_      string
	Embedded_ bool
}

func (*StructField) Embedded

func (f *StructField) Embedded() bool

Embedded reports whether the field is embedded.

func (*StructField) Exported

func (f *StructField) Exported() bool

Exported reports whether the field is exported.

type StructType

type StructType struct {
	Type
	PkgPath_ string
	Fields   []StructField
}

type TFlag

type TFlag uint8

TFlag is used by a Type to signal what extra type information is available in the memory directly following the Type value.

const (
	// TFlagUncommon means that there is a data with a type, UncommonType,
	// just beyond the shared-per-type common data.  That is, the data
	// for struct types will store their UncommonType at one offset, the
	// data for interface types will store their UncommonType at a different
	// offset.  UncommonType is always accessed via a pointer that is computed
	// using trust-us-we-are-the-implementors pointer arithmetic.
	//
	// For example, if t.Kind() == Struct and t.tflag&TFlagUncommon != 0,
	// then t has UncommonType data and it can be accessed as:
	//
	//	type structTypeUncommon struct {
	//		structType
	//		u UncommonType
	//	}
	//	u := &(*structTypeUncommon)(unsafe.Pointer(t)).u
	TFlagUncommon TFlag = 1 << 0

	// TFlagExtraStar means the name in the str field has an
	// extraneous '*' prefix. This is because for most types T in
	// a program, the type *T also exists and reusing the str data
	// saves binary size.
	TFlagExtraStar TFlag = 1 << 1

	// TFlagNamed means the type has a name.
	TFlagNamed TFlag = 1 << 2

	// TFlagRegularMemory means that equal and hash functions can treat
	// this type as a single region of t.size bytes.
	TFlagRegularMemory TFlag = 1 << 3

	// TFlagVariadic means a funcType with variadic parameters
	TFlagVariadic TFlag = 1 << 4

	// TFlagClosure marks a struct descriptor for a Go closure.
	TFlagClosure TFlag = 1 << 5

	// On Func descriptors this kind-specific bit marks native signatures that
	// can call an environment-free Go entry without an ABI adapter.
	TFlagDirectGoCallback TFlag = TFlagClosure

	// TFlagNative means this declaration has a legacy cdecl/stdcall
	// storage and calling ABI. Go size and alignment queries may still
	// report the ordinary Go layout. Unlabeled wrappers are not marked;
	// consumers walk to this leaf.
	TFlagNative TFlag = 1 << 6

	// TFlagGCMaskOnDemand means that the GC pointer bitmask will be
	// computed on demand at runtime instead of being precomputed at
	// compile time. If this flag is set, the GCData field effectively
	// has type **byte instead of *byte. The runtime will store a
	// pointer to the GC pointer bitmask in *GCData.
	TFlagGCMaskOnDemand TFlag = 1 << 7
)

type Text

type Text = unsafe.Pointer // TODO(xsw): to be confirmed

type Type

type Type struct {
	Size_       uintptr
	PtrBytes    uintptr // number of (prefix) bytes in the type that can contain pointers
	Hash        uint32  // hash of type; avoids computation in hash tables
	TFlag       TFlag   // extra type information flags
	Align_      uint8   // alignment of variable with this type
	FieldAlign_ uint8   // alignment of struct field with this type
	Kind_       uint8   // enumeration for C
	// function for comparing objects of this type
	// (ptr to object A, ptr to object B) -> ==?
	Equal func(unsafe.Pointer, unsafe.Pointer) bool
	// GCData stores the GC type data for the garbage collector.
	// If the KindGCProg bit is set in kind, GCData is a GC program.
	// Otherwise it is a ptrmask bitmap. See mbitmap.go for details.
	GCData     *byte
	Str_       string // string form
	PtrToThis_ *Type  // type for pointer to this type, may be nil
}

Type is the runtime representation of a Go type.

Type is also referenced implicitly (in the form of expressions involving constants and arch.PtrSize) in cmd/compile/internal/reflectdata/reflect.go and cmd/link/internal/ld/decodesym.go (e.g. data[2*arch.PtrSize+4] references the TFlag field) unsafe.OffsetOf(Type{}.TFlag) cannot be used directly in those places because it varies with cross compilation and experiments.

func TypeFor

func TypeFor[T any]() *Type

TypeFor returns the runtime Type for a type parameter.

func TypeOf

func TypeOf(a any) *Type

TypeOf returns the runtime Type of some value.

func (*Type) Align

func (t *Type) Align() int

Align returns the alignment of data with type t.

func (*Type) ArrayType

func (t *Type) ArrayType() *ArrayType

ArrayType returns t cast to a *ArrayType, or nil if its tag does not match.

func (*Type) ChanDir

func (t *Type) ChanDir() ChanDir

ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).

func (*Type) Common

func (t *Type) Common() *Type

func (*Type) Elem

func (t *Type) Elem() *Type

Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.

func (*Type) ExportedMethods

func (t *Type) ExportedMethods() []Method

func (*Type) FieldAlign

func (t *Type) FieldAlign() int

func (*Type) FuncType

func (t *Type) FuncType() *FuncType

FuncType returns t cast to a *FuncType, or nil if its tag does not match.

func (*Type) GcSlice

func (t *Type) GcSlice(begin, end uintptr) []byte

func (*Type) HasName

func (t *Type) HasName() bool

func (*Type) HasNativeLayout

func (t *Type) HasNativeLayout() bool

HasNativeLayout reports whether t itself is marked with a legacy native ABI.

func (*Type) IfaceIndir

func (t *Type) IfaceIndir() bool

IfaceIndir reports whether t is stored indirectly in an interface value.

func (*Type) InterfaceType

func (t *Type) InterfaceType() *InterfaceType

InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match.

func (*Type) IsClosure

func (t *Type) IsClosure() bool

IsClosure reports whether t is closure struct

func (*Type) IsDirectIface

func (t *Type) IsDirectIface() bool

IsDirectIface reports whether t is stored directly in an interface value.

func (*Type) IsStdcall

func (t *Type) IsStdcall() bool

IsStdcall reports whether a native function type uses the stdcall ABI. Windows amd64 and arm64 use the default ABI even with this annotation.

func (*Type) Key

func (t *Type) Key() *Type

func (*Type) Kind

func (t *Type) Kind() Kind

func (*Type) Len

func (t *Type) Len() int

Len returns the length of t if t is an array type, otherwise 0

func (*Type) MapType

func (t *Type) MapType() *MapType

MapType returns t cast to a *MapType, or nil if its tag does not match.

func (*Type) NativeFuncAlias

func (t *Type) NativeFuncAlias() *QualifiedFuncType

func (*Type) NumMethod

func (t *Type) NumMethod() int

func (*Type) Pointers

func (t *Type) Pointers() bool

func (*Type) PublicFunc

func (t *Type) PublicFunc() *Type

PublicFunc returns the Go identity of an anonymous physical signature.

func (*Type) Size

func (t *Type) Size() uintptr

Size returns the size of data with type t.

func (*Type) String

func (t *Type) String() string

String returns string form of type t.

func (*Type) StructType

func (t *Type) StructType() *StructType

StructType returns t cast to a *StructType, or nil if its tag does not match.

func (*Type) Uncommon

func (t *Type) Uncommon() *UncommonType

Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil

type UncommonType

type UncommonType struct {
	PkgPath_ string // import path; empty for built-in types like int, string
	Mcount   uint16 // number of methods
	Xcount   uint16 // number of exported methods
	Moff     uint32 // offset from this uncommontype to [mcount]Method
}

UncommonType is present only for defined types or types with methods (if T is a defined type, the uncommonTypes for T and *T have methods). Using a pointer to this struct reduces the overall size required to describe a non-defined type with no methods.

func (*UncommonType) ExportedMethods

func (t *UncommonType) ExportedMethods() []Method

func (*UncommonType) Method

func (t *UncommonType) Method(i int) *Method

Method returns a pointer into t's method table without copying it. Callers must treat the referenced metadata as read-only. The table can be dynamically allocated; callers must keep its backing type metadata alive for as long as they use the returned pointer. It panics if i is out of range.

func (*UncommonType) Methods

func (t *UncommonType) Methods() []Method

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL