runtime

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 7 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 AppendTextMethod added in v0.11.2

func AppendTextMethod(typ reflect.Type) (reflect.Method, bool)

AppendTextMethod looks AppendText up.

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 IsStdMarshalerType added in v0.11.2

func IsStdMarshalerType(typ reflect.Type) bool

IsStdMarshalerType is whether the type, or the type it points to, is a named type of a package of the standard library whose marshalers are trusted: what MarshalJSON returns is valid and compact, AppendText appends what MarshalText returns, and UnmarshalJSON and UnmarshalText keep nothing of the bytes they are given.

func MarshalJSONMethod added in v0.11.2

func MarshalJSONMethod(typ reflect.Type) (reflect.Method, bool)

MarshalJSONMethod looks MarshalJSON up.

func MarshalTextMethod added in v0.11.2

func MarshalTextMethod(typ reflect.Type) (reflect.Method, bool)

MarshalTextMethod looks MarshalText up.

func PromotedStdMethod added in v0.11.2

func PromotedStdMethod(typ reflect.Type, method MethodLookup) (reflect.Type, uintptr, bool, bool)

PromotedStdMethod reports whether the method of the type which the lookup finds, or the one of the type it points to, is the method of a type of the standard library whose marshalers are trusted ( see IsStdMarshalerType ), which the type has by embedding it and doesn't declare itself: a call of the method then runs the method of that type, on the embedded value. It returns that type and, if the embedded value is in the value of the type ( embedded by value at every depth ), its offset in it, and whether it is so ( inline ), and whether the method is such a method. A type which declares the method, or which has it from more than one embedded type at one depth, is not such a type.

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.

func UnmarshalJSONMethod added in v0.11.2

func UnmarshalJSONMethod(typ reflect.Type) (reflect.Method, bool)

UnmarshalJSONMethod looks UnmarshalJSON up.

Types

type MethodLookup added in v0.11.2

type MethodLookup func(reflect.Type) (reflect.Method, bool)

MethodLookup looks the method of one name up in a type, by reflect.Type.MethodByName with the name as a constant.

The compiler tells the linker which names the calls of Method and MethodByName of reflect look up when it sees them as constants, and the linker keeps the methods of those names only. A call with any other argument makes the linker keep every exported method of every type of the program ( cmd/compile/internal/walk.usemethod ), so the methods are looked up by these functions, each with its name in its code, and never by a name in a variable.

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