Source File
typeparam.go
Belonging Package
go/types
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.// Source: ../../cmd/compile/internal/types2/typeparam.go// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package typesimport// Note: This is a uint32 rather than a uint64 because the// respective 64 bit atomic instructions are not available// on all platforms.var lastID atomic.Uint32// nextID returns a value increasing monotonically by 1 with// each call, starting with 1. It may be called concurrently.func () uint64 { return uint64(lastID.Add(1)) }// A TypeParam represents the type of a type parameter in a generic declaration.//// A TypeParam has a name; use the [TypeParam.Obj] method to access// its [TypeName] object.type TypeParam struct {check *Checker // for lazy type bound completionid uint64 // unique id, for debugging onlyobj *TypeName // corresponding type nameindex int // type parameter index in source order, starting at 0bound Type // any type, but underlying is eventually *Interface for correct programs (see TypeParam.iface)}// NewTypeParam returns a new TypeParam. Type parameters may be set on a Named// type by calling SetTypeParams. Setting a type parameter on more than one type// will result in a panic.//// The constraint argument can be nil, and set later via SetConstraint. If the// constraint is non-nil, it must be fully defined.func ( *TypeName, Type) *TypeParam {return (*Checker)(nil).newTypeParam(, )}// check may be nilfunc ( *Checker) ( *TypeName, Type) *TypeParam {// Always increment lastID, even if it is not used.:= nextID()if != nil {.nextID++= .nextID}:= &TypeParam{check: , id: , obj: , index: -1, bound: }if .typ == nil {.typ =}// iface may mutate typ.bound, so we must ensure that iface() is called// at least once before the resulting TypeParam escapes.if != nil {.needsCleanup()} else if != nil {.iface()}return}// Obj returns the type name for the type parameter t.func ( *TypeParam) () *TypeName { return .obj }// Index returns the index of the type param within its param list, or -1 if// the type parameter has not yet been bound to a type.func ( *TypeParam) () int {return .index}// Constraint returns the type constraint specified for t.func ( *TypeParam) () Type {return .bound}// SetConstraint sets the type constraint for t.//// It must be called by users of NewTypeParam after the bound's underlying is// fully defined, and before using the type parameter in any way other than to// form other types. Once SetConstraint returns the receiver, t is safe for// concurrent use.func ( *TypeParam) ( Type) {if == nil {panic("nil constraint")}.bound =// iface may mutate t.bound (if bound is not an interface), so ensure that// this is done before returning..iface()}// Underlying returns the [underlying type] of the type parameter t, which is// the underlying type of its constraint. This type is always an interface.//// [underlying type]: https://go.dev/ref/spec#Underlying_types.func ( *TypeParam) () Type {return .iface()}func ( *TypeParam) () string { return TypeString(, nil) }// ----------------------------------------------------------------------------// Implementationfunc ( *TypeParam) () {.iface().check = nil}// iface returns the constraint interface of t.func ( *TypeParam) () *Interface {:= .bound// determine constraint interfacevar *Interfaceswitch u := under().(type) {case *Basic:if !isValid() {// error is reported elsewherereturn &emptyInterface}case *Interface:if isTypeParam() {// error is reported in Checker.collectTypeParamsreturn &emptyInterface}=}// If we don't have an interface, wrap constraint into an implicit interface.if == nil {= NewInterfaceType(nil, []Type{}).implicit = true.bound = // update t.bound for next time (optimization)}// compute type set if necessaryif .tset == nil {// pos is used for tracing output; start with the type parameter position.:= .obj.pos// use the (original or possibly instantiated) type bound position if we have oneif := asNamed(); != nil {= .obj.pos}computeInterfaceTypeSet(.check, , )}return}// is calls f with the specific type terms of t's constraint and reports whether// all calls to f returned true. If there are no specific terms, is// returns the result of f(nil).func ( *TypeParam) ( func(*term) bool) bool {return .iface().typeSet().is()}// typeset is an iterator over the (type/underlying type) pairs of the// specific type terms of t's constraint.// If there are no specific terms, typeset calls yield with (nil, nil).// In any case, typeset is guaranteed to call yield at least once.func ( *TypeParam) ( func(, Type) bool) {.iface().typeSet().typeset()}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)