Functions
Addr
method
#
Addr returns a pointer value representing the address of v.
It panics if [Value.CanAddr] returns false.
Addr is typically used to obtain a pointer to a struct field
or slice element in order to call a method that requires a
pointer receiver.
func (v Value) Addr() Value
Align
method
#
func (t *rtype) Align() int
Append
function
#
Append appends the values x to a slice s and returns the resulting slice.
As in Go, each x's value must be assignable to the slice's element type.
func Append(s Value, x ...Value) Value
AppendSlice
function
#
AppendSlice appends a slice t to a slice s and returns the resulting slice.
The slices s and t must have the same element type.
func AppendSlice(s Value, t Value) Value
ArenaNew
function
#
ArenaNew returns a [Value] representing a pointer to a new zero value for the
specified type, allocating storage for it in the provided arena. That is,
the returned Value's Type is [PointerTo](typ).
func ArenaNew(a *arena.Arena, typ Type) Value
ArrayOf
function
#
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
AssignableTo
method
#
func (t *rtype) AssignableTo(u Type) bool
Bits
method
#
func (t *rtype) Bits() int
Bool
method
#
Bool returns v's underlying value.
It panics if v's kind is not [Bool].
func (v Value) Bool() bool
Bytes
method
#
Bytes returns v's underlying value.
It panics if v's underlying value is not a slice of bytes or
an addressable array of bytes.
func (v Value) Bytes() []byte
Call
method
#
Call calls the function v with the input arguments in.
For example, if len(in) == 3, v.Call(in) represents the Go call v(in[0], in[1], in[2]).
Call panics if v's Kind is not [Func].
It returns the output results as Values.
As in Go, each input argument must be assignable to the
type of the function's corresponding input parameter.
If v is a variadic function, Call creates the variadic slice parameter
itself, copying in the corresponding values.
func (v Value) Call(in []Value) []Value
CallSlice
method
#
CallSlice calls the variadic function v with the input arguments in,
assigning the slice in[len(in)-1] to v's final variadic argument.
For example, if len(in) == 3, v.CallSlice(in) represents the Go call v(in[0], in[1], in[2]...).
CallSlice panics if v's Kind is not [Func] or if v is not variadic.
It returns the output results as Values.
As in Go, each input argument must be assignable to the
type of the function's corresponding input parameter.
func (v Value) CallSlice(in []Value) []Value
CanAddr
method
#
CanAddr reports whether the value's address can be obtained with [Value.Addr].
Such values are called addressable. A value is addressable if it is
an element of a slice, an element of an addressable array,
a field of an addressable struct, or the result of dereferencing a pointer.
If CanAddr returns false, calling [Value.Addr] will panic.
func (v Value) CanAddr() bool
CanComplex
method
#
CanComplex reports whether [Value.Complex] can be used without panicking.
func (v Value) CanComplex() bool
CanConvert
method
#
CanConvert reports whether the value v can be converted to type t.
If v.CanConvert(t) returns true then v.Convert(t) will not panic.
func (v Value) CanConvert(t Type) bool
CanFloat
method
#
CanFloat reports whether [Value.Float] can be used without panicking.
func (v Value) CanFloat() bool
CanInt
method
#
CanInt reports whether Int can be used without panicking.
func (v Value) CanInt() bool
CanInterface
method
#
CanInterface reports whether [Value.Interface] can be used without panicking.
func (v Value) CanInterface() bool
CanSeq
method
#
func (t *rtype) CanSeq() bool
CanSeq2
method
#
func (t *rtype) CanSeq2() bool
CanSet
method
#
CanSet reports whether the value of v can be changed.
A [Value] can be changed only if it is addressable and was not
obtained by the use of unexported struct fields.
If CanSet returns false, calling [Value.Set] or any type-specific
setter (e.g., [Value.SetBool], [Value.SetInt]) will panic.
func (v Value) CanSet() bool
CanUint
method
#
CanUint reports whether [Value.Uint] can be used without panicking.
func (v Value) CanUint() bool
Cap
method
#
Cap returns v's capacity.
It panics if v's Kind is not [Array], [Chan], [Slice] or pointer to [Array].
func (v Value) Cap() int
ChanDir
method
#
func (t *rtype) ChanDir() ChanDir
ChanOf
function
#
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
Clear
method
#
Clear clears the contents of a map or zeros the contents of a slice.
It panics if v's Kind is not [Map] or [Slice].
func (v Value) Clear()
Close
method
#
Close closes the channel v.
It panics if v's Kind is not [Chan] or
v is a receive-only channel.
func (v Value) Close()
Comparable
method
#
func (t *rtype) Comparable() bool
Comparable
method
#
Comparable reports whether the value v is comparable.
If the type of v is an interface, this checks the dynamic type.
If this reports true then v.Interface() == x will not panic for any x,
nor will v.Equal(u) for any Value u.
func (v Value) Comparable() bool
Complex
method
#
Complex returns v's underlying value, as a complex128.
It panics if v's Kind is not [Complex64] or [Complex128]
func (v Value) Complex() complex128
Convert
method
#
Convert returns the value v converted to type t.
If the usual Go conversion rules do not allow conversion
of the value v to type t, or if converting v to type t panics, Convert panics.
func (v Value) Convert(t Type) Value
ConvertibleTo
method
#
func (t *rtype) ConvertibleTo(u Type) bool
Copy
function
#
Copy copies the contents of src into dst until either
dst has been filled or src has been exhausted.
It returns the number of elements copied.
Dst and src each must have kind [Slice] or [Array], and
dst and src must have the same element type.
It dst is an [Array], it panics if [Value.CanSet] returns false.
As a special case, src can have kind [String] if the element type of dst is kind [Uint8].
func Copy(dst Value, src Value) int
DeepEqual
function
#
DeepEqual reports whether x and y are “deeply equal,” defined as follows.
Two values of identical type are deeply equal if one of the following cases applies.
Values of distinct types are never deeply equal.
Array values are deeply equal when their corresponding elements are deeply equal.
Struct values are deeply equal if their corresponding fields,
both exported and unexported, are deeply equal.
Func values are deeply equal if both are nil; otherwise they are not deeply equal.
Interface values are deeply equal if they hold deeply equal concrete values.
Map values are deeply equal when all of the following are true:
they are both nil or both non-nil, they have the same length,
and either they are the same map object or their corresponding keys
(matched using Go equality) map to deeply equal values.
Pointer values are deeply equal if they are equal using Go's == operator
or if they point to deeply equal values.
Slice values are deeply equal when all of the following are true:
they are both nil or both non-nil, they have the same length,
and either they point to the same initial entry of the same underlying array
(that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil))
are not deeply equal.
Other values - numbers, bools, strings, and channels - are deeply equal
if they are equal using Go's == operator.
In general DeepEqual is a recursive relaxation of Go's == operator.
However, this idea is impossible to implement without some inconsistency.
Specifically, it is possible for a value to be unequal to itself,
either because it is of func type (uncomparable in general)
or because it is a floating-point NaN value (not equal to itself in floating-point comparison),
or because it is an array, struct, or interface containing
such a value.
On the other hand, pointer values are always equal to themselves,
even if they point at or contain such problematic values,
because they compare equal using Go's == operator, and that
is a sufficient condition to be deeply equal, regardless of content.
DeepEqual has been defined so that the same short-cut applies
to slices and maps: if x and y are the same slice or the same map,
they are deeply equal regardless of content.
As DeepEqual traverses the data values it may find a cycle. The
second and subsequent times that DeepEqual compares two pointer
values that have been compared before, it treats the values as
equal rather than examining the values to which they point.
This ensures that DeepEqual terminates.
func DeepEqual(x any, y any) bool
Elem
method
#
Elem returns the value that the interface v contains
or that the pointer v points to.
It panics if v's Kind is not [Interface] or [Pointer].
It returns the zero Value if v is nil.
func (v Value) Elem() Value
Elem
method
#
func (t *rtype) Elem() Type
Equal
method
#
Equal reports true if v is equal to u.
For two invalid values, Equal will report true.
For an interface value, Equal will compare the value within the interface.
Otherwise, If the values have different types, Equal will report false.
Otherwise, for arrays and structs Equal will compare each element in order,
and report false if it finds non-equal elements.
During all comparisons, if values of the same type are compared,
and the type is not comparable, Equal will panic.
func (v Value) Equal(u Value) bool
Error
method
#
func (e *ValueError) Error() string
Field
method
#
Field returns the i'th field of the struct v.
It panics if v's Kind is not [Struct] or i is out of range.
func (v Value) Field(i int) Value
Field
method
#
func (t *rtype) Field(i int) StructField
Field
method
#
Field returns the i'th struct field.
func (t *structType) Field(i int) (f StructField)
FieldAlign
method
#
func (t *rtype) FieldAlign() int
FieldByIndex
method
#
func (t *rtype) FieldByIndex(index []int) StructField
FieldByIndex
method
#
FieldByIndex returns the nested field corresponding to index.
It panics if evaluation requires stepping through a nil
pointer or a field that is not a struct.
func (v Value) FieldByIndex(index []int) Value
FieldByIndex
method
#
FieldByIndex returns the nested field corresponding to index.
func (t *structType) FieldByIndex(index []int) (f StructField)
FieldByIndexErr
method
#
FieldByIndexErr returns the nested field corresponding to index.
It returns an error if evaluation requires stepping through a nil
pointer, but panics if it must step through a field that
is not a struct.
func (v Value) FieldByIndexErr(index []int) (Value, error)
FieldByName
method
#
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)
FieldByName
method
#
func (t *rtype) FieldByName(name string) (StructField, bool)
FieldByName
method
#
FieldByName returns the struct field with the given name.
It returns the zero Value if no field was found.
It panics if v's Kind is not [Struct].
func (v Value) FieldByName(name string) Value
FieldByNameFunc
method
#
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)
FieldByNameFunc
method
#
FieldByNameFunc returns the struct field with a name
that satisfies the match function.
It panics if v's Kind is not [Struct].
It returns the zero Value if no field was found.
func (v Value) FieldByNameFunc(match func(string) bool) Value
FieldByNameFunc
method
#
func (t *rtype) FieldByNameFunc(match func(string) bool) (StructField, bool)
Float
method
#
Float returns v's underlying value, as a float64.
It panics if v's Kind is not [Float32] or [Float64]
func (v Value) Float() float64
FuncOf
function
#
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 []Type, out []Type, variadic bool) Type
Get
method
#
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
Grow
method
#
Grow increases the slice's capacity, if necessary, to guarantee space for
another n elements. After Grow(n), at least n elements can be appended
to the slice without another allocation.
It panics if v's Kind is not a [Slice], or if n is negative or too large to
allocate the memory, or if [Value.CanSet] returns false.
func (v Value) Grow(n int)
Implements
method
#
func (t *rtype) Implements(u Type) bool
In
method
#
func (t *rtype) In(i int) Type
Index
method
#
Index returns v's i'th element.
It panics if v's Kind is not [Array], [Slice], or [String] or i is out of range.
func (v Value) Index(i int) Value
Indirect
function
#
Indirect returns the value that v points to.
If v is a nil pointer, Indirect returns a zero Value.
If v is not a pointer, Indirect returns v.
func Indirect(v Value) Value
Int
method
#
Int returns v's underlying value, as an int64.
It panics if v's Kind is not [Int], [Int8], [Int16], [Int32], or [Int64].
func (v Value) Int() int64
Interface
method
#
Interface returns v's current value as an interface{}.
It is equivalent to:
var i interface{} = (v's underlying value)
It panics if the Value was obtained by accessing
unexported struct fields.
func (v Value) Interface() (i any)
InterfaceData
method
#
InterfaceData returns a pair of unspecified uintptr values.
It panics if v's Kind is not Interface.
In earlier versions of Go, this function returned the interface's
value as a uintptr pair. As of Go 1.4, the implementation of
interface values precludes any defined use of InterfaceData.
Deprecated: The memory representation of interface values is not
compatible with InterfaceData.
func (v Value) InterfaceData() [2]uintptr
IsExported
method
#
IsExported reports whether the field is exported.
func (f StructField) IsExported() bool
IsExported
method
#
IsExported reports whether the method is exported.
func (m Method) IsExported() bool
IsNil
method
#
IsNil reports whether its argument v is nil. The argument must be
a chan, func, interface, map, pointer, or slice value; if it is
not, IsNil panics. Note that IsNil is not always equivalent to a
regular comparison with nil in Go. For example, if v was created
by calling [ValueOf] with an uninitialized interface variable i,
i==nil will be true but v.IsNil will panic as v will be the zero
Value.
func (v Value) IsNil() bool
IsValid
method
#
IsValid reports whether v represents a value.
It returns false if v is the zero Value.
If [Value.IsValid] returns false, all other methods except String panic.
Most functions and methods never return an invalid Value.
If one does, its documentation states the conditions explicitly.
func (v Value) IsValid() bool
IsVariadic
method
#
func (t *rtype) IsVariadic() bool
IsZero
method
#
IsZero reports whether v is the zero value for its type.
It panics if the argument is invalid.
func (v Value) IsZero() bool
Key
method
#
Key returns the key of iter's current map entry.
func (iter *MapIter) Key() Value
Key
method
#
func (t *rtype) Key() Type
Key
method
#
func (t *rtype) Key() Type
Key
method
#
Key returns the key of iter's current map entry.
func (iter *MapIter) Key() Value
Kind
method
#
Kind returns v's Kind.
If v is the zero Value ([Value.IsValid] returns false), Kind returns Invalid.
func (v Value) Kind() Kind
Kind
method
#
func (t *rtype) Kind() Kind
Len
method
#
Len returns v's length.
It panics if v's Kind is not [Array], [Chan], [Map], [Slice], [String], or pointer to [Array].
func (v Value) Len() int
Len
method
#
func (t *rtype) Len() int
Lookup
method
#
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)
MakeChan
function
#
MakeChan creates a new channel with the specified type and buffer size.
func MakeChan(typ Type, buffer int) Value
MakeFunc
function
#
MakeFunc returns a new function of the given [Type]
that wraps the function fn. When called, that new function
does the following:
- converts its arguments to a slice of Values.
- runs results := fn(args).
- returns the results as a slice of Values, one per formal result.
The implementation fn can assume that the argument [Value] slice
has the number and type of arguments given by typ.
If typ describes a variadic function, the final Value is itself
a slice representing the variadic arguments, as in the
body of a variadic function. The result Value slice returned by fn
must have the number and type of results given by typ.
The [Value.Call] method allows the caller to invoke a typed function
in terms of Values; in contrast, MakeFunc allows the caller to implement
a typed function in terms of Values.
The Examples section of the documentation includes an illustration
of how to use MakeFunc to build a swap function for different types.
func MakeFunc(typ Type, fn func(args []Value) results []Value) Value
MakeMap
function
#
MakeMap creates a new map with the specified type.
func MakeMap(typ Type) Value
MakeMapWithSize
function
#
MakeMapWithSize creates a new map with the specified type
and initial space for approximately n elements.
func MakeMapWithSize(typ Type, n int) Value
MakeSlice
function
#
MakeSlice creates a new zero-initialized slice value
for the specified slice type, length, and capacity.
func MakeSlice(typ Type, len int, cap int) Value
MapIndex
method
#
MapIndex returns the value associated with key in the map v.
It panics if v's Kind is not [Map].
It returns the zero Value if key is not found in the map or if v represents a nil map.
As in Go, the key's value must be assignable to the map's key type.
func (v Value) MapIndex(key Value) Value
MapIndex
method
#
MapIndex returns the value associated with key in the map v.
It panics if v's Kind is not [Map].
It returns the zero Value if key is not found in the map or if v represents a nil map.
As in Go, the key's value must be assignable to the map's key type.
func (v Value) MapIndex(key Value) Value
MapKeys
method
#
MapKeys returns a slice containing all the keys present in the map,
in unspecified order.
It panics if v's Kind is not [Map].
It returns an empty slice if v represents a nil map.
func (v Value) MapKeys() []Value
MapKeys
method
#
MapKeys returns a slice containing all the keys present in the map,
in unspecified order.
It panics if v's Kind is not [Map].
It returns an empty slice if v represents a nil map.
func (v Value) MapKeys() []Value
MapOf
function
#
MapOf returns the map type with the given key and element types.
For example, if k represents int and e represents string,
MapOf(k, e) represents map[int]string.
If the key type is not a valid map key type (that is, if it does
not implement Go's == operator), MapOf panics.
func MapOf(key Type, elem Type) Type
MapOf
function
#
MapOf returns the map type with the given key and element types.
For example, if k represents int and e represents string,
MapOf(k, e) represents map[int]string.
If the key type is not a valid map key type (that is, if it does
not implement Go's == operator), MapOf panics.
func MapOf(key Type, elem Type) Type
MapRange
method
#
MapRange returns a range iterator for a map.
It panics if v's Kind is not [Map].
Call [MapIter.Next] to advance the iterator, and [MapIter.Key]/[MapIter.Value] to access each entry.
[MapIter.Next] returns false when the iterator is exhausted.
MapRange follows the same iteration semantics as a range statement.
Example:
iter := reflect.ValueOf(m).MapRange()
for iter.Next() {
k := iter.Key()
v := iter.Value()
...
}
func (v Value) MapRange() *MapIter
MapRange
method
#
MapRange returns a range iterator for a map.
It panics if v's Kind is not [Map].
Call [MapIter.Next] to advance the iterator, and [MapIter.Key]/[MapIter.Value] to access each entry.
[MapIter.Next] returns false when the iterator is exhausted.
MapRange follows the same iteration semantics as a range statement.
Example:
iter := reflect.ValueOf(m).MapRange()
for iter.Next() {
k := iter.Key()
v := iter.Value()
...
}
func (v Value) MapRange() *MapIter
Method
method
#
func (t *rtype) Method(i int) (m Method)
Method
method
#
Method returns the i'th method in the type's method set.
func (t *interfaceType) Method(i int) (m Method)
Method
method
#
Method returns a function value corresponding to v's i'th method.
The arguments to a Call on the returned function should not include
a receiver; the returned function will always use v as the receiver.
Method panics if i is out of range or if v is a nil interface value.
func (v Value) Method(i int) Value
MethodByName
method
#
MethodByName returns a function value corresponding to the method
of v with the given name.
The arguments to a Call on the returned function should not include
a receiver; the returned function will always use v as the receiver.
It returns the zero Value if no method was found.
func (v Value) MethodByName(name string) Value
MethodByName
method
#
func (t *rtype) MethodByName(name string) (m Method, ok bool)
MethodByName
method
#
MethodByName method with the given name in the type's method set.
func (t *interfaceType) MethodByName(name string) (m Method, ok bool)
Name
method
#
func (t *rtype) Name() string
New
function
#
New returns a Value representing a pointer to a new zero value
for the specified type. That is, the returned Value's Type is [PointerTo](typ).
func New(typ Type) Value
NewAt
function
#
NewAt returns a Value representing a pointer to a value of the
specified type, using p as that pointer.
func NewAt(typ Type, p unsafe.Pointer) Value
Next
method
#
Next advances the map iterator and reports whether there is another
entry. It returns false when iter is exhausted; subsequent
calls to [MapIter.Key], [MapIter.Value], or [MapIter.Next] will panic.
func (iter *MapIter) Next() bool
Next
method
#
Next advances the map iterator and reports whether there is another
entry. It returns false when iter is exhausted; subsequent
calls to [MapIter.Key], [MapIter.Value], or [MapIter.Next] will panic.
func (iter *MapIter) Next() bool
NumField
method
#
NumField returns the number of fields in the struct v.
It panics if v's Kind is not [Struct].
func (v Value) NumField() int
NumField
method
#
func (t *rtype) NumField() int
NumIn
method
#
func (t *rtype) NumIn() int
NumMethod
method
#
NumMethod returns the number of methods in the value's method set.
For a non-interface type, it returns the number of exported methods.
For an interface type, it returns the number of exported and unexported methods.
func (v Value) NumMethod() int
NumMethod
method
#
func (t *rtype) NumMethod() int
NumMethod
method
#
NumMethod returns the number of interface methods in the type's method set.
func (t *interfaceType) NumMethod() int
NumOut
method
#
func (t *rtype) NumOut() int
Out
method
#
func (t *rtype) Out(i int) Type
OverflowComplex
method
#
func (t *rtype) OverflowComplex(x complex128) bool
OverflowComplex
method
#
OverflowComplex reports whether the complex128 x cannot be represented by v's type.
It panics if v's Kind is not [Complex64] or [Complex128].
func (v Value) OverflowComplex(x complex128) bool
OverflowFloat
method
#
OverflowFloat reports whether the float64 x cannot be represented by v's type.
It panics if v's Kind is not [Float32] or [Float64].
func (v Value) OverflowFloat(x float64) bool
OverflowFloat
method
#
func (t *rtype) OverflowFloat(x float64) bool
OverflowInt
method
#
func (t *rtype) OverflowInt(x int64) bool
OverflowInt
method
#
OverflowInt reports whether the int64 x cannot be represented by v's type.
It panics if v's Kind is not [Int], [Int8], [Int16], [Int32], or [Int64].
func (v Value) OverflowInt(x int64) bool
OverflowUint
method
#
OverflowUint reports whether the uint64 x cannot be represented by v's type.
It panics if v's Kind is not [Uint], [Uintptr], [Uint8], [Uint16], [Uint32], or [Uint64].
func (v Value) OverflowUint(x uint64) bool
OverflowUint
method
#
func (t *rtype) OverflowUint(x uint64) bool
PkgPath
method
#
func (t *rtype) PkgPath() string
Pointer
method
#
Pointer returns v's value as a uintptr.
It panics if v's Kind is not [Chan], [Func], [Map], [Pointer], [Slice], [String], or [UnsafePointer].
If v's Kind is [Func], the returned pointer is an underlying
code pointer, but not necessarily enough to identify a
single function uniquely. The only guarantee is that the
result is zero if and only if v is a nil func Value.
If v's Kind is [Slice], the returned pointer is to the first
element of the slice. If the slice is nil the returned value
is 0. If the slice is empty but non-nil the return value is non-zero.
If v's Kind is [String], the returned pointer is to the first
element of the underlying bytes of string.
It's preferred to use uintptr(Value.UnsafePointer()) to get the equivalent result.
func (v Value) Pointer() uintptr
PointerTo
function
#
PointerTo returns the pointer type with element t.
For example, if t represents type Foo, PointerTo(t) represents *Foo.
func PointerTo(t Type) Type
PtrTo
function
#
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
Recv
method
#
Recv receives and returns a value from the channel v.
It panics if v's Kind is not [Chan].
The receive blocks until a value is ready.
The boolean value ok is true if the value x corresponds to a send
on the channel, false if it is a zero value received because the channel is closed.
func (v Value) Recv() (x Value, ok bool)
Reset
method
#
Reset modifies iter to iterate over v.
It panics if v's Kind is not [Map] and v is not the zero Value.
Reset(Value{}) causes iter to not to refer to any map,
which may allow the previously iterated-over map to be garbage collected.
func (iter *MapIter) Reset(v Value)
Reset
method
#
Reset modifies iter to iterate over v.
It panics if v's Kind is not [Map] and v is not the zero Value.
Reset(Value{}) causes iter to not to refer to any map,
which may allow the previously iterated-over map to be garbage collected.
func (iter *MapIter) Reset(v Value)
Select
function
#
Select executes a select operation described by the list of cases.
Like the Go select statement, it blocks until at least one of the cases
can proceed, makes a uniform pseudo-random choice,
and then executes that case. It returns the index of the chosen case
and, if that case was a receive operation, the value received and a
boolean indicating whether the value corresponds to a send on the channel
(as opposed to a zero value received because the channel is closed).
Select supports a maximum of 65536 cases.
func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)
Send
method
#
Send sends x on the channel v.
It panics if v's kind is not [Chan] or if x's type is not the same type as v's element type.
As in Go, x's value must be assignable to the channel's element type.
func (v Value) Send(x Value)
Seq
method
#
Seq returns an iter.Seq[Value] that loops over the elements of v.
If v's kind is Func, it must be a function that has no results and
that takes a single argument of type func(T) bool for some type T.
If v's kind is Pointer, the pointer element type must have kind Array.
Otherwise v's kind must be Int, Int8, Int16, Int32, Int64,
Uint, Uint8, Uint16, Uint32, Uint64, Uintptr,
Array, Chan, Map, Slice, or String.
func (v Value) Seq() *ast.IndexExpr
Seq2
method
#
Seq2 returns an iter.Seq2[Value, Value] that loops over the elements of v.
If v's kind is Func, it must be a function that has no results and
that takes a single argument of type func(K, V) bool for some type K, V.
If v's kind is Pointer, the pointer element type must have kind Array.
Otherwise v's kind must be Array, Map, Slice, or String.
func (v Value) Seq2() *ast.IndexListExpr
Set
method
#
Set assigns x to the value v.
It panics if [Value.CanSet] returns false.
As in Go, x's value must be assignable to v's type and
must not be derived from an unexported field.
func (v Value) Set(x Value)
SetBool
method
#
SetBool sets v's underlying value.
It panics if v's Kind is not [Bool] or if [Value.CanSet] returns false.
func (v Value) SetBool(x bool)
SetBytes
method
#
SetBytes sets v's underlying value.
It panics if v's underlying value is not a slice of bytes
or if [Value.CanSet] returns false.
func (v Value) SetBytes(x []byte)
SetCap
method
#
SetCap sets v's capacity to n.
It panics if v's Kind is not [Slice], or if n is smaller than the length or
greater than the capacity of the slice,
or if [Value.CanSet] returns false.
func (v Value) SetCap(n int)
SetComplex
method
#
SetComplex sets v's underlying value to x.
It panics if v's Kind is not [Complex64] or [Complex128],
or if [Value.CanSet] returns false.
func (v Value) SetComplex(x complex128)
SetFloat
method
#
SetFloat sets v's underlying value to x.
It panics if v's Kind is not [Float32] or [Float64],
or if [Value.CanSet] returns false.
func (v Value) SetFloat(x float64)
SetInt
method
#
SetInt sets v's underlying value to x.
It panics if v's Kind is not [Int], [Int8], [Int16], [Int32], or [Int64],
or if [Value.CanSet] returns false.
func (v Value) SetInt(x int64)
SetIterKey
method
#
SetIterKey assigns to v the key of iter's current map entry.
It is equivalent to v.Set(iter.Key()), but it avoids allocating a new Value.
As in Go, the key must be assignable to v's type and
must not be derived from an unexported field.
It panics if [Value.CanSet] returns false.
func (v Value) SetIterKey(iter *MapIter)
SetIterKey
method
#
SetIterKey assigns to v the key of iter's current map entry.
It is equivalent to v.Set(iter.Key()), but it avoids allocating a new Value.
As in Go, the key must be assignable to v's type and
must not be derived from an unexported field.
It panics if [Value.CanSet] returns false.
func (v Value) SetIterKey(iter *MapIter)
SetIterValue
method
#
SetIterValue assigns to v the value of iter's current map entry.
It is equivalent to v.Set(iter.Value()), but it avoids allocating a new Value.
As in Go, the value must be assignable to v's type and
must not be derived from an unexported field.
It panics if [Value.CanSet] returns false.
func (v Value) SetIterValue(iter *MapIter)
SetIterValue
method
#
SetIterValue assigns to v the value of iter's current map entry.
It is equivalent to v.Set(iter.Value()), but it avoids allocating a new Value.
As in Go, the value must be assignable to v's type and
must not be derived from an unexported field.
It panics if [Value.CanSet] returns false.
func (v Value) SetIterValue(iter *MapIter)
SetLen
method
#
SetLen sets v's length to n.
It panics if v's Kind is not [Slice], or if n is negative or
greater than the capacity of the slice,
or if [Value.CanSet] returns false.
func (v Value) SetLen(n int)
SetMapIndex
method
#
SetMapIndex sets the element associated with key in the map v to elem.
It panics if v's Kind is not [Map].
If elem is the zero Value, SetMapIndex deletes the key from the map.
Otherwise if v holds a nil map, SetMapIndex will panic.
As in Go, key's elem must be assignable to the map's key type,
and elem's value must be assignable to the map's elem type.
func (v Value) SetMapIndex(key Value, elem Value)
SetMapIndex
method
#
SetMapIndex sets the element associated with key in the map v to elem.
It panics if v's Kind is not [Map].
If elem is the zero Value, SetMapIndex deletes the key from the map.
Otherwise if v holds a nil map, SetMapIndex will panic.
As in Go, key's elem must be assignable to the map's key type,
and elem's value must be assignable to the map's elem type.
func (v Value) SetMapIndex(key Value, elem Value)
SetPointer
method
#
SetPointer sets the [unsafe.Pointer] value v to x.
It panics if v's Kind is not [UnsafePointer]
or if [Value.CanSet] returns false.
func (v Value) SetPointer(x unsafe.Pointer)
SetString
method
#
SetString sets v's underlying value to x.
It panics if v's Kind is not [String] or if [Value.CanSet] returns false.
func (v Value) SetString(x string)
SetUint
method
#
SetUint sets v's underlying value to x.
It panics if v's Kind is not [Uint], [Uintptr], [Uint8], [Uint16], [Uint32], or [Uint64],
or if [Value.CanSet] returns false.
func (v Value) SetUint(x uint64)
SetZero
method
#
SetZero sets v to be the zero value of v's type.
It panics if [Value.CanSet] returns false.
func (v Value) SetZero()
Size
method
#
func (t *rtype) Size() uintptr
Slice
method
#
Slice returns v[i:j].
It panics if v's Kind is not [Array], [Slice] or [String], or if v is an unaddressable array,
or if the indexes are out of bounds.
func (v Value) Slice(i int, j int) Value
Slice3
method
#
Slice3 is the 3-index form of the slice operation: it returns v[i:j:k].
It panics if v's Kind is not [Array] or [Slice], or if v is an unaddressable array,
or if the indexes are out of bounds.
func (v Value) Slice3(i int, j int, k int) Value
SliceAt
function
#
SliceAt returns a [Value] representing a slice whose underlying
data starts at p, with length and capacity equal to n.
This is like [unsafe.Slice].
func SliceAt(typ Type, p unsafe.Pointer, n int) Value
SliceOf
function
#
SliceOf returns the slice type with element type t.
For example, if t represents int, SliceOf(t) represents []int.
func SliceOf(t Type) Type
String
method
#
String returns the name of k.
func (k Kind) String() string
String
method
#
func (t *rtype) String() string
String
method
#
func (d ChanDir) String() string
String
method
#
String returns the string v's underlying value, as a string.
String is a special case because of Go's String method convention.
Unlike the other getters, it does not panic if v's Kind is not [String].
Instead, it returns a string of the form "" where T is v's type.
The fmt package treats Values specially. It does not call their String
method implicitly but instead prints the concrete values they hold.
func (v Value) String() string
StructOf
function
#
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
Swapper
function
#
Swapper returns a function that swaps the elements in the provided
slice.
Swapper panics if the provided interface is not a slice.
func Swapper(slice any) (func(i int, j int))
TryRecv
method
#
TryRecv attempts to receive a value from the channel v but will not block.
It panics if v's Kind is not [Chan].
If the receive delivers a value, x is the transferred value and ok is true.
If the receive cannot finish without blocking, x is the zero Value and ok is false.
If the channel is closed, x is the zero value for the channel's element type and ok is false.
func (v Value) TryRecv() (x Value, ok bool)
TrySend
method
#
TrySend attempts to send x on the channel v but will not block.
It panics if v's Kind is not [Chan].
It reports whether the value was sent.
As in Go, x's value must be assignable to the channel's element type.
func (v Value) TrySend(x Value) bool
Type
method
#
Type returns v's type.
func (v Value) Type() Type
TypeFor
function
#
TypeFor returns the [Type] that represents the type argument T.
func TypeFor() Type
TypeOf
function
#
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
Uint
method
#
Uint returns v's underlying value, as a uint64.
It panics if v's Kind is not [Uint], [Uintptr], [Uint8], [Uint16], [Uint32], or [Uint64].
func (v Value) Uint() uint64
UnsafeAddr
method
#
UnsafeAddr returns a pointer to v's data, as a uintptr.
It panics if v is not addressable.
It's preferred to use uintptr(Value.Addr().UnsafePointer()) to get the equivalent result.
func (v Value) UnsafeAddr() uintptr
UnsafePointer
method
#
UnsafePointer returns v's value as a [unsafe.Pointer].
It panics if v's Kind is not [Chan], [Func], [Map], [Pointer], [Slice], [String] or [UnsafePointer].
If v's Kind is [Func], the returned pointer is an underlying
code pointer, but not necessarily enough to identify a
single function uniquely. The only guarantee is that the
result is zero if and only if v is a nil func Value.
If v's Kind is [Slice], the returned pointer is to the first
element of the slice. If the slice is nil the returned value
is nil. If the slice is empty but non-nil the return value is non-nil.
If v's Kind is [String], the returned pointer is to the first
element of the underlying bytes of string.
func (v Value) UnsafePointer() unsafe.Pointer
Value
method
#
Value returns the value of iter's current map entry.
func (iter *MapIter) Value() Value
Value
method
#
Value returns the value of iter's current map entry.
func (iter *MapIter) Value() Value
ValueOf
function
#
ValueOf returns a new Value initialized to the concrete value
stored in the interface i. ValueOf(nil) returns the zero Value.
func ValueOf(i any) Value
VisibleFields
function
#
VisibleFields returns all the visible fields in t, which must be a
struct type. A field is defined as visible if it's accessible
directly with a FieldByName call. The returned fields include fields
inside anonymous struct members and unexported fields. They follow
the same order found in the struct, with anonymous fields followed
immediately by their promoted fields.
For each element e of the returned slice, the corresponding field
can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index).
func VisibleFields(t Type) []StructField
Zero
function
#
Zero returns a Value representing the zero value for the specified type.
The result is different from the zero value of the Value struct,
which represents no value at all.
For example, Zero(TypeOf(42)) returns a Value with Kind [Int] and value 0.
The returned value is neither addressable nor settable.
func Zero(typ Type) Value
abiType
method
#
func (v Value) abiType() *abi.Type
abiTypeSlow
method
#
func (v Value) abiTypeSlow() *abi.Type
add
function
#
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
addArg
method
#
addArg extends the abiSeq with a new Go value of type t.
If the value was stack-assigned, returns the single
abiStep describing that translation, and nil otherwise.
func (a *abiSeq) addArg(t *abi.Type) *abiStep
addRcvr
method
#
addRcvr extends the abiSeq with a new method call
receiver according to the interface calling convention.
If the receiver was stack-assigned, returns the single
abiStep describing that translation, and nil otherwise.
Returns true if the receiver is a pointer.
func (a *abiSeq) addRcvr(rcvr *abi.Type) (*abiStep, bool)
addReflectOff
function
#
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
addTypeBits
function
#
func addTypeBits(bv *bitVector, offset uintptr, t *abi.Type)
align
function
#
align returns the result of rounding x up to a multiple of n.
n must be a power of two.
func align(x uintptr, n uintptr) uintptr
append
method
#
append a bit to the bitmap.
func (bv *bitVector) append(bit uint8)
appendVarint
function
#
func appendVarint(x []byte, v uintptr) []byte
archFloat32FromReg
function
#
func archFloat32FromReg(reg uint64) float32
archFloat32FromReg
function
#
func archFloat32FromReg(reg uint64) float32
archFloat32FromReg
function
#
func archFloat32FromReg(reg uint64) float32
archFloat32ToReg
function
#
func archFloat32ToReg(val float32) uint64
archFloat32ToReg
function
#
func archFloat32ToReg(val float32) uint64
archFloat32ToReg
function
#
func archFloat32ToReg(val float32) uint64
arena_New
function
#
func arena_New(a *arena.Arena, typ any) any
arrayAt
function
#
arrayAt returns the i-th element of p,
an array whose elements are eltSize bytes wide.
The array pointed at by p must have at least i+1 elements:
it is invalid (but impossible to check here) to pass i >= len,
because then the result will point outside the array.
whySafe must explain why i < len. (Passing "i < len" is fine;
the benefit is to surface this assumption at the call site.)
func arrayAt(p unsafe.Pointer, i int, eltSize uintptr, whySafe string) unsafe.Pointer
assignFloatN
method
#
assignFloatN assigns n values to registers, each "size" bytes large,
from the data at [offset, offset+n*size) in memory. Each value at
[offset+i*size, offset+(i+1)*size) for i < n is assigned to the
next n floating-point registers.
Returns whether assignment succeeded.
func (a *abiSeq) assignFloatN(offset uintptr, size uintptr, n int) bool
assignIntN
method
#
assignIntN assigns n values to registers, each "size" bytes large,
from the data at [offset, offset+n*size) in memory. Each value at
[offset+i*size, offset+(i+1)*size) for i < n is assigned to the
next n integer registers.
Bit i in ptrMap indicates whether the i'th value is a pointer.
n must be <= 8.
Returns whether assignment succeeded.
func (a *abiSeq) assignIntN(offset uintptr, size uintptr, n int, ptrMap uint8) bool
assignTo
method
#
assignTo returns a value v that can be assigned directly to dst.
It panics if v is not assignable to dst.
For a conversion to an interface type, target, if not nil,
is a suggested scratch space to use.
target must be initialized memory (or nil).
func (v Value) assignTo(context string, dst *abi.Type, target unsafe.Pointer) Value
badlinkname_Value_pointer
function
#
go:linkname badlinkname_Value_pointer reflect.(*Value).pointer
func badlinkname_Value_pointer(Value) unsafe.Pointer
badlinkname_rtype_Align
function
#
go:linkname badlinkname_rtype_Align reflect.(*rtype).Align
func badlinkname_rtype_Align(*rtype) int
badlinkname_rtype_AssignableTo
function
#
go:linkname badlinkname_rtype_AssignableTo reflect.(*rtype).AssignableTo
func badlinkname_rtype_AssignableTo(*rtype, Type) bool
badlinkname_rtype_Bits
function
#
go:linkname badlinkname_rtype_Bits reflect.(*rtype).Bits
func badlinkname_rtype_Bits(*rtype) int
badlinkname_rtype_ChanDir
function
#
go:linkname badlinkname_rtype_ChanDir reflect.(*rtype).ChanDir
func badlinkname_rtype_ChanDir(*rtype) ChanDir
badlinkname_rtype_Comparable
function
#
go:linkname badlinkname_rtype_Comparable reflect.(*rtype).Comparable
func badlinkname_rtype_Comparable(*rtype) bool
badlinkname_rtype_ConvertibleTo
function
#
go:linkname badlinkname_rtype_ConvertibleTo reflect.(*rtype).ConvertibleTo
func badlinkname_rtype_ConvertibleTo(*rtype, Type) bool
badlinkname_rtype_Elem
function
#
go:linkname badlinkname_rtype_Elem reflect.(*rtype).Elem
func badlinkname_rtype_Elem(*rtype) Type
badlinkname_rtype_Field
function
#
go:linkname badlinkname_rtype_Field reflect.(*rtype).Field
func badlinkname_rtype_Field(*rtype, int) StructField
badlinkname_rtype_FieldAlign
function
#
go:linkname badlinkname_rtype_FieldAlign reflect.(*rtype).FieldAlign
func badlinkname_rtype_FieldAlign(*rtype) int
badlinkname_rtype_FieldByIndex
function
#
go:linkname badlinkname_rtype_FieldByIndex reflect.(*rtype).FieldByIndex
func badlinkname_rtype_FieldByIndex(*rtype, []int) StructField
badlinkname_rtype_FieldByName
function
#
go:linkname badlinkname_rtype_FieldByName reflect.(*rtype).FieldByName
func badlinkname_rtype_FieldByName(*rtype, string) (StructField, bool)
badlinkname_rtype_FieldByNameFunc
function
#
go:linkname badlinkname_rtype_FieldByNameFunc reflect.(*rtype).FieldByNameFunc
func badlinkname_rtype_FieldByNameFunc(*rtype, func(string) bool) (StructField, bool)
badlinkname_rtype_Implements
function
#
go:linkname badlinkname_rtype_Implements reflect.(*rtype).Implements
func badlinkname_rtype_Implements(*rtype, Type) bool
badlinkname_rtype_In
function
#
go:linkname badlinkname_rtype_In reflect.(*rtype).In
func badlinkname_rtype_In(*rtype, int) Type
badlinkname_rtype_IsVariadic
function
#
go:linkname badlinkname_rtype_IsVariadic reflect.(*rtype).IsVariadic
func badlinkname_rtype_IsVariadic(*rtype) bool
badlinkname_rtype_Key
function
#
go:linkname badlinkname_rtype_Key reflect.(*rtype).Key
func badlinkname_rtype_Key(*rtype) Type
badlinkname_rtype_Kind
function
#
go:linkname badlinkname_rtype_Kind reflect.(*rtype).Kind
func badlinkname_rtype_Kind(*rtype) Kind
badlinkname_rtype_Len
function
#
go:linkname badlinkname_rtype_Len reflect.(*rtype).Len
func badlinkname_rtype_Len(*rtype) int
badlinkname_rtype_Method
function
#
go:linkname badlinkname_rtype_Method reflect.(*rtype).Method
func badlinkname_rtype_Method(*rtype, int) Method
badlinkname_rtype_MethodByName
function
#
go:linkname badlinkname_rtype_MethodByName reflect.(*rtype).MethodByName
func badlinkname_rtype_MethodByName(*rtype, string) (Method, bool)
badlinkname_rtype_Name
function
#
go:linkname badlinkname_rtype_Name reflect.(*rtype).Name
func badlinkname_rtype_Name(*rtype) string
badlinkname_rtype_NumField
function
#
go:linkname badlinkname_rtype_NumField reflect.(*rtype).NumField
func badlinkname_rtype_NumField(*rtype) int
badlinkname_rtype_NumIn
function
#
go:linkname badlinkname_rtype_NumIn reflect.(*rtype).NumIn
func badlinkname_rtype_NumIn(*rtype) int
badlinkname_rtype_NumMethod
function
#
go:linkname badlinkname_rtype_NumMethod reflect.(*rtype).NumMethod
func badlinkname_rtype_NumMethod(*rtype) int
badlinkname_rtype_NumOut
function
#
go:linkname badlinkname_rtype_NumOut reflect.(*rtype).NumOut
func badlinkname_rtype_NumOut(*rtype) int
badlinkname_rtype_Out
function
#
go:linkname badlinkname_rtype_Out reflect.(*rtype).Out
func badlinkname_rtype_Out(*rtype, int) Type
badlinkname_rtype_PkgPath
function
#
go:linkname badlinkname_rtype_PkgPath reflect.(*rtype).PkgPath
func badlinkname_rtype_PkgPath(*rtype) string
badlinkname_rtype_Size
function
#
go:linkname badlinkname_rtype_Size reflect.(*rtype).Size
func badlinkname_rtype_Size(*rtype) uintptr
badlinkname_rtype_String
function
#
go:linkname badlinkname_rtype_String reflect.(*rtype).String
func badlinkname_rtype_String(*rtype) string
badlinkname_rtype_ptrTo
function
#
go:linkname badlinkname_rtype_ptrTo reflect.(*rtype).ptrTo
func badlinkname_rtype_ptrTo(*rtype) *abi.Type
bucketOf
function
#
func bucketOf(ktyp *abi.Type, etyp *abi.Type) *abi.Type
bytesSlow
method
#
func (v Value) bytesSlow() []byte
call
method
#
func (v Value) call(op string, in []Value) []Value
call
function
#
call calls fn with "stackArgsSize" bytes of stack arguments laid out
at stackArgs and register arguments laid out in regArgs. frameSize is
the total amount of stack space that will be reserved by call, so this
should include enough space to spill register arguments to the stack in
case of preemption.
After fn returns, call copies stackArgsSize-stackRetOffset result bytes
back into stackArgs+stackRetOffset before returning, for any return
values passed on the stack. Register-based return values will be found
in the same regArgs structure.
regArgs must also be prepared with an appropriate ReturnIsPtr bitmap
indicating which registers will contain pointer-valued return values. The
purpose of this bitmap is to keep pointers visible to the GC between
returning from reflectcall and actually using them.
If copying result bytes back from the stack, the caller must pass the
argument frame type as stackArgsType, so that call can execute appropriate
write barriers during the copy.
Arguments passed through to call do not escape. The type is used only in a
very limited callee of call, the stackArgs are copied, and regArgs is only
used in the call frame.
go:noescape
go:linkname call runtime.reflectcall
func call(stackArgsType *abi.Type, f unsafe.Pointer, stackArgs unsafe.Pointer, stackArgsSize uint32, stackRetOffset uint32, frameSize uint32, regArgs *abi.RegArgs)
callMethod
function
#
callMethod is the call implementation used by a function returned
by makeMethodValue (used by v.Method(i).Interface()).
It is a streamlined version of the usual reflect call: the caller has
already laid out the argument frame for us, so we don't have
to deal with individual Values for each argument.
It is in this file so that it can be next to the two similar functions above.
The remainder of the makeMethodValue implementation is in makefunc.go.
NOTE: This function must be marked as a "wrapper" in the generated code,
so that the linker can make it work correctly for panic and recover.
The gc compilers know to do that for the name "reflect.callMethod".
ctxt is the "closure" generated by makeMethodValue.
frame is a pointer to the arguments to that closure on the stack.
retValid points to a boolean which should be set when the results
section of frame is set.
regs contains the argument values passed in registers and will contain
the values returned from ctxt.fn in registers.
func callMethod(ctxt *methodValue, frame unsafe.Pointer, retValid *bool, regs *abi.RegArgs)
callReflect
function
#
callReflect is the call implementation used by a function
returned by MakeFunc. In many ways it is the opposite of the
method Value.call above. The method above converts a call using Values
into a call of a function with a concrete argument frame, while
callReflect converts a call of a function with a concrete argument
frame into a call using Values.
It is in this file so that it can be next to the call method above.
The remainder of the MakeFunc implementation is in makefunc.go.
NOTE: This function must be marked as a "wrapper" in the generated code,
so that the linker can make it work correctly for panic and recover.
The gc compilers know to do that for the name "reflect.callReflect".
ctxt is the "closure" generated by MakeFunc.
frame is a pointer to the arguments to that closure on the stack.
retValid points to a boolean which should be set when the results
section of frame is set.
regs contains the argument values passed in registers and will contain
the values returned from ctxt.fn in registers.
func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs *abi.RegArgs)
canRangeFunc
function
#
func canRangeFunc(t *abi.Type) bool
canRangeFunc2
function
#
func canRangeFunc2(t *abi.Type) bool
capNonSlice
method
#
func (v Value) capNonSlice() int
chancap
function
#
implemented in ../runtime
go:noescape
func chancap(ch unsafe.Pointer) int
chanclose
function
#
go:noescape
func chanclose(ch unsafe.Pointer)
chanlen
function
#
go:noescape
func chanlen(ch unsafe.Pointer) int
chanrecv
function
#
go:noescape
func chanrecv(ch unsafe.Pointer, nb bool, val unsafe.Pointer) (selected bool, received bool)
chansend
function
#
func chansend(ch unsafe.Pointer, val unsafe.Pointer, nb bool) bool
chansend0
function
#
go:noescape
func chansend0(ch unsafe.Pointer, val unsafe.Pointer, nb bool) bool
common
method
#
func (t *interfaceType) common() *abi.Type
common
method
#
func (t *rtype) common() *abi.Type
contentEscapes
function
#
Dummy annotation marking that the content of value x
escapes (i.e. modeling roughly heap=*x),
for use in cases where the reflect code is so clever that
the compiler cannot follow.
func contentEscapes(x unsafe.Pointer)
convertOp
function
#
convertOp returns the function to convert a value of type src
to a value of type dst. If the conversion is illegal, convertOp returns nil.
func convertOp(dst *abi.Type, src *abi.Type) (func(Value, Type) Value)
copyVal
function
#
copyVal returns a Value containing the map key or value at ptr,
allocating a new variable as needed.
func copyVal(typ *abi.Type, fl flag, ptr unsafe.Pointer) Value
cvtBytesString
function
#
convertOp: []byte -> string
func cvtBytesString(v Value, t Type) Value
cvtComplex
function
#
convertOp: complexXX -> complexXX
func cvtComplex(v Value, t Type) Value
cvtDirect
function
#
convertOp: direct copy
func cvtDirect(v Value, typ Type) Value
cvtFloat
function
#
convertOp: floatXX -> floatXX
func cvtFloat(v Value, t Type) Value
cvtFloatInt
function
#
convertOp: floatXX -> intXX
func cvtFloatInt(v Value, t Type) Value
cvtFloatUint
function
#
convertOp: floatXX -> uintXX
func cvtFloatUint(v Value, t Type) Value
cvtI2I
function
#
convertOp: interface -> interface
func cvtI2I(v Value, typ Type) Value
cvtInt
function
#
convertOp: intXX -> [u]intXX
func cvtInt(v Value, t Type) Value
cvtIntFloat
function
#
convertOp: intXX -> floatXX
func cvtIntFloat(v Value, t Type) Value
cvtIntString
function
#
convertOp: intXX -> string
func cvtIntString(v Value, t Type) Value
cvtRunesString
function
#
convertOp: []rune -> string
func cvtRunesString(v Value, t Type) Value
cvtSliceArray
function
#
convertOp: []T -> [N]T
func cvtSliceArray(v Value, t Type) Value
cvtSliceArrayPtr
function
#
convertOp: []T -> *[N]T
func cvtSliceArrayPtr(v Value, t Type) Value
cvtStringBytes
function
#
convertOp: string -> []byte
func cvtStringBytes(v Value, t Type) Value
cvtStringRunes
function
#
convertOp: string -> []rune
func cvtStringRunes(v Value, t Type) Value
cvtT2I
function
#
convertOp: concrete -> interface
func cvtT2I(v Value, typ Type) Value
cvtUint
function
#
convertOp: uintXX -> [u]intXX
func cvtUint(v Value, t Type) Value
cvtUintFloat
function
#
convertOp: uintXX -> floatXX
func cvtUintFloat(v Value, t Type) Value
cvtUintString
function
#
convertOp: uintXX -> string
func cvtUintString(v Value, t Type) Value
deepValueEqual
function
#
Tests for deep equality using reflected types. The map argument tracks
comparisons that have already been seen, which allows short circuiting on
recursive types.
func deepValueEqual(v1 Value, v2 Value, visited map[visit]bool) bool
directlyAssignable
function
#
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 *abi.Type, V *abi.Type) bool
dump
method
#
func (a *abiDesc) dump()
dump
method
#
func (a *abiSeq) dump()
dumpPtrBitMap
function
#
func dumpPtrBitMap(b abi.IntArgRegBitmap)
elem
function
#
func elem(t *abi.Type) *abi.Type
embeddedIfaceMethStub
function
#
func embeddedIfaceMethStub()
emitGCMask
function
#
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)
escapes
function
#
Dummy annotation marking that the value x escapes,
for use in cases where the reflect code is so clever that
the compiler cannot follow.
func escapes(x any)
exportedMethods
method
#
func (t *rtype) exportedMethods() []abi.Method
extendSlice
method
#
extendSlice extends a slice by n elements.
Unlike Value.grow, which modifies the slice in place and
does not change the length of the slice in place,
extendSlice returns a new slice value with the length
incremented by the number of specified elements.
func (v Value) extendSlice(n int) Value
floatFromReg
function
#
floatFromReg loads a float value from its register representation in r.
argSize must be 4 or 8.
func floatFromReg(r *abi.RegArgs, reg int, argSize uintptr, to unsafe.Pointer)
floatToReg
function
#
floatToReg stores a float value in its register representation in r.
argSize must be either 4 or 8.
func floatToReg(r *abi.RegArgs, reg int, argSize uintptr, from unsafe.Pointer)
fnv1
function
#
fnv1 incorporates the list of bytes into the hash x using the FNV-1 hash function.
func fnv1(x uint32, list ...byte) uint32
funcLayout
function
#
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)
funcName
function
#
funcName returns the name of f, for use in error messages.
func funcName(f func([]Value) []Value) string
funcStr
function
#
funcStr builds a string representation of a funcType.
func funcStr(ft *funcType) string
getStaticuint64s
function
#
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
groupAndSlotOf
function
#
func groupAndSlotOf(ktyp Type, etyp Type) (Type, Type)
grow
method
#
grow is identical to Grow but does not check for assignability.
func (v Value) grow(n int)
growslice
function
#
go:noescape
func growslice(t *abi.Type, old unsafeheader.Slice, num int) unsafeheader.Slice
hashMightPanic
function
#
hashMightPanic reports whether the hash of a map key of type t might panic.
func hashMightPanic(t *abi.Type) bool
haveIdenticalType
function
#
func haveIdenticalType(T *abi.Type, V *abi.Type, cmpTags bool) bool
haveIdenticalUnderlyingType
function
#
func haveIdenticalUnderlyingType(T *abi.Type, V *abi.Type, cmpTags bool) bool
ifaceE2I
function
#
func ifaceE2I(t *abi.Type, src any, dst unsafe.Pointer)
implements
function
#
implements reports whether the type V implements the interface type T.
func implements(T *abi.Type, V *abi.Type) bool
initFuncTypes
function
#
func initFuncTypes(n int) Type
initialized
method
#
func (h *hiter) initialized() bool
intFromReg
function
#
intFromReg loads an argSize sized integer from reg and places it at to.
argSize must be non-zero, fit in a register, and a power-of-two.
func intFromReg(r *abi.RegArgs, reg int, argSize uintptr, to unsafe.Pointer)
intToReg
function
#
intToReg loads an argSize sized integer and stores it into reg.
argSize must be non-zero, fit in a register, and a power-of-two.
func intToReg(r *abi.RegArgs, reg int, argSize uintptr, from unsafe.Pointer)
isLetter
function
#
isLetter reports whether a given 'rune' is classified as a Letter.
func isLetter(ch rune) bool
isPaddedField
function
#
isPaddedField reports whether the i'th field of struct type t is followed
by padding.
func isPaddedField(t Type, i int) bool
isReflexive
function
#
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
isRegularMemory
function
#
This must match cmd/compile/internal/compare.IsRegularMemory
func isRegularMemory(t Type) bool
isValidFieldName
function
#
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
isZero
function
#
isZero For all zeros, performance is not as good as
return bytealg.Count(b, byte(0)) == len(b)
func isZero(b []byte) bool
kind
method
#
func (f flag) kind() Kind
lenNonSlice
method
#
func (v Value) lenNonSlice() int
makeBytes
function
#
func makeBytes(f flag, v []byte, t Type) Value
makeComplex
function
#
makeComplex returns a Value of type t equal to v (possibly truncated to complex64),
where t is a complex64 or complex128 type.
func makeComplex(f flag, v complex128, t Type) Value
makeFloat
function
#
makeFloat returns a Value of type t equal to v (possibly truncated to float32),
where t is a float32 or float64 type.
func makeFloat(f flag, v float64, t Type) Value
makeFloat32
function
#
makeFloat32 returns a Value of type t equal to v, where t is a float32 type.
func makeFloat32(f flag, v float32, t Type) Value
makeFuncStub
function
#
makeFuncStub is an assembly function that is the code half of
the function returned from MakeFunc. It expects a *callReflectFunc
as its context register, and its job is to invoke callReflect(ctxt, frame)
where ctxt is the context register and frame is a pointer to the first
word in the passed-in argument frame.
func makeFuncStub()
makeInt
function
#
makeInt returns a Value of type t equal to bits (possibly truncated),
where t is a signed or unsigned int type.
func makeInt(f flag, bits uint64, t Type) Value
makeMethodValue
function
#
makeMethodValue converts v from the rcvr+method index representation
of a method value to an actual method func value, which is
basically the receiver value with a special bit set, into a true
func value - a value holding an actual func. The output is
semantically equivalent to the input as far as the user of package
reflect can tell, but the true func representation can be handled
by code like Convert and Interface and Assign.
func makeMethodValue(op string, v Value) Value
makeRunes
function
#
func makeRunes(f flag, v []rune, t Type) Value
makeString
function
#
func makeString(f flag, v string, t Type) Value
makechan
function
#
func makechan(typ *abi.Type, size int) (ch unsafe.Pointer)
makemap
function
#
func makemap(t *abi.Type, cap int) (m unsafe.Pointer)
mapIterNext
function
#
Equivalent to runtime.mapIterNext.
go:noinline
func mapIterNext(it *maps.Iter)
mapIterStart
function
#
Equivalent to runtime.mapIterStart.
go:noinline
func mapIterStart(t *abi.SwissMapType, m *maps.Map, it *maps.Iter)
mapaccess
function
#
go:noescape
func mapaccess(t *abi.Type, m unsafe.Pointer, key unsafe.Pointer) (val unsafe.Pointer)
mapaccess_faststr
function
#
go:noescape
func mapaccess_faststr(t *abi.Type, m unsafe.Pointer, key string) (val unsafe.Pointer)
mapassign
function
#
mapassign should be an internal detail,
but widely used packages access it using linkname.
Notable members of the hall of shame include:
- github.com/modern-go/reflect2
- github.com/goccy/go-json
Do not remove or change the type signature.
See go.dev/issue/67401.
go:linkname mapassign
func mapassign(t *abi.Type, m unsafe.Pointer, key unsafe.Pointer, val unsafe.Pointer)
mapassign0
function
#
go:noescape
func mapassign0(t *abi.Type, m unsafe.Pointer, key unsafe.Pointer, val unsafe.Pointer)
mapassign_faststr
function
#
func mapassign_faststr(t *abi.Type, m unsafe.Pointer, key string, val unsafe.Pointer)
mapassign_faststr0
function
#
go:noescape
func mapassign_faststr0(t *abi.Type, m unsafe.Pointer, key string, val unsafe.Pointer)
mapclear
function
#
func mapclear(t *abi.Type, m unsafe.Pointer)
mapdelete
function
#
go:noescape
func mapdelete(t *abi.Type, m unsafe.Pointer, key unsafe.Pointer)
mapdelete_faststr
function
#
go:noescape
func mapdelete_faststr(t *abi.Type, m unsafe.Pointer, key string)
mapiterinit
function
#
go:noescape
func mapiterinit(t *abi.Type, m unsafe.Pointer, it *hiter)
mapiternext
function
#
go:noescape
func mapiternext(it *hiter)
maplen
function
#
go:noescape
func maplen(m unsafe.Pointer) int
memmove
function
#
memmove copies size bytes to dst from src. No write barriers are used.
go:noescape
func memmove(dst unsafe.Pointer, src unsafe.Pointer, size uintptr)
methodReceiver
function
#
methodReceiver returns information about the receiver
described by v. The Value v may or may not have the
flagMethod bit set, so the kind cached in v.flag should
not be used.
The return value rcvrtype gives the method's actual receiver type.
The return value t gives the method type signature (without the receiver).
The return value fn is a pointer to the method code.
func methodReceiver(op string, v Value, methodIndex int) (rcvrtype *abi.Type, t *funcType, fn unsafe.Pointer)
methodValueCall
function
#
methodValueCall is an assembly function that is the code half of
the function returned from makeMethodValue. It expects a *methodValue
as its context register, and its job is to invoke callMethod(ctxt, frame)
where ctxt is the context register and frame is a pointer to the first
word in the passed-in argument frame.
func methodValueCall()
methodValueCallCodePtr
function
#
func methodValueCallCodePtr() uintptr
moveMakeFuncArgPtrs
function
#
moveMakeFuncArgPtrs uses ctxt.regPtrs to copy integer pointer arguments
in args.Ints to args.Ptrs where the GC can see them.
This is similar to what reflectcallmove does in the runtime, except
that happens on the return path, whereas this happens on the call path.
nosplit because pointers are being held in uintptr slots in args, so
having our stack scanned now could lead to accidentally freeing
memory.
go:nosplit
func moveMakeFuncArgPtrs(ctxt *makeFuncCtxt, args *abi.RegArgs)
mustBe
method
#
mustBe panics if f's kind is not expected.
Making this a method on flag instead of on Value
(and embedding flag in Value) means that we can write
the very clear v.mustBe(Bool) and have it compile into
v.flag.mustBe(Bool), which will only bother to copy the
single important word for the receiver.
func (f flag) mustBe(expected Kind)
mustBeAssignable
method
#
mustBeAssignable panics if f records that the value is not assignable,
which is to say that either it was obtained using an unexported field
or it is not addressable.
func (f flag) mustBeAssignable()
mustBeAssignableSlow
method
#
func (f flag) mustBeAssignableSlow()
mustBeExported
method
#
mustBeExported panics if f records that the value was obtained using
an unexported field.
func (f flag) mustBeExported()
mustBeExportedSlow
method
#
func (f flag) mustBeExportedSlow()
nameFor
function
#
func nameFor(t *abi.Type) string
nameOff
method
#
func (t *rtype) nameOff(off aNameOff) abi.Name
nameOff
method
#
func (t *interfaceType) nameOff(off aNameOff) abi.Name
nameOffFor
function
#
func nameOffFor(t *abi.Type, off aNameOff) abi.Name
needKeyUpdate
function
#
needKeyUpdate reports whether map overwrites require the key to be copied.
func needKeyUpdate(t *abi.Type) bool
newAbiDesc
function
#
func newAbiDesc(t *funcType, rcvr *abi.Type) abiDesc
newName
function
#
func newName(n string, tag string, exported bool, embedded bool) abi.Name
overflowFloat32
function
#
func overflowFloat32(x float64) bool
packEface
function
#
packEface converts v to the empty interface.
func packEface(v Value) any
panicNotBool
method
#
func (v Value) panicNotBool()
panicNotMap
method
#
Force slow panicking path not inlined, so it won't add to the
inlining budget of the caller.
TODO: undo when the inliner is no longer bottom-up only.
go:noinline
func (f flag) panicNotMap()
panicNotMap
method
#
Force slow panicking path not inlined, so it won't add to the
inlining budget of the caller.
TODO: undo when the inliner is no longer bottom-up only.
go:noinline
func (f flag) panicNotMap()
pkgPath
function
#
func pkgPath(n abi.Name) string
pkgPathFor
function
#
func pkgPathFor(t *abi.Type) string
pointer
method
#
pointer returns the underlying pointer represented by v.
v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer
if v.Kind() == Pointer, the base type must not be not-in-heap.
func (v Value) pointer() unsafe.Pointer
ptrTo
method
#
func (t *rtype) ptrTo() *abi.Type
ptrTo
function
#
func ptrTo(t *abi.Type) *abi.Type
rangeNum
function
#
func rangeNum(num N, t Type) *ast.IndexExpr
recv
method
#
internal recv, possibly non-blocking (nb).
v is known to be a channel.
func (v Value) recv(nb bool) (val Value, ok bool)
regAssign
method
#
regAssign attempts to reserve argument registers for a value of
type t, stored at some offset.
It returns whether or not the assignment succeeded, but
leaves any changes it made to a.steps behind, so the caller
must undo that work by adjusting a.steps if it fails.
This method along with the assign* methods represent the
complete register-assignment algorithm for the Go ABI.
func (a *abiSeq) regAssign(t *abi.Type, offset uintptr) bool
resolveNameOff
function
#
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
resolveReflectName
function
#
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
resolveReflectText
function
#
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
resolveReflectType
function
#
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
resolveTextOff
function
#
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
resolveTypeOff
function
#
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
ro
method
#
func (f flag) ro() flag
rselect
function
#
rselect runs a select. It returns the index of the chosen case.
If the case was a receive, val is filled in with the received value.
The conventional OK bool indicates whether the receive corresponds
to a sent value.
rselect generally doesn't escape the runtimeSelect slice, except
that for the send case the value to send needs to escape. We don't
have a way to represent that in the function signature. So we handle
that with a forced escape in function Select.
go:noescape
func rselect([]runtimeSelect) (chosen int, recvOK bool)
rtypeOf
function
#
rtypeOf directly extracts the *rtype of the provided value.
func rtypeOf(i any) *abi.Type
rtypeOff
function
#
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
runes
method
#
runes returns v's underlying value.
It panics if v's underlying value is not a slice of runes (int32s).
func (v Value) runes() []rune
runtimeStructField
function
#
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)
send
method
#
internal send, possibly non-blocking.
v is known to be a channel.
func (v Value) send(x Value, nb bool) (selected bool)
setRunes
method
#
setRunes sets v's underlying value.
It panics if v's underlying value is not a slice of runes (int32s)
or if [Value.CanSet] returns false.
func (v Value) setRunes(x []rune)
specialChannelAssignability
function
#
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 *abi.Type, V *abi.Type) bool
stackAssign
method
#
stackAssign reserves space for one value that is "size" bytes
large with alignment "alignment" to the stack.
Should not be called directly; use addArg instead.
func (a *abiSeq) stackAssign(size uintptr, alignment uintptr)
stepsForValue
method
#
stepsForValue returns the ABI instructions for translating
the i'th Go argument or return value represented by this
abiSeq to the Go ABI.
func (a *abiSeq) stepsForValue(i int) []abiStep
storeRcvr
function
#
v is a method receiver. Store at p the word which is used to
encode that receiver at the start of the argument list.
Reflect uses the "interface" calling convention for
methods, which always uses one word to record the receiver.
func storeRcvr(v Value, p unsafe.Pointer)
stringFor
function
#
func stringFor(t *abi.Type) string
stringNonString
method
#
func (v Value) stringNonString() string
textOff
method
#
func (t *rtype) textOff(off aTextOff) unsafe.Pointer
textOffFor
function
#
func textOffFor(t *abi.Type, off aTextOff) unsafe.Pointer
toRType
function
#
func toRType(t *abi.Type) *rtype
toType
function
#
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
typ
method
#
typ returns the *abi.Type stored in the Value. This method is fast,
but it doesn't always return the correct type for the Value.
See abiType and Type, which do return the correct type.
func (v Value) typ() *abi.Type
typeOff
method
#
func (t *rtype) typeOff(off aTypeOff) *abi.Type
typeOff
method
#
func (t *interfaceType) typeOff(off aTypeOff) *abi.Type
typeOffFor
function
#
func typeOffFor(t *abi.Type, off aTypeOff) *abi.Type
typeSlow
method
#
go:noinline
func (v Value) typeSlow() Type
typedarrayclear
function
#
typedarrayclear zeroes the value at ptr of an array of elemType,
only clears len elem.
go:noescape
func typedarrayclear(elemType *abi.Type, ptr unsafe.Pointer, len int)
typedmemclr
function
#
typedmemclr zeros the value at ptr of type t.
go:noescape
func typedmemclr(t *abi.Type, ptr unsafe.Pointer)
typedmemclrpartial
function
#
typedmemclrpartial is like typedmemclr but assumes that
dst points off bytes into the value and only clears size bytes.
go:noescape
func typedmemclrpartial(t *abi.Type, ptr unsafe.Pointer, off uintptr, size uintptr)
typedmemmove
function
#
typedmemmove copies a value of type t to dst from src.
go:noescape
func typedmemmove(t *abi.Type, dst unsafe.Pointer, src unsafe.Pointer)
typedslicecopy
function
#
typedslicecopy copies a slice of elemType values from src to dst,
returning the number of elements copied.
go:noescape
func typedslicecopy(t *abi.Type, dst unsafeheader.Slice, src unsafeheader.Slice) int
typehash
function
#
go:noescape
func typehash(t *abi.Type, p unsafe.Pointer, h uintptr) uintptr
typelinks
function
#
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)
typeptrdata
function
#
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
typesByString
function
#
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
typesMustMatch
function
#
func typesMustMatch(what string, t1 Type, t2 Type)
uncommon
method
#
func (t *rtype) uncommon() *abi.UncommonType
uncommon
method
#
func (t *interfaceType) uncommon() *abi.UncommonType
unpackEface
function
#
unpackEface converts the empty interface i to a Value.
func unpackEface(i any) Value
unsafe_New
function
#
go:noescape
func unsafe_New(*abi.Type) unsafe.Pointer
unsafe_NewArray
function
#
go:noescape
func unsafe_NewArray(*abi.Type, int) unsafe.Pointer
unsafeslice
function
#
go:noescape
func unsafeslice(t *abi.Type, ptr unsafe.Pointer, len int)
unusedIfaceIndir
function
#
ifaceIndir reports whether t is stored indirectly in an interface value.
It is no longer used by this package and is here entirely for the
linkname uses.
go:linkname unusedIfaceIndir reflect.ifaceIndir
func unusedIfaceIndir(t *abi.Type) bool
valueInterface
function
#
func valueInterface(v Value, safe bool) any
valueMethodName
function
#
valueMethodName returns the name of the exported calling method on Value.
func valueMethodName() string
verifyNotInHeapPtr
function
#
func verifyNotInHeapPtr(p uintptr) bool
walk
method
#
walk walks all the fields in the struct type t, visiting
fields in index preorder and appending them to w.fields
(this maintains the required ordering).
Fields that have been overridden have their
Name field cleared.
func (w *visibleFieldsWalker) walk(t Type)