go/src/reflect/type.go

type Type

type Kind

const Invalid

const Bool

const Int

const Int8

const Int16

const Int32

const Int64

const Uint

const Uint8

const Uint16

const Uint32

const Uint64

const Uintptr

const Float32

const Float64

const Complex64

const Complex128

const Array

const Chan

const Func

const Interface

const Map

const Pointer

const Slice

const String

const Struct

const UnsafePointer

const Ptr

type uncommonType

type common

type rtype

func (t *rtype) common() *abi.Type {}

func (t *rtype) uncommon() *abi.UncommonType {}

type aNameOff

type aTypeOff

type aTextOff

type ChanDir

const RecvDir

const SendDir

const BothDir

type arrayType

type chanType

type funcType

type interfaceType

func (t *interfaceType) nameOff(off aNameOff) abi.Name {}

func nameOffFor(t *abi.Type, off aNameOff) abi.Name {}

func typeOffFor(t *abi.Type, off aTypeOff) *abi.Type {}

func (t *interfaceType) typeOff(off aTypeOff) *abi.Type {}

func (t *interfaceType) common() *abi.Type {}

func (t *interfaceType) uncommon() *abi.UncommonType {}

type ptrType

type sliceType

type structField

type structType

func pkgPath(n abi.Name) string {}

func newName(n, tag string, exported, embedded bool) abi.Name {}

type Method

// IsExported reports whether the method is exported.
func (m Method) IsExported() bool {}

// String returns the name of k.
func (k Kind) String() string {}

var kindNames

// resolveNameOff resolves a name offset from a base pointer.
// The (*rtype).nameOff method is a convenience wrapper for this function.
// Implemented in the runtime package.
//
//go:noescape
func resolveNameOff(ptrInModule unsafe.Pointer, off int32) unsafe.Pointer

// resolveTypeOff resolves an *rtype offset from a base type.
// The (*rtype).typeOff method is a convenience wrapper for this function.
// Implemented in the runtime package.
//
//go:noescape
func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer

// resolveTextOff resolves a function pointer offset from a base type.
// The (*rtype).textOff method is a convenience wrapper for this function.
// Implemented in the runtime package.
//
//go:noescape
func resolveTextOff(rtype unsafe.Pointer, off int32) unsafe.Pointer

// addReflectOff adds a pointer to the reflection lookup map in the runtime.
// It returns a new ID that can be used as a typeOff or textOff, and will
// be resolved correctly. Implemented in the runtime package.
//
// addReflectOff should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
//   - github.com/goplus/reflectx
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname addReflectOff
//go:noescape
func addReflectOff(ptr unsafe.Pointer) int32

// resolveReflectName adds a name to the reflection lookup map in the runtime.
// It returns a new nameOff that can be used to refer to the pointer.
func resolveReflectName(n abi.Name) aNameOff {}

// resolveReflectType adds a *rtype to the reflection lookup map in the runtime.
// It returns a new typeOff that can be used to refer to the pointer.
func resolveReflectType(t *abi.Type) aTypeOff {}

// resolveReflectText adds a function pointer to the reflection lookup map in
// the runtime. It returns a new textOff that can be used to refer to the
// pointer.
func resolveReflectText(ptr unsafe.Pointer) aTextOff {}

func (t *rtype) nameOff(off aNameOff) abi.Name {}

func (t *rtype) typeOff(off aTypeOff) *abi.Type {}

func (t *rtype) textOff(off aTextOff) unsafe.Pointer {}

func textOffFor(t *abi.Type, off aTextOff) unsafe.Pointer {}

func (t *rtype) String() string {}

func (t *rtype) Size() uintptr {}

func (t *rtype) Bits() int {}

func (t *rtype) Align() int {}

func (t *rtype) FieldAlign() int {}

func (t *rtype) Kind() Kind {}

func (t *rtype) exportedMethods() []abi.Method {}

func (t *rtype) NumMethod() int {}

func (t *rtype) Method(i int) (m Method) {}

func (t *rtype) MethodByName(name string) (m Method, ok bool) {}

func (t *rtype) PkgPath() string {}

func pkgPathFor(t *abi.Type) string {}

func (t *rtype) Name() string {}

func nameFor(t *abi.Type) string {}

func (t *rtype) ChanDir() ChanDir {}

func toRType(t *abi.Type) *rtype {}

func elem(t *abi.Type) *abi.Type {}

func (t *rtype) Elem() Type {}

func (t *rtype) Field(i int) StructField {}

func (t *rtype) FieldByIndex(index []int) StructField {}

func (t *rtype) FieldByName(name string) (StructField, bool) {}

func (t *rtype) FieldByNameFunc(match func(string) bool) (StructField, bool) {}

func (t *rtype) Len() int {}

func (t *rtype) NumField() int {}

func (t *rtype) In(i int) Type {}

func (t *rtype) NumIn() int {}

func (t *rtype) NumOut() int {}

func (t *rtype) Out(i int) Type {}

func (t *rtype) IsVariadic() bool {}

func (t *rtype) OverflowComplex(x complex128) bool {}

func (t *rtype) OverflowFloat(x float64) bool {}

func (t *rtype) OverflowInt(x int64) bool {}

func (t *rtype) OverflowUint(x uint64) bool {}

func (t *rtype) CanSeq() bool {}

func canRangeFunc(t *abi.Type) bool {}

func (t *rtype) CanSeq2() bool {}

func canRangeFunc2(t *abi.Type) bool {}

// add returns p+x.
//
// The whySafe string is ignored, so that the function still inlines
// as efficiently as p+x, but all call sites should use the string to
// record why the addition is safe, which is to say why the addition
// does not cause x to advance to the very end of p's allocation
// and therefore point incorrectly at the next block in memory.
//
// add should be an internal detail (and is trivially copyable),
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
//   - github.com/pinpoint-apm/pinpoint-go-agent
//   - github.com/vmware/govmomi
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname add
func add(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {}

func (d ChanDir) String() string {}

// Method returns the i'th method in the type's method set.
func (t *interfaceType) Method(i int) (m Method) {}

// NumMethod returns the number of interface methods in the type's method set.
func (t *interfaceType) NumMethod() int {}

// MethodByName method with the given name in the type's method set.
func (t *interfaceType) MethodByName(name string) (m Method, ok bool) {}

type StructField

// IsExported reports whether the field is exported.
func (f StructField) IsExported() bool {}

type StructTag

// Get returns the value associated with key in the tag string.
// If there is no such key in the tag, Get returns the empty string.
// If the tag does not have the conventional format, the value
// returned by Get is unspecified. To determine whether a tag is
// explicitly set to the empty string, use [StructTag.Lookup].
func (tag StructTag) Get(key string) string {}

// Lookup returns the value associated with key in the tag string.
// If the key is present in the tag the value (which may be empty)
// is returned. Otherwise the returned value will be the empty string.
// The ok return value reports whether the value was explicitly set in
// the tag string. If the tag does not have the conventional format,
// the value returned by Lookup is unspecified.
func (tag StructTag) Lookup(key string) (value string, ok bool) {}

// Field returns the i'th struct field.
func (t *structType) Field(i int) (f StructField) {}

// getStaticuint64s returns a pointer to an array of 256 uint64 values,
// defined in the runtime package in read-only memory.
// staticuint64s[0] == 0, staticuint64s[1] == 1, and so forth.
//
//go:linkname getStaticuint64s runtime.getStaticuint64s
func getStaticuint64s() *[256]uint64

// FieldByIndex returns the nested field corresponding to index.
func (t *structType) FieldByIndex(index []int) (f StructField) {}

type fieldScan

// FieldByNameFunc returns the struct field with a name that satisfies the
// match function and a boolean to indicate if the field was found.
func (t *structType) FieldByNameFunc(match func(string) bool) (result StructField, ok bool) {}

// FieldByName returns the struct field with the given name
// and a boolean to indicate if the field was found.
func (t *structType) FieldByName(name string) (f StructField, present bool) {}

// TypeOf returns the reflection [Type] that represents the dynamic type of i.
// If i is a nil interface value, TypeOf returns nil.
func TypeOf(i any) Type {}

// rtypeOf directly extracts the *rtype of the provided value.
func rtypeOf(i any) *abi.Type {}

var ptrMap

// PtrTo returns the pointer type with element t.
// For example, if t represents type Foo, PtrTo(t) represents *Foo.
//
// PtrTo is the old spelling of [PointerTo].
// The two functions behave identically.
//
// Deprecated: Superseded by [PointerTo].
func PtrTo(t Type) Type {}

// PointerTo returns the pointer type with element t.
// For example, if t represents type Foo, PointerTo(t) represents *Foo.
func PointerTo(t Type) Type {}

func (t *rtype) ptrTo() *abi.Type {}

func ptrTo(t *abi.Type) *abi.Type {}

// fnv1 incorporates the list of bytes into the hash x using the FNV-1 hash function.
func fnv1(x uint32, list ...byte) uint32 {}

func (t *rtype) Implements(u Type) bool {}

func (t *rtype) AssignableTo(u Type) bool {}

func (t *rtype) ConvertibleTo(u Type) bool {}

func (t *rtype) Comparable() bool {}

// implements reports whether the type V implements the interface type T.
func implements(T, V *abi.Type) bool {}

// specialChannelAssignability reports whether a value x of channel type V
// can be directly assigned (using memmove) to another channel type T.
// https://golang.org/doc/go_spec.html#Assignability
// T and V must be both of Chan kind.
func specialChannelAssignability(T, V *abi.Type) bool {}

// directlyAssignable reports whether a value x of type V can be directly
// assigned (using memmove) to a value of type T.
// https://golang.org/doc/go_spec.html#Assignability
// Ignoring the interface rules (implemented elsewhere)
// and the ideal constant rules (no ideal constants at run time).
func directlyAssignable(T, V *abi.Type) bool {}

func haveIdenticalType(T, V *abi.Type, cmpTags bool) bool {}

func haveIdenticalUnderlyingType(T, V *abi.Type, cmpTags bool) bool {}

// typelinks is implemented in package runtime.
// It returns a slice of the sections in each module,
// and a slice of *rtype offsets in each module.
//
// The types in each module are sorted by string. That is, the first
// two linked types of the first module are:
//
//	d0 := sections[0]
//	t1 := (*rtype)(add(d0, offset[0][0]))
//	t2 := (*rtype)(add(d0, offset[0][1]))
//
// and
//
//	t1.String() < t2.String()
//
// Note that strings are not unique identifiers for types:
// there can be more than one with a given string.
// Only types we might want to look up are included:
// pointers, channels, maps, slices, and arrays.
func typelinks() (sections []unsafe.Pointer, offset [][]int32)

// rtypeOff should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
//   - github.com/goccy/go-json
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname rtypeOff
func rtypeOff(section unsafe.Pointer, off int32) *abi.Type {}

// typesByString returns the subslice of typelinks() whose elements have
// the given string representation.
// It may be empty (no known types with that string) or may have
// multiple elements (multiple types with that string).
//
// typesByString should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
//   - github.com/aristanetworks/goarista
//   - fortio.org/log
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname typesByString
func typesByString(s string) []*abi.Type {}

var lookupCache

type cacheKey

var funcLookupCache

// ChanOf returns the channel type with the given direction and element type.
// For example, if t represents int, ChanOf(RecvDir, t) represents <-chan int.
//
// The gc runtime imposes a limit of 64 kB on channel element types.
// If t's size is equal to or exceeds this limit, ChanOf panics.
func ChanOf(dir ChanDir, t Type) Type {}

var funcTypes

var funcTypesMutex

func initFuncTypes(n int) Type {}

// FuncOf returns the function type with the given argument and result types.
// For example if k represents int and e represents string,
// FuncOf([]Type{k}, []Type{e}, false) represents func(int) string.
//
// The variadic argument controls whether the function is variadic. FuncOf
// panics if the in[len(in)-1] does not represent a slice and variadic is
// true.
func FuncOf(in, out []Type, variadic bool) Type {}

func stringFor(t *abi.Type) string {}

// funcStr builds a string representation of a funcType.
func funcStr(ft *funcType) string {}

// isReflexive reports whether the == operation on the type is reflexive.
// That is, x == x for all values x of type t.
func isReflexive(t *abi.Type) bool {}

// needKeyUpdate reports whether map overwrites require the key to be copied.
func needKeyUpdate(t *abi.Type) bool {}

// hashMightPanic reports whether the hash of a map key of type t might panic.
func hashMightPanic(t *abi.Type) bool {}

func (t *rtype) gcSlice(begin, end uintptr) []byte {}

// emitGCMask writes the GC mask for [n]typ into out, starting at bit
// offset base.
func emitGCMask(out []byte, base uintptr, typ *abi.Type, n uintptr) {}

// appendGCProg appends the GC program for the first ptrdata bytes of
// typ to dst and returns the extended slice.
func appendGCProg(dst []byte, typ *abi.Type) []byte {}

// SliceOf returns the slice type with element type t.
// For example, if t represents int, SliceOf(t) represents []int.
func SliceOf(t Type) Type {}

var structLookupCache

type structTypeUncommon

// isLetter reports whether a given 'rune' is classified as a Letter.
func isLetter(ch rune) bool {}

// isValidFieldName checks if a string is a valid (struct) field name or not.
//
// According to the language spec, a field name should be an identifier.
//
// identifier = letter { letter | unicode_digit } .
// letter = unicode_letter | "_" .
func isValidFieldName(fieldName string) bool {}

// This must match cmd/compile/internal/compare.IsRegularMemory
func isRegularMemory(t Type) bool {}

// isPaddedField reports whether the i'th field of struct type t is followed
// by padding.
func isPaddedField(t Type, i int) bool {}

// StructOf returns the struct type containing fields.
// The Offset and Index fields are ignored and computed as they would be
// by the compiler.
//
// StructOf currently does not support promoted methods of embedded fields
// and panics if passed unexported StructFields.
func StructOf(fields []StructField) Type {}

func embeddedIfaceMethStub() {}

// runtimeStructField takes a StructField value passed to StructOf and
// returns both the corresponding internal representation, of type
// structField, and the pkgpath value to use for this field.
func runtimeStructField(field StructField) (structField, string) {}

// typeptrdata returns the length in bytes of the prefix of t
// containing pointer data. Anything after this offset is scalar data.
// keep in sync with ../cmd/compile/internal/reflectdata/reflect.go
func typeptrdata(t *abi.Type) uintptr {}

// ArrayOf returns the array type with the given length and element type.
// For example, if t represents int, ArrayOf(5, t) represents [5]int.
//
// If the resulting type would be larger than the available address space,
// ArrayOf panics.
func ArrayOf(length int, elem Type) Type {}

func appendVarint(x []byte, v uintptr) []byte {}

// toType converts from a *rtype to a Type that can be returned
// to the client of package reflect. In gc, the only concern is that
// a nil *rtype must be replaced by a nil Type, but in gccgo this
// function takes care of ensuring that multiple *rtype for the same
// type are coalesced into a single Type.
//
// toType should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
//   - fortio.org/log
//   - github.com/goccy/go-json
//   - github.com/goccy/go-reflect
//   - github.com/sohaha/zlsgo
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname toType
func toType(t *abi.Type) Type {}

type layoutKey

type layoutType

var layoutCache

// funcLayout computes a struct type representing the layout of the
// stack-assigned function arguments and return values for the function
// type t.
// If rcvr != nil, rcvr specifies the type of the receiver.
// The returned type exists only for GC, so we only fill out GC relevant info.
// Currently, that's just size and the GC program. We also fill in
// the name for possible debugging use.
func funcLayout(t *funcType, rcvr *abi.Type) (frametype *abi.Type, framePool *sync.Pool, abid abiDesc) {}

type bitVector

// append a bit to the bitmap.
func (bv *bitVector) append(bit uint8) {}

func addTypeBits(bv *bitVector, offset uintptr, t *abi.Type) {}

// TypeFor returns the [Type] that represents the type argument T.
func TypeFor[T any]() Type {}