runtime

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const TypeHashMultiplier = 0x9E3779B97F4A7C15

TypeHashMultiplier is the multiplier of the Fibonacci hashing of the address of a type: the top bits of the product spread the addresses, which are aligned and close to each other, over a table.

Variables

View Source
var HasAVX2 = detectAVX2()

HasAVX2 is whether the CPU and the OS support AVX2.

Functions

func IfaceIndir

func IfaceIndir(typ reflect.Type) bool

IfaceIndir reports whether a value of the type is stored indirectly in an interface value: the data word of the interface points to a copy of the value, instead of being the value itself.

Which types are stored directly is decided by the compiler and the rule depends on the Go version ( e.g. a struct of a zero-sized field and a pointer is direct since Go 1.26 ), so the rule is not reimplemented here. Instead, a value whose first word is a known pointer is converted to an interface value, and the data word tells how it was stored.

func IsIgnoredStructField

func IsIgnoredStructField(field reflect.StructField) bool

func TypeOfPtr added in v0.11.0

func TypeOfPtr(typ unsafe.Pointer) reflect.Type

TypeOfPtr converts the pointer to the type descriptor to reflect.Type. reflect.TypeOf reads only the type word of the interface value, so the data word is left nil.

func TypePtr added in v0.11.0

func TypePtr(t reflect.Type) unsafe.Pointer

TypePtr returns the pointer to the type descriptor of the type. It is the type word of an interface value which holds a value of the type, and it is what the functions of the runtime package take as a type.

Types

type SliceHeader

type SliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}

type StructTag

type StructTag struct {
	Key         string
	IsTaggedKey bool
	IsOmitEmpty bool
	// IsOmitZero is whether the field has the omitzero option, which encoding/json has from Go 1.24: it is
	// false with an older Go, whose encoding/json ignores the option.
	IsOmitZero bool
	IsString   bool
	Field      reflect.StructField
}

func StructTagFromField

func StructTagFromField(field reflect.StructField) *StructTag

type StructTags

type StructTags []*StructTag

func (StructTags) ExistsKey

func (t StructTags) ExistsKey(key string) bool

type TypeCache added in v0.11.0

type TypeCache[T any] struct {
	// contains filtered or unexported fields
}

TypeCache is a table of the values for the types, which is looked up by the address of a type without a lock.

It is a hash table with open addressing. It used to be an array which had a slot for every address a type of the program can be at, which was found from the type links of the runtime: that needed a linkname, a scan of every type at the start, memory in proportion to the size of the program, and a fallback for the types which are not in the type links. A lookup of this table costs about the same, and it has none of them.

The zero value is ready to use.

func (*TypeCache[T]) Load added in v0.11.0

func (c *TypeCache[T]) Load(typ uintptr) *T

Load returns the value for the type, or nil.

func (*TypeCache[T]) Store added in v0.11.0

func (c *TypeCache[T]) Store(typ uintptr, v *T) *T

Store sets the value for the type, and returns the value which the table has for the type: it is the value which was stored first if the type was compiled by more than one goroutine at a time.

Jump to

Keyboard shortcuts

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