Involved Source Filesabi.godeepequal.gofloat32reg_generic.gomakefunc.goswapper.go Package reflect implements run-time reflection, allowing a program to
manipulate objects with arbitrary types. The typical use is to take a value
with static type interface{} and extract its dynamic type information by
calling TypeOf, which returns a Type.
A call to ValueOf returns a Value representing the run-time data.
Zero takes a Type and returns a Value representing a zero value
for that type.
See "The Laws of Reflection" for an introduction to reflection in Go:
https://golang.org/doc/articles/laws_of_reflection.htmlvalue.govisiblefields.goasm_amd64.s
Code Examples
package main
import (
"fmt"
"reflect"
)
func main() {
for _, v := range []any{"hi", 42, func() {}} {
switch v := reflect.ValueOf(v); v.Kind() {
case reflect.String:
fmt.Println(v.String())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
fmt.Println(v.Int())
default:
fmt.Printf("unhandled kind %s", v.Kind())
}
}
}
package main
import (
"fmt"
"reflect"
)
func main() {
// swap is the implementation passed to MakeFunc.
// It must work in terms of reflect.Values so that it is possible
// to write code without knowing beforehand what the types
// will be.
swap := func(in []reflect.Value) []reflect.Value {
return []reflect.Value{in[1], in[0]}
}
// makeSwap expects fptr to be a pointer to a nil function.
// It sets that pointer to a new function created with MakeFunc.
// When the function is invoked, reflect turns the arguments
// into Values, calls swap, and then turns swap's result slice
// into the values returned by the new function.
makeSwap := func(fptr any) {
// fptr is a pointer to a function.
// Obtain the function value itself (likely nil) as a reflect.Value
// so that we can query its type and then set the value.
fn := reflect.ValueOf(fptr).Elem()
// Make a function of the right type.
v := reflect.MakeFunc(fn.Type(), swap)
// Assign it to the value fn represents.
fn.Set(v)
}
// Make and call a swap function for ints.
var intSwap func(int, int) (int, int)
makeSwap(&intSwap)
fmt.Println(intSwap(0, 1))
// Make and call a swap function for float64s.
var floatSwap func(float64, float64) (float64, float64)
makeSwap(&floatSwap)
fmt.Println(floatSwap(2.72, 3.14))
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
)
func main() {
typ := reflect.StructOf([]reflect.StructField{
{
Name: "Height",
Type: reflect.TypeOf(float64(0)),
Tag: `json:"height"`,
},
{
Name: "Age",
Type: reflect.TypeOf(int(0)),
Tag: `json:"age"`,
},
})
v := reflect.New(typ).Elem()
v.Field(0).SetFloat(0.4)
v.Field(1).SetInt(2)
s := v.Addr().Interface()
w := new(bytes.Buffer)
if err := json.NewEncoder(w).Encode(s); err != nil {
panic(err)
}
fmt.Printf("value: %+v\n", s)
fmt.Printf("json: %s", w.Bytes())
r := bytes.NewReader([]byte(`{"height":1.5,"age":10}`))
if err := json.NewDecoder(r).Decode(s); err != nil {
panic(err)
}
fmt.Printf("value: %+v\n", s)
}
package main
import (
"fmt"
"reflect"
)
func main() {
type S struct {
F string `species:"gopher" color:"blue"`
}
s := S{}
st := reflect.TypeOf(s)
field := st.Field(0)
fmt.Println(field.Tag.Get("color"), field.Tag.Get("species"))
}
package main
import (
"fmt"
"reflect"
)
func main() {
type S struct {
F0 string `alias:"field_0"`
F1 string `alias:""`
F2 string
}
s := S{}
st := reflect.TypeOf(s)
for i := 0; i < st.NumField(); i++ {
field := st.Field(i)
if alias, ok := field.Tag.Lookup("alias"); ok {
if alias == "" {
fmt.Println("(blank)")
} else {
fmt.Println(alias)
}
} else {
fmt.Println("(not specified)")
}
}
}
package main
import (
"fmt"
"io"
"os"
"reflect"
)
func main() {
// As interface types are only used for static typing, a
// common idiom to find the reflection Type for an interface
// type Foo is to use a *Foo value.
writerType := reflect.TypeOf((*io.Writer)(nil)).Elem()
fileType := reflect.TypeOf((*os.File)(nil))
fmt.Println(fileType.Implements(writerType))
}
package main
import (
"fmt"
"reflect"
)
func main() {
// This example shows a case in which the name of a promoted field
// is hidden by another field: FieldByName will not work, so
// FieldByIndex must be used instead.
type user struct {
firstName string
lastName string
}
type data struct {
user
firstName string
lastName string
}
u := data{
user: user{"Embedded John", "Embedded Doe"},
firstName: "John",
lastName: "Doe",
}
s := reflect.ValueOf(u).FieldByIndex([]int{0, 1})
fmt.Println("embedded last name:", s)
}
package main
import (
"fmt"
"reflect"
)
func main() {
type user struct {
firstName string
lastName string
}
u := user{firstName: "John", lastName: "Doe"}
s := reflect.ValueOf(u)
fmt.Println("Name:", s.FieldByName("firstName"))
}
Package-Level Type Names (total 48, in which 13 are exported)
A MapIter is an iterator for ranging over a map.
See Value.MapRange.hiterhitermValue Key returns the key of iter's current map entry. Next advances the map iterator and reports whether there is another
entry. It returns false when iter is exhausted; subsequent
calls to Key, Value, or Next will panic. 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. Value returns the value of iter's current map entry.
func Value.MapRange() *MapIter
func Value.SetIterKey(iter *MapIter)
func Value.SetIterValue(iter *MapIter)
Method represents a single method. // func with receiver as first argument // index for Type.Method Name is the method name. PkgPath is the package path that qualifies a lower case (unexported)
method name. It is empty for upper case (exported) method names.
The combination of PkgPath and Name uniquely identifies a method
in a method set.
See https://golang.org/ref/spec#Uniqueness_of_identifiers // method type IsExported reports whether the method is exported.
func Type.Method(int) Method
func Type.MethodByName(string) (Method, bool)
A SelectCase describes a single case in a select operation.
The kind of case depends on Dir, the communication direction.
If Dir is SelectDefault, the case represents a default case.
Chan and Send must be zero Values.
If Dir is SelectSend, the case represents a send operation.
Normally Chan's underlying value must be a channel, and Send's underlying value must be
assignable to the channel's element type. As a special case, if Chan is a zero Value,
then the case is ignored, and the field Send will also be ignored and may be either zero
or non-zero.
If Dir is SelectRecv, the case represents a receive operation.
Normally Chan's underlying value must be a channel and Send must be a zero Value.
If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value.
When a receive operation is selected, the received Value is returned by Select. // channel to use (for send or receive) // direction of case // value to send (for send)
func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)
SliceHeader is the runtime representation of a slice.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
Deprecated: Use unsafe.Slice or unsafe.SliceData instead.CapintDatauintptrLenint
StringHeader is the runtime representation of a string.
It cannot be used safely or portably and its representation may
change in a later release.
Moreover, the Data field is not sufficient to guarantee the data
it references will not be garbage collected, so programs must keep
a separate, correctly typed pointer to the underlying data.
Deprecated: Use unsafe.String or unsafe.StringData instead.DatauintptrLenint
A StructField describes a single field in a struct. // is an embedded field // index sequence for Type.FieldByIndex Name is the field name. // offset within struct, in bytes PkgPath is the package path that qualifies a lower case (unexported)
field name. It is empty for upper case (exported) field names.
See https://golang.org/ref/spec#Uniqueness_of_identifiers // field tag string // field type IsExported reports whether the field is exported.
func VisibleFields(t Type) []StructField
func Type.Field(i int) StructField
func Type.FieldByIndex(index []int) StructField
func Type.FieldByName(name string) (StructField, bool)
func Type.FieldByNameFunc(match func(string) bool) (StructField, bool)
func StructOf(fields []StructField) Type
func runtimeStructField(field StructField) (structField, string)
A StructTag is the tag string in a struct field.
By convention, tag strings are a concatenation of
optionally space-separated key:"value" pairs.
Each key is a non-empty string consisting of non-control
characters other than space (U+0020 ' '), quote (U+0022 '"'),
and colon (U+003A ':'). Each value is quoted using U+0022 '"'
characters and Go string literal syntax. 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 Lookup. 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.
Type is the representation of a Go type.
Not all methods apply to all kinds of types. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of type before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run-time panic.
Type values are comparable, such as with the == operator,
so they can be used as map keys.
Two Type values are equal if they represent identical types. Align returns the alignment in bytes of a value of
this type when allocated in memory. AssignableTo reports whether a value of the type is assignable to type u. Bits returns the size of the type in bits.
It panics if the type's Kind is not one of the
sized or unsized Int, Uint, Float, or Complex kinds. ChanDir returns a channel type's direction.
It panics if the type's Kind is not Chan. Comparable reports whether values of this type are comparable.
Even if Comparable returns true, the comparison may still panic.
For example, values of interface type are comparable,
but the comparison will panic if their dynamic type is not comparable. ConvertibleTo reports whether a value of the type is convertible to type u.
Even if ConvertibleTo returns true, the conversion may still panic.
For example, a slice of type []T is convertible to *[N]T,
but the conversion will panic if its length is less than N. Elem returns a type's element type.
It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice. Field returns a struct type's i'th field.
It panics if the type's Kind is not Struct.
It panics if i is not in the range [0, NumField()). FieldAlign returns the alignment in bytes of a value of
this type when used as a field in a struct. FieldByIndex returns the nested field corresponding
to the index sequence. It is equivalent to calling Field
successively for each index i.
It panics if the type's Kind is not Struct. FieldByName returns the struct field with the given name
and a boolean indicating if the field was found. FieldByNameFunc returns the struct field with a name
that satisfies the match function and a boolean indicating if
the field was found.
FieldByNameFunc considers the fields in the struct itself
and then the fields in any embedded structs, in breadth first order,
stopping at the shallowest nesting depth containing one or more
fields satisfying the match function. If multiple fields at that depth
satisfy the match function, they cancel each other
and FieldByNameFunc returns no match.
This behavior mirrors Go's handling of name lookup in
structs containing embedded fields. Implements reports whether the type implements the interface type u. In returns the type of a function type's i'th input parameter.
It panics if the type's Kind is not Func.
It panics if i is not in the range [0, NumIn()). IsVariadic reports whether a function type's final input parameter
is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's
implicit actual type []T.
For concreteness, if t represents func(x int, y ... float64), then
t.NumIn() == 2
t.In(0) is the reflect.Type for "int"
t.In(1) is the reflect.Type for "[]float64"
t.IsVariadic() == true
IsVariadic panics if the type's Kind is not Func. Key returns a map type's key type.
It panics if the type's Kind is not Map. Kind returns the specific kind of this type. Len returns an array type's length.
It panics if the type's Kind is not Array. Method returns the i'th method in the type's method set.
It panics if i is not in the range [0, NumMethod()).
For a non-interface type T or *T, the returned Method's Type and Func
fields describe a function whose first argument is the receiver,
and only exported methods are accessible.
For an interface type, the returned Method's Type field gives the
method signature, without a receiver, and the Func field is nil.
Methods are sorted in lexicographic order. MethodByName returns the method with that name in the type's
method set and a boolean indicating if the method was found.
For a non-interface type T or *T, the returned Method's Type and Func
fields describe a function whose first argument is the receiver.
For an interface type, the returned Method's Type field gives the
method signature, without a receiver, and the Func field is nil. Name returns the type's name within its package for a defined type.
For other (non-defined) types it returns the empty string. NumField returns a struct type's field count.
It panics if the type's Kind is not Struct. NumIn returns a function type's input parameter count.
It panics if the type's Kind is not Func. NumMethod returns the number of methods accessible using Method.
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. NumOut returns a function type's output parameter count.
It panics if the type's Kind is not Func. Out returns the type of a function type's i'th output parameter.
It panics if the type's Kind is not Func.
It panics if i is not in the range [0, NumOut()). PkgPath returns a defined type's package path, that is, the import path
that uniquely identifies the package, such as "encoding/base64".
If the type was predeclared (string, error) or not defined (*T, struct{},
[]int, or A where A is an alias for a non-defined type), the package path
will be the empty string. Size returns the number of bytes needed to store
a value of the given type; it is analogous to unsafe.Sizeof. String returns a string representation of the type.
The string representation may use shortened package names
(e.g., base64 instead of "encoding/base64") and is not
guaranteed to be unique among types. To test for type identity,
compare the Types directly.( Type) common() *abi.Type( Type) uncommon() *uncommonType
*rtype
Type : fmt.Stringer
Type : context.stringer
Type : runtime.stringer
func ArrayOf(length int, elem Type) Type
func ChanOf(dir ChanDir, t Type) Type
func FuncOf(in, out []Type, variadic bool) Type
func MapOf(key, elem Type) Type
func PointerTo(t Type) Type
func PtrTo(t Type) Type
func SliceOf(t Type) Type
func StructOf(fields []StructField) Type
func TypeOf(i any) Type
func Type.Elem() Type
func Type.In(i int) Type
func Type.Key() Type
func Type.Out(i int) Type
func Value.Type() Type
func initFuncTypes(n int) Type
func toType(t *abi.Type) Type
func Value.typeSlow() Type
func encoding/json.typeByIndex(t Type, index []int) Type
func ArrayOf(length int, elem Type) Type
func ChanOf(dir ChanDir, t Type) Type
func FuncOf(in, out []Type, variadic bool) Type
func MakeChan(typ Type, buffer int) Value
func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value
func MakeMap(typ Type) Value
func MakeMapWithSize(typ Type, n int) Value
func MakeSlice(typ Type, len, cap int) Value
func MapOf(key, elem Type) Type
func New(typ Type) Value
func NewAt(typ Type, p unsafe.Pointer) Value
func PointerTo(t Type) Type
func PtrTo(t Type) Type
func SliceOf(t Type) Type
func VisibleFields(t Type) []StructField
func Zero(typ Type) Value
func Type.AssignableTo(u Type) bool
func Type.ConvertibleTo(u Type) bool
func Type.Implements(u Type) bool
func Value.CanConvert(t Type) bool
func Value.Convert(t Type) Value
func cvtBytesString(v Value, t Type) Value
func cvtComplex(v Value, t Type) Value
func cvtDirect(v Value, typ Type) Value
func cvtFloat(v Value, t Type) Value
func cvtFloatInt(v Value, t Type) Value
func cvtFloatUint(v Value, t Type) Value
func cvtI2I(v Value, typ Type) Value
func cvtInt(v Value, t Type) Value
func cvtIntFloat(v Value, t Type) Value
func cvtIntString(v Value, t Type) Value
func cvtRunesString(v Value, t Type) Value
func cvtSliceArray(v Value, t Type) Value
func cvtSliceArrayPtr(v Value, t Type) Value
func cvtStringBytes(v Value, t Type) Value
func cvtStringRunes(v Value, t Type) Value
func cvtT2I(v Value, typ Type) Value
func cvtUint(v Value, t Type) Value
func cvtUintFloat(v Value, t Type) Value
func cvtUintString(v Value, t Type) Value
func makeBytes(f flag, v []byte, t Type) Value
func makeComplex(f flag, v complex128, t Type) Value
func makeFloat(f flag, v float64, t Type) Value
func makeFloat32(f flag, v float32, t Type) Value
func makeInt(f flag, bits uint64, t Type) Value
func makeRunes(f flag, v []rune, t Type) Value
func makeString(f flag, v string, t Type) Value
func typesMustMatch(what string, t1, t2 Type)
func encoding/asn1.getUniversalType(t Type) (matchAny bool, tagNumber int, isCompound, ok bool)
func encoding/asn1.parseSequenceOf(bytes []byte, sliceType Type, elemType Type) (ret Value, err error)
func encoding/asn1.parseSequenceOf(bytes []byte, sliceType Type, elemType Type) (ret Value, err error)
func encoding/binary.sizeof(t Type) int
func encoding/json.cachedTypeFields(t Type) json.structFields
func encoding/json.newArrayEncoder(t Type) json.encoderFunc
func encoding/json.newMapEncoder(t Type) json.encoderFunc
func encoding/json.newPtrEncoder(t Type) json.encoderFunc
func encoding/json.newSliceEncoder(t Type) json.encoderFunc
func encoding/json.newStructEncoder(t Type) json.encoderFunc
func encoding/json.newTypeEncoder(t Type, allowAddr bool) json.encoderFunc
func encoding/json.typeByIndex(t Type, index []int) Type
func encoding/json.typeEncoder(t Type) json.encoderFunc
func encoding/json.typeFields(t Type) json.structFields
var encoding/asn1.bigIntType
var encoding/asn1.bitStringType
var encoding/asn1.enumeratedType
var encoding/asn1.flagType
var encoding/asn1.objectIdentifierType
var encoding/asn1.rawContentsType
var encoding/asn1.rawValueType
var encoding/asn1.timeType
var encoding/json.marshalerType
var encoding/json.numberType
var encoding/json.textMarshalerType
var encoding/json.textUnmarshalerType
var go.opentelemetry.io/otel/attribute.keyValueType
var net/http.nopCloserType
var net/http.nopCloserWriterToType
Value is the reflection interface to a Go value.
Not all methods apply to all kinds of values. Restrictions,
if any, are noted in the documentation for each method.
Use the Kind method to find out the kind of value before
calling kind-specific methods. Calling a method
inappropriate to the kind of type causes a run time panic.
The zero Value represents no value.
Its IsValid method returns false, its Kind method returns Invalid,
its String method returns "<invalid Value>", and all other methods panic.
Most functions and methods never return an invalid value.
If one does, its documentation states the conditions explicitly.
A Value can be used concurrently by multiple goroutines provided that
the underlying Go value can be used concurrently for the equivalent
direct operations.
To compare two Values, compare the results of the Interface method.
Using == on two Values does not compare the underlying values
they represent. flag holds metadata about the value.
The lowest five bits give the Kind of the value, mirroring typ.Kind().
The next set of bits are flag bits:
- flagStickyRO: obtained via unexported not embedded field, so read-only
- flagEmbedRO: obtained via unexported embedded field, so read-only
- flagIndir: val holds a pointer to the data
- flagAddr: v.CanAddr is true (implies flagIndir and ptr is non-nil)
- flagMethod: v is a method value.
If ifaceIndir(typ), code can assume that flagIndir is set.
The remaining 22+ bits give a method number for method values.
If flag.kind() != Func, code can assume that flagMethod is unset. Pointer-valued data or, if flagIndir is set, pointer to data.
Valid when either flagIndir is set or typ.pointers() is true. typ_ holds the type of the value represented by a Value.
Access using the typ method to avoid escape of v. Addr returns a pointer value representing the address of v.
It panics if 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. Bool returns v's underlying value.
It panics if v's kind is not Bool. 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. 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. 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. CanAddr reports whether the value's address can be obtained with 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 Addr will panic. CanComplex reports whether Complex can be used without panicking. 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. CanFloat reports whether Float can be used without panicking. CanInt reports whether Int can be used without panicking. CanInterface reports whether Interface can be used without panicking. 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 Set or any type-specific
setter (e.g., SetBool, SetInt) will panic. CanUint reports whether Uint can be used without panicking. Cap returns v's capacity.
It panics if v's Kind is not Array, Chan, Slice or pointer to Array. 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. Close closes the channel v.
It panics if v's Kind is not Chan. 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. Complex returns v's underlying value, as a complex128.
It panics if v's Kind is not Complex64 or Complex128 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. 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. 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. 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. 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. 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. 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. 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. Float returns v's underlying value, as a float64.
It panics if v's Kind is not Float32 or Float64 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. 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. Int returns v's underlying value, as an int64.
It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64. 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. 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. 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. IsValid reports whether v represents a value.
It returns false if v is the zero Value.
If 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. IsZero reports whether v is the zero value for its type.
It panics if the argument is invalid. Kind returns v's Kind.
If v is the zero Value (IsValid returns false), Kind returns Invalid. Len returns v's length.
It panics if v's Kind is not Array, Chan, Map, Slice, String, or pointer to Array. 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. 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. MapRange returns a range iterator for a map.
It panics if v's Kind is not Map.
Call Next to advance the iterator, and Key/Value to access each entry.
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()
...
} 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. 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. NumField returns the number of fields in the struct v.
It panics if v's Kind is not Struct. 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. OverflowComplex reports whether the complex128 x cannot be represented by v's type.
It panics if v's Kind is not Complex64 or Complex128. OverflowFloat reports whether the float64 x cannot be represented by v's type.
It panics if v's Kind is not Float32 or Float64. 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. 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. Pointer returns v's value as a uintptr.
It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, 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.
It's preferred to use uintptr(Value.UnsafePointer()) to get the equivalent result. 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. 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. Set assigns x to the value v.
It panics if 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. SetBool sets v's underlying value.
It panics if v's Kind is not Bool or if CanSet() is false. SetBytes sets v's underlying value.
It panics if v's underlying value is not a slice of bytes. 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. SetComplex sets v's underlying value to x.
It panics if v's Kind is not Complex64 or Complex128, or if CanSet() is false. SetFloat sets v's underlying value to x.
It panics if v's Kind is not Float32 or Float64, or if CanSet() is false. SetInt sets v's underlying value to x.
It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64, or if CanSet() is false. 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. 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. 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. 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. SetPointer sets the [unsafe.Pointer] value v to x.
It panics if v's Kind is not UnsafePointer. SetString sets v's underlying value to x.
It panics if v's Kind is not String or if CanSet() is false. 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 CanSet() is false. SetZero sets v to be the zero value of v's type.
It panics if CanSet returns false. 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. 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. 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 "<T value>" 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. 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. 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. Type returns v's type. Uint returns v's underlying value, as a uint64.
It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64. 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. UnsafePointer returns v's value as a [unsafe.Pointer].
It panics if v's Kind is not Chan, Func, Map, Pointer, Slice, 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. 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).( Value) bytesSlow() []byte( Value) call(op string, in []Value) []Value( Value) capNonSlice() int 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. grow is identical to Grow but does not check for assignability.( Value) kind() Kind( Value) lenNonSlice() int 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. 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.( Value) mustBeAssignableSlow() mustBeExported panics if f records that the value was obtained using
an unexported field.( Value) mustBeExportedSlow()( Value) panicNotBool() 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. 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. internal recv, possibly non-blocking (nb).
v is known to be a channel.( Value) ro() flag runes returns v's underlying value.
It panics if v's underlying value is not a slice of runes (int32s). internal send, possibly non-blocking.
v is known to be a channel. setRunes sets v's underlying value.
It panics if v's underlying value is not a slice of runes (int32s).( Value) stringNonString() string( Value) typ() *abi.Type( Value) typeSlow() Type
Value : fmt.Stringer
Value : context.stringer
Value : runtime.stringer
func Append(s Value, x ...Value) Value
func AppendSlice(s, t Value) Value
func Indirect(v Value) Value
func MakeChan(typ Type, buffer int) Value
func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value
func MakeMap(typ Type) Value
func MakeMapWithSize(typ Type, n int) Value
func MakeSlice(typ Type, len, cap int) Value
func New(typ Type) Value
func NewAt(typ Type, p unsafe.Pointer) Value
func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)
func ValueOf(i any) Value
func Zero(typ Type) Value
func (*MapIter).Key() Value
func (*MapIter).Value() Value
func Value.Addr() Value
func Value.Call(in []Value) []Value
func Value.CallSlice(in []Value) []Value
func Value.Convert(t Type) Value
func Value.Elem() Value
func Value.Field(i int) Value
func Value.FieldByIndex(index []int) Value
func Value.FieldByIndexErr(index []int) (Value, error)
func Value.FieldByName(name string) Value
func Value.FieldByNameFunc(match func(string) bool) Value
func Value.Index(i int) Value
func Value.MapIndex(key Value) Value
func Value.MapKeys() []Value
func Value.Method(i int) Value
func Value.MethodByName(name string) Value
func Value.Recv() (x Value, ok bool)
func Value.Slice(i, j int) Value
func Value.Slice3(i, j, k int) Value
func Value.TryRecv() (x Value, ok bool)
func copyVal(typ *abi.Type, fl flag, ptr unsafe.Pointer) Value
func cvtBytesString(v Value, t Type) Value
func cvtComplex(v Value, t Type) Value
func cvtDirect(v Value, typ Type) Value
func cvtFloat(v Value, t Type) Value
func cvtFloatInt(v Value, t Type) Value
func cvtFloatUint(v Value, t Type) Value
func cvtI2I(v Value, typ Type) Value
func cvtInt(v Value, t Type) Value
func cvtIntFloat(v Value, t Type) Value
func cvtIntString(v Value, t Type) Value
func cvtRunesString(v Value, t Type) Value
func cvtSliceArray(v Value, t Type) Value
func cvtSliceArrayPtr(v Value, t Type) Value
func cvtStringBytes(v Value, t Type) Value
func cvtStringRunes(v Value, t Type) Value
func cvtT2I(v Value, typ Type) Value
func cvtUint(v Value, t Type) Value
func cvtUintFloat(v Value, t Type) Value
func cvtUintString(v Value, t Type) Value
func makeBytes(f flag, v []byte, t Type) Value
func makeComplex(f flag, v complex128, t Type) Value
func makeFloat(f flag, v float64, t Type) Value
func makeFloat32(f flag, v float32, t Type) Value
func makeInt(f flag, bits uint64, t Type) Value
func makeMethodValue(op string, v Value) Value
func makeRunes(f flag, v []rune, t Type) Value
func makeString(f flag, v string, t Type) Value
func unpackEface(i any) Value
func Value.assignTo(context string, dst *abi.Type, target unsafe.Pointer) Value
func Value.call(op string, in []Value) []Value
func Value.extendSlice(n int) Value
func Value.recv(nb bool) (val Value, ok bool)
func encoding/asn1.parseSequenceOf(bytes []byte, sliceType Type, elemType Type) (ret Value, err error)
func encoding/json.indirect(v Value, decodingNull bool) (json.Unmarshaler, encoding.TextUnmarshaler, Value)
func fmt.getField(v Value, i int) Value
func go.opentelemetry.io/otel/attribute.Distinct.reflectValue() Value
func Append(s Value, x ...Value) Value
func Append(s Value, x ...Value) Value
func AppendSlice(s, t Value) Value
func Copy(dst, src Value) int
func Indirect(v Value) Value
func (*MapIter).Reset(v Value)
func Value.Call(in []Value) []Value
func Value.CallSlice(in []Value) []Value
func Value.Equal(u Value) bool
func Value.MapIndex(key Value) Value
func Value.Send(x Value)
func Value.Set(x Value)
func Value.SetMapIndex(key, elem Value)
func Value.TrySend(x Value) bool
func internal/fmtsort.Sort(mapValue Value) *fmtsort.SortedMap
func cvtBytesString(v Value, t Type) Value
func cvtComplex(v Value, t Type) Value
func cvtDirect(v Value, typ Type) Value
func cvtFloat(v Value, t Type) Value
func cvtFloatInt(v Value, t Type) Value
func cvtFloatUint(v Value, t Type) Value
func cvtI2I(v Value, typ Type) Value
func cvtInt(v Value, t Type) Value
func cvtIntFloat(v Value, t Type) Value
func cvtIntString(v Value, t Type) Value
func cvtRunesString(v Value, t Type) Value
func cvtSliceArray(v Value, t Type) Value
func cvtSliceArrayPtr(v Value, t Type) Value
func cvtStringBytes(v Value, t Type) Value
func cvtStringRunes(v Value, t Type) Value
func cvtT2I(v Value, typ Type) Value
func cvtUint(v Value, t Type) Value
func cvtUintFloat(v Value, t Type) Value
func cvtUintString(v Value, t Type) Value
func deepValueEqual(v1, v2 Value, visited map[visit]bool) bool
func makeMethodValue(op string, v Value) Value
func methodReceiver(op string, v Value, methodIndex int) (rcvrtype *abi.Type, t *funcType, fn unsafe.Pointer)
func packEface(v Value) any
func storeRcvr(v Value, p unsafe.Pointer)
func valueInterface(v Value, safe bool) any
func Value.call(op string, in []Value) []Value
func Value.send(x Value, nb bool) (selected bool)
func encoding/asn1.makeBody(value Value, params asn1.fieldParameters) (e asn1.encoder, err error)
func encoding/asn1.makeField(v Value, params asn1.fieldParameters) (e asn1.encoder, err error)
func encoding/asn1.parseField(v Value, bytes []byte, initOffset int, params asn1.fieldParameters) (offset int, err error)
func encoding/asn1.setDefaultValue(v Value, params asn1.fieldParameters) (ok bool)
func encoding/binary.dataSize(v Value) int
func encoding/json.addrMarshalerEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.addrTextMarshalerEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.boolEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.encodeByteSlice(e *json.encodeState, v Value, _ json.encOpts)
func encoding/json.indirect(v Value, decodingNull bool) (json.Unmarshaler, encoding.TextUnmarshaler, Value)
func encoding/json.intEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.interfaceEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.invalidValueEncoder(e *json.encodeState, v Value, _ json.encOpts)
func encoding/json.isEmptyValue(v Value) bool
func encoding/json.marshalerEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.stringEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.textMarshalerEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.uintEncoder(e *json.encodeState, v Value, opts json.encOpts)
func encoding/json.unsupportedTypeEncoder(e *json.encodeState, v Value, _ json.encOpts)
func encoding/json.valueEncoder(v Value) json.encoderFunc
func fmt.getField(v Value, i int) Value
func github.com/gotd/td/tdp.formatValue(b *strings.Builder, prefix, fieldName string, opt tdp.options, v Value)
func internal/fmtsort.compare(aVal, bVal Value) int
func internal/fmtsort.nilCompare(aVal, bVal Value) (int, bool)
A ValueError occurs when a Value method is invoked on
a Value that does not support it. Such cases are documented
in the description of each method.KindKindMethodstring(*ValueError) Error() string
*ValueError : error
abiDesc describes the ABI for a function or method. call and ret represent the translation steps for
the call and return paths of a Go function. inRegPtrs is a bitmap whose i'th bit indicates
whether the i'th integer argument register contains
a pointer. Used by makeFuncStub and methodValueCall
to make result pointers visible to the GC.
outRegPtrs is the same, but for result values.
Used by reflectcall to make result pointers visible
to the GC. inRegPtrs is a bitmap whose i'th bit indicates
whether the i'th integer argument register contains
a pointer. Used by makeFuncStub and methodValueCall
to make result pointers visible to the GC.
outRegPtrs is the same, but for result values.
Used by reflectcall to make result pointers visible
to the GC. call and ret represent the translation steps for
the call and return paths of a Go function. These fields describe the stack space allocated
for the call. stackCallArgsSize is the amount of space
reserved for arguments but not return values. retOffset
is the offset at which return values begin, and
spill is the size in bytes of additional space reserved
to spill argument registers into in case of preemption in
reflectcall's stack frame. These fields describe the stack space allocated
for the call. stackCallArgsSize is the amount of space
reserved for arguments but not return values. retOffset
is the offset at which return values begin, and
spill is the size in bytes of additional space reserved
to spill argument registers into in case of preemption in
reflectcall's stack frame. These fields describe the stack space allocated
for the call. stackCallArgsSize is the amount of space
reserved for arguments but not return values. retOffset
is the offset at which return values begin, and
spill is the size in bytes of additional space reserved
to spill argument registers into in case of preemption in
reflectcall's stack frame. stackPtrs is a bitmap that indicates whether
each word in the ABI stack space (stack-assigned
args + return values) is a pointer. Used
as the heap pointer bitmap for stack space
passed to reflectcall.(*abiDesc) dump()
func funcLayout(t *funcType, rcvr *abi.Type) (frametype *abi.Type, framePool *sync.Pool, abid abiDesc)
func newAbiDesc(t *funcType, rcvr *abi.Type) abiDesc
abiSeq represents a sequence of ABI instructions for copying
from a series of reflect.Values to a call frame (for call arguments)
or vice-versa (for call results).
An abiSeq should be populated by calling its addArg method. // registers used // registers used // stack space used steps is the set of instructions.
The instructions are grouped together by whole arguments,
with the starting index for the instructions
of the i'th Go value available in valueStart.
For instance, if this abiSeq represents 3 arguments
passed to a function, then the 2nd argument's steps
begin at steps[valueStart[1]].
Because reflect accepts Go arguments in distinct
Values and each Value is stored separately, each abiStep
that begins a new argument will have its offset
field == 0.valueStart[]int 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. 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. 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. 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.(*abiSeq) dump() 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. 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. stepsForValue returns the ABI instructions for translating
the i'th Go argument or return value represented by this
abiSeq to the Go ABI.
abiStep represents an ABI "instruction." Each instruction
describes one part of how to translate between a Go value
in memory and a call frame. // FP register index, used if kind == abiStepFloatReg // integer register index, used if kind == abiStepIntReg or kind == abiStepPointerkindabiStepKind offset and size together describe a part of a Go value
in memory. // size in bytes of the part These fields describe the ABI side of the translation. // stack offset, used if kind == abiStepStack
Note: this type must agree with runtime.bitvector.data[]byte // number of bits append a bit to the bitmap.
func addTypeBits(bv *bitVector, offset uintptr, t *abi.Type)
A cacheKey is the key for use in the lookupCache.
Four values describe any of the types we are looking for:
type kind, one or two subtypes, and an extra integer.extrauintptrkindKindt1*abi.Typet2*abi.Type
chanType represents a channel type.
Embed this type to get common/uncommonTypeabi.Type // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type GCData stores the GC type data for the garbage collector.
If the KindGCProg bit is set in kind, GCData is a GC program.
Otherwise it is a ptrmask bitmap. See mbitmap.go for details. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zeroType.Size_uintptr // string form // extra type information flags Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match. ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).(*common) Common() *abi.Type Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.(*common) ExportedMethods() []abi.Method(*common) FieldAlign() int FuncType returns t cast to a *FuncType, or nil if its tag does not match.(*common) GcSlice(begin, end uintptr) []byte(*common) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value. InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.(*common) Key() *abi.Type(*common) Kind() abi.Kind Len returns the length of t if t is an array type, otherwise 0 MapType returns t cast to a *MapType, or nil if its tag does not match.(*common) NumMethod() int(*common) Pointers() bool Size returns the size of data with type t. StructType returns t cast to a *StructType, or nil if its tag does not match. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil
A fieldScan represents an item on the fieldByNameFunc scan work list.index[]inttyp*structType
( flag) kind() Kind 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. 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.( flag) mustBeAssignableSlow() mustBeExported panics if f records that the value was obtained using
an unexported field.( flag) mustBeExportedSlow() 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.( flag) ro() flag
func copyVal(typ *abi.Type, fl flag, ptr unsafe.Pointer) Value
func makeBytes(f flag, v []byte, t Type) Value
func makeComplex(f flag, v complex128, t Type) Value
func makeFloat(f flag, v float64, t Type) Value
func makeFloat32(f flag, v float32, t Type) Value
func makeInt(f flag, bits uint64, t Type) Value
func makeRunes(f flag, v []rune, t Type) Value
func makeString(f flag, v string, t Type) Value
const flagAddr
const flagEmbedRO
const flagIndir
const flagKindMask
const flagMethod
const flagRO
const flagStickyRO
funcType represents a function type.
A *rtype for each in and out parameter is stored in an array that
directly follows the funcType (and possibly its uncommonType). So
a function type with one method, one input, and one output is:
struct {
funcType
uncommonType
[2]*rtype // [0] is in, [1] is out
}
interfaceType represents an interface type. // can embed directly because not a public type. // sorted by hash // import pathInterfaceType.Typeabi.Type // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type GCData stores the GC type data for the garbage collector.
If the KindGCProg bit is set in kind, GCData is a GC program.
Otherwise it is a ptrmask bitmap. See mbitmap.go for details. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zeroInterfaceType.Type.Size_uintptr // string form // extra type information flags Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match. ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).(*interfaceType) Common() *abi.Type Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.(*interfaceType) ExportedMethods() []abi.Method(*interfaceType) FieldAlign() int FuncType returns t cast to a *FuncType, or nil if its tag does not match.(*interfaceType) GcSlice(begin, end uintptr) []byte(*interfaceType) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value. isDirectIface reports whether t is stored directly in an interface value.(*interfaceType) Key() *abi.Type(*interfaceType) Kind() abi.Kind Len returns the length of t if t is an array type, otherwise 0 MapType returns t cast to a *MapType, or nil if its tag does not match. Method returns the i'th method in the type's method set. MethodByName method with the given name in the type's method set. NumMethod returns the number of interface methods in the type's method set.(*interfaceType) Pointers() bool Size returns the size of data with type t. StructType returns t cast to a *StructType, or nil if its tag does not match. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil(*interfaceType) common() *abi.Type(*interfaceType) nameOff(off aNameOff) abi.Name(*interfaceType) typeOff(off aTypeOff) *abi.Type(*interfaceType) uncommon() *abi.UncommonType
// function signature // receiver type, or nil if none
This structure must be kept in sync with runtime.reflectMethodValue.
Any changes should be reflected in all both. // just argsfnuintptrregPtrsabi.IntArgRegBitmap // ptrmap for both stack args and results
func moveMakeFuncArgPtrs(ctxt *makeFuncCtxt, args *abi.RegArgs)
mapType represents a map type.MapTypeabi.MapType // internal type representing a hash bucket // size of bucketMapType.Elem*abi.TypeMapType.Flagsuint32 function for hashing keys (ptr to key, seed) -> hashMapType.Key*abi.Type // size of key slotMapType.Typeabi.Type // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type GCData stores the GC type data for the garbage collector.
If the KindGCProg bit is set in kind, GCData is a GC program.
Otherwise it is a ptrmask bitmap. See mbitmap.go for details. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zeroMapType.Type.Size_uintptr // string form // extra type information flags // size of elem slot Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match. ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).(*mapType) Common() *abi.Type(*mapType) ExportedMethods() []abi.Method(*mapType) FieldAlign() int FuncType returns t cast to a *FuncType, or nil if its tag does not match.(*mapType) GcSlice(begin, end uintptr) []byte(*mapType) HasName() bool(*mapType) HashMightPanic() bool IfaceIndir reports whether t is stored indirectly in an interface value.(*mapType) IndirectElem() bool Note: flag values must match those used in the TMAP case
in ../cmd/compile/internal/reflectdata/reflect.go:writeType. InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.(*mapType) Kind() abi.Kind Len returns the length of t if t is an array type, otherwise 0(*mapType) NeedKeyUpdate() bool(*mapType) NumMethod() int(*mapType) Pointers() bool(*mapType) ReflexiveKey() bool Size returns the size of data with type t. StructType returns t cast to a *StructType, or nil if its tag does not match. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil
nonEmptyInterface is the header for an interface value with methods. see ../runtime/iface.go:/Itabwordunsafe.Pointer
ptrType represents a pointer type.PtrTypeabi.PtrType // slice element typePtrType.Typeabi.Type // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type GCData stores the GC type data for the garbage collector.
If the KindGCProg bit is set in kind, GCData is a GC program.
Otherwise it is a ptrmask bitmap. See mbitmap.go for details. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zeroPtrType.Type.Size_uintptr // string form // extra type information flags Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match. ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).(*ptrType) Common() *abi.Type(*ptrType) ExportedMethods() []abi.Method(*ptrType) FieldAlign() int FuncType returns t cast to a *FuncType, or nil if its tag does not match.(*ptrType) GcSlice(begin, end uintptr) []byte(*ptrType) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value. InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.(*ptrType) Key() *abi.Type(*ptrType) Kind() abi.Kind Len returns the length of t if t is an array type, otherwise 0 MapType returns t cast to a *MapType, or nil if its tag does not match.(*ptrType) NumMethod() int(*ptrType) Pointers() bool Size returns the size of data with type t. StructType returns t cast to a *StructType, or nil if its tag does not match. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil
A runtimeSelect is a single case passed to rselect.
This must match ../runtime/select.go:/runtimeSelect // channel // SelectSend, SelectRecv or SelectDefault // channel type // ptr to data (SendDir) or ptr to receive buffer (RecvDir)
func rselect([]runtimeSelect) (chosen int, recvOK bool)
sliceType represents a slice type.SliceTypeabi.SliceType // slice element typeSliceType.Typeabi.Type // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type GCData stores the GC type data for the garbage collector.
If the KindGCProg bit is set in kind, GCData is a GC program.
Otherwise it is a ptrmask bitmap. See mbitmap.go for details. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zeroSliceType.Type.Size_uintptr // string form // extra type information flags Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match. ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).(*sliceType) Common() *abi.Type(*sliceType) ExportedMethods() []abi.Method(*sliceType) FieldAlign() int FuncType returns t cast to a *FuncType, or nil if its tag does not match.(*sliceType) GcSlice(begin, end uintptr) []byte(*sliceType) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value. InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.(*sliceType) Key() *abi.Type(*sliceType) Kind() abi.Kind Len returns the length of t if t is an array type, otherwise 0 MapType returns t cast to a *MapType, or nil if its tag does not match.(*sliceType) NumMethod() int(*sliceType) Pointers() bool Size returns the size of data with type t. StructType returns t cast to a *StructType, or nil if its tag does not match. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil
Struct field
structType represents a struct type.StructTypeabi.StructTypeStructType.Fields[]abi.StructFieldStructType.PkgPathabi.NameStructType.Typeabi.Type // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type GCData stores the GC type data for the garbage collector.
If the KindGCProg bit is set in kind, GCData is a GC program.
Otherwise it is a ptrmask bitmap. See mbitmap.go for details. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zeroStructType.Type.Size_uintptr // string form // extra type information flags Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match. ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).(*structType) Common() *abi.Type Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.(*structType) ExportedMethods() []abi.Method Field returns the i'th struct field.(*structType) FieldAlign() int FieldByIndex returns the nested field corresponding to index. FieldByName returns the struct field with the given name
and a boolean to indicate if the field was found. FieldByNameFunc returns the struct field with a name that satisfies the
match function and a boolean to indicate if the field was found. FuncType returns t cast to a *FuncType, or nil if its tag does not match.(*structType) GcSlice(begin, end uintptr) []byte(*structType) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value. InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.(*structType) Key() *abi.Type(*structType) Kind() abi.Kind Len returns the length of t if t is an array type, otherwise 0 MapType returns t cast to a *MapType, or nil if its tag does not match.(*structType) NumMethod() int(*structType) Pointers() bool Size returns the size of data with type t. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil
structType.StructTypeabi.StructTypestructType.StructType.Fields[]abi.StructFieldstructType.StructType.PkgPathabi.NamestructType.StructType.Typeabi.Type // alignment of variable with this type function for comparing objects of this type
(ptr to object A, ptr to object B) -> ==? // alignment of struct field with this type GCData stores the GC type data for the garbage collector.
If the KindGCProg bit is set in kind, GCData is a GC program.
Otherwise it is a ptrmask bitmap. See mbitmap.go for details. // hash of type; avoids computation in hash tables // enumeration for C // number of (prefix) bytes in the type that can contain pointers // type for pointer to this type, may be zerostructType.StructType.Type.Size_uintptr // string form // extra type information flagsstructTypestructTypeuuncommonType Align returns the alignment of data with type t. ArrayType returns t cast to a *ArrayType, or nil if its tag does not match. ChanDir returns the direction of t if t is a channel type, otherwise InvalidDir (0).(*structTypeUncommon) Common() *abi.Type Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.(*structTypeUncommon) ExportedMethods() []abi.Method Field returns the i'th struct field.(*structTypeUncommon) FieldAlign() int FieldByIndex returns the nested field corresponding to index. FieldByName returns the struct field with the given name
and a boolean to indicate if the field was found. FieldByNameFunc returns the struct field with a name that satisfies the
match function and a boolean to indicate if the field was found. FuncType returns t cast to a *FuncType, or nil if its tag does not match.(*structTypeUncommon) GcSlice(begin, end uintptr) []byte(*structTypeUncommon) HasName() bool IfaceIndir reports whether t is stored indirectly in an interface value. InterfaceType returns t cast to a *InterfaceType, or nil if its tag does not match. isDirectIface reports whether t is stored directly in an interface value.(*structTypeUncommon) Key() *abi.Type(*structTypeUncommon) Kind() abi.Kind Len returns the length of t if t is an array type, otherwise 0 MapType returns t cast to a *MapType, or nil if its tag does not match.(*structTypeUncommon) NumMethod() int(*structTypeUncommon) Pointers() bool Size returns the size of data with type t. Uncommon returns a pointer to T's "uncommon" data if there is any, otherwise nil
uncommonType is present only for defined types or types with methods
(if T is a defined type, the uncommonTypes for T and *T have methods).
Using a pointer to this struct reduces the overall size required
to describe a non-defined type with no methods.
byNamemap[string]intfields[]StructFieldindex[]intvisitingmap[Type]bool 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.
During deepValueEqual, must keep track of checks that are
in progress. The comparison algorithm assumes that all
checks in progress are true when it reencounters them.
Visited comparisons are stored in a map indexed by visit.a1unsafe.Pointera2unsafe.PointertypType
func deepValueEqual(v1, v2 Value, visited map[visit]bool) bool
Package-Level Functions (total 166, in which 26 are exported)
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.
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.
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.
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.
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.
As a special case, src can have kind String if the element type of dst is kind Uint8.
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.
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.
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.
MakeChan creates a new channel with the specified type and buffer size.
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.
MakeMap creates a new map with the specified type.
MakeMapWithSize creates a new map with the specified type
and initial space for approximately n elements.
MakeSlice creates a new zero-initialized slice value
for the specified slice type, length, and capacity.
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.
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).
NewAt returns a Value representing a pointer to a value of the
specified type, using p as that pointer.
PointerTo returns the pointer type with element t.
For example, if t represents type Foo, PointerTo(t) represents *Foo.
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.
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.
SliceOf returns the slice type with element type t.
For example, if t represents int, SliceOf(t) represents []int.
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 generate wrapper methods for embedded
fields and panics if passed unexported StructFields.
These limitations may be lifted in a future version.
Swapper returns a function that swaps the elements in the provided
slice.
Swapper panics if the provided interface is not a slice.
TypeOf returns the reflection Type that represents the dynamic type of i.
If i is a nil interface value, TypeOf returns nil.
ValueOf returns a new Value initialized to the concrete value
stored in the interface i. ValueOf(nil) returns the zero Value.
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).
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.
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.
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.
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.)
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.
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 makeVethodValue.
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.
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.
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.
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.
copyVal returns a Value containing the map key or value at ptr,
allocating a new variable as needed.
convertOp: []byte -> string
convertOp: complexXX -> complexXX
convertOp: direct copy
convertOp: floatXX -> floatXX
convertOp: floatXX -> intXX
convertOp: floatXX -> uintXX
convertOp: interface -> interface
convertOp: intXX -> [u]intXX
convertOp: intXX -> floatXX
convertOp: intXX -> string
convertOp: []rune -> string
convertOp: []T -> [N]T
convertOp: []T -> *[N]T
convertOp: string -> []byte
convertOp: string -> []rune
convertOp: concrete -> interface
convertOp: uintXX -> [u]intXX
convertOp: uintXX -> floatXX
convertOp: uintXX -> string
Tests for deep equality using reflected types. The map argument tracks
comparisons that have already been seen, which allows short circuiting on
recursive types.
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).
emitGCMask writes the GC mask for [n]typ into out, starting at bit
offset base.
Dummy annotation marking that the value x escapes,
for use in cases where the reflect code is so clever that
the compiler cannot follow.
floatFromReg loads a float value from its register representation in r.
argSize must be 4 or 8.
floatToReg stores a float value in its register representation in r.
argSize must be either 4 or 8.
fnv1 incorporates the list of bytes into the hash x using the FNV-1 hash 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.
funcName returns the name of f, for use in error messages.
funcStr builds a string representation of a funcType.
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.
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.
isLetter reports whether a given 'rune' is classified as a Letter.
isReflexive reports whether the == operation on the type is reflexive.
That is, x == x for all values x of type t.
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 | "_" .
makeComplex returns a Value of type t equal to v (possibly truncated to complex64),
where t is a complex64 or complex128 type.
makeFloat returns a Value of type t equal to v (possibly truncated to float32),
where t is a float32 or float64 type.
makeFloat32 returns a Value of type t equal to v, where t is a float32 type.
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.
makeInt returns a Value of type t equal to bits (possibly truncated),
where t is a signed or unsigned int type.
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.
memmove copies size bytes to dst from src. No write barriers are used.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
rtypeOf directly extracts the *rtype of the provided value.
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.
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.
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.
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.
typedarrayclear zeroes the value at ptr of an array of elemType,
only clears len elem.
typedmemclr zeros the value at ptr of type t.
typedmemclrpartial is like typedmemclr but assumes that
dst points off bytes into the value and only clears size bytes.
typedmemmove copies a value of type t to dst from src.
typedslicecopy copies a slice of elemType values from src to dst,
returning the number of elements copied.
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.
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
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).
These variables are used by the register assignment
algorithm in this file.
They should be modified with care (no other reflect code
may be executing) and are generally only modified
when testing this package.
They should never be set higher than their internal/abi
constant counterparts, because the system relies on a
structure that is at least large enough to hold the
registers the system supports.
Currently they're set to zero because using the actual
constants will break every part of the toolchain that
uses reflect to call functions (e.g. go test, or anything
that uses text/template). The values that are currently
commented out there should be the actual values once
we're ready to use the register ABI everywhere.
These variables are used by the register assignment
algorithm in this file.
They should be modified with care (no other reflect code
may be executing) and are generally only modified
when testing this package.
They should never be set higher than their internal/abi
constant counterparts, because the system relies on a
structure that is at least large enough to hold the
registers the system supports.
Currently they're set to zero because using the actual
constants will break every part of the toolchain that
uses reflect to call functions (e.g. go test, or anything
that uses text/template). The values that are currently
commented out there should be the actual values once
we're ready to use the register ABI everywhere.
The funcLookupCache caches FuncOf lookups.
FuncOf does not share the common lookupCache since cacheKey is not
sufficient to represent functions unambiguously.
These variables are used by the register assignment
algorithm in this file.
They should be modified with care (no other reflect code
may be executing) and are generally only modified
when testing this package.
They should never be set higher than their internal/abi
constant counterparts, because the system relies on a
structure that is at least large enough to hold the
registers the system supports.
Currently they're set to zero because using the actual
constants will break every part of the toolchain that
uses reflect to call functions (e.g. go test, or anything
that uses text/template). The values that are currently
commented out there should be the actual values once
we're ready to use the register ABI everywhere.
The structLookupCache caches StructOf lookups.
StructOf does not share the common lookupCache since we need to pin
the memory associated with *structTypeFixedN.
Make sure these routines stay in sync with ../runtime/map.go!
These types exist only for GC, so we only fill out GC relevant info.
Currently, that's just size and the GC program. We also fill in string
for possible debugging use.
Before Go 1.21, ValueOf always escapes and a Value's content
is always heap allocated.
Set go121noForceValueEscape to true to avoid the forced escape,
allowing Value content to be on the stack.
Set go121noForceValueEscape to false for the legacy behavior
(for debugging).
Make sure these routines stay in sync with ../runtime/map.go!
These types exist only for GC, so we only fill out GC relevant info.
Currently, that's just size and the GC program. We also fill in string
for possible debugging use.
See cmd/compile/internal/reflectdata/reflect.go for derivation of constant.
Make sure these routines stay in sync with ../runtime/map.go!
These types exist only for GC, so we only fill out GC relevant info.
Currently, that's just size and the GC program. We also fill in string
for possible debugging use.
must match declarations in runtime/map.go.
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.