return (*Type)(NoEscape(unsafe.Pointer(eface.Type)))
}
+// TypeFor returns the abi.Type for a type parameter.
+func TypeFor[T any]() *Type {
+ var v T
+ if t := TypeOf(v); t != nil {
+ return t // optimize for T being a non-interface kind
+ }
+ return TypeOf((*T)(nil)).Elem() // only for an interface kind
+}
+
func (t *Type) Kind() Kind { return t.Kind_ & KindMask }
func (t *Type) HasName() bool {
func testCloneSeq[T any](t *testing.T, want cloneSeq) {
typName := reflect.TypeFor[T]().Name()
- typ := abi.TypeOf(*new(T))
+ typ := abi.TypeFor[T]()
t.Run(typName, func(t *testing.T) {
got := makeCloneSeq(typ)
if !reflect.DeepEqual(got, want) {
// are equal if and only if the values used to produce them are equal.
func Make[T comparable](value T) Handle[T] {
// Find the map for type T.
- typ := abi.TypeOf(value)
+ typ := abi.TypeFor[T]()
ma, ok := uniqueMaps.Load(typ)
if !ok {
// This is a good time to initialize cleanup, since we must go through
s: [2]testStringStruct{testStringStruct{"y"}, testStringStruct{"z"}},
})
testHandle[testStruct](t, testStruct{0.5, "184"})
+ testHandle[testEface](t, testEface("hello"))
}
func testHandle[T comparable](t *testing.T, value T) {
func checkMapsFor[T comparable](t *testing.T, value T) {
// Manually load the value out of the map.
- typ := abi.TypeOf(value)
+ typ := abi.TypeFor[T]()
a, ok := uniqueMaps.Load(typ)
if !ok {
return