From: Mark Freeman Date: Mon, 18 Aug 2025 18:32:05 +0000 (-0400) Subject: types2: better documentation for resolve() X-Git-Tag: go1.26rc1~910 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=00824f5ff5913712710e449de8b7bbae51182197;p=gostls13.git types2: better documentation for resolve() Change-Id: Iece109dfbdc98d436b845148612f4943598697fe Reviewed-on: https://go-review.googlesource.com/c/go/+/697697 Reviewed-by: Robert Findley Commit-Queue: Mark Freeman LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go index dbb1fa0b3e..d02b95e874 100644 --- a/src/cmd/compile/internal/types2/named.go +++ b/src/cmd/compile/internal/types2/named.go @@ -162,12 +162,25 @@ func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named { } // resolve resolves the type parameters, methods, and underlying type of n. -// This information may be loaded from a provided loader function, or computed -// from an origin type (in the case of instances). // -// After resolution, the type parameters, methods, and underlying type of n are -// accessible; but if n is an instantiated type, its methods may still be -// unexpanded. +// For the purposes of resolution, there are three categories of named types: +// 1. Instantiated Types +// 2. Lazy Loaded Types +// 3. All Others +// +// Note that the above form a partition. +// +// Instantiated types: +// Type parameters, methods, and underlying type of n become accessible, +// though methods are lazily populated as needed. +// +// Lazy loaded types: +// Type parameters, methods, and underlying type of n become accessible +// and are fully expanded. +// +// All others: +// Effectively, nothing happens. The underlying type of n may still be +// a named type. func (n *Named) resolve() *Named { if n.state() > unresolved { // avoid locking below return n diff --git a/src/go/types/named.go b/src/go/types/named.go index 72fd4970bb..b2f99ffccb 100644 --- a/src/go/types/named.go +++ b/src/go/types/named.go @@ -165,12 +165,25 @@ func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named { } // resolve resolves the type parameters, methods, and underlying type of n. -// This information may be loaded from a provided loader function, or computed -// from an origin type (in the case of instances). // -// After resolution, the type parameters, methods, and underlying type of n are -// accessible; but if n is an instantiated type, its methods may still be -// unexpanded. +// For the purposes of resolution, there are three categories of named types: +// 1. Instantiated Types +// 2. Lazy Loaded Types +// 3. All Others +// +// Note that the above form a partition. +// +// Instantiated types: +// Type parameters, methods, and underlying type of n become accessible, +// though methods are lazily populated as needed. +// +// Lazy loaded types: +// Type parameters, methods, and underlying type of n become accessible +// and are fully expanded. +// +// All others: +// Effectively, nothing happens. The underlying type of n may still be +// a named type. func (n *Named) resolve() *Named { if n.state() > unresolved { // avoid locking below return n