From 9fcdc814b200da8d7e5bc8c9b89e42393c26c63d Mon Sep 17 00:00:00 2001 From: Mark Freeman Date: Mon, 20 Oct 2025 16:29:44 -0400 Subject: [PATCH] go/types, types2: rename loaded namedState to lazyLoaded This is a minor renaming to help differentiate the two kinds of loading that can happen for named types (eager and lazy). Use of the term "loaded" suggests that it might also apply to types which are eagerly-loaded, which is not the case. This change uses "lazyLoaded" instead to mark this difference. Change-Id: Iee170024246d9adf3eed978bde2b0500f6d490b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/713282 Reviewed-by: Robert Griesemer Auto-Submit: Mark Freeman LUCI-TryBot-Result: Go LUCI --- src/cmd/compile/internal/types2/named.go | 20 ++++++++++---------- src/go/types/named.go | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go index 0823839d81c..a275e26a0c3 100644 --- a/src/cmd/compile/internal/types2/named.go +++ b/src/cmd/compile/internal/types2/named.go @@ -142,7 +142,7 @@ type instance struct { // according to the below diagram: // // unresolved -// loaded +// lazyLoaded // resolved // └── hasMethods // └── hasUnder @@ -158,9 +158,9 @@ type instance struct { // set left-to-right, they are: // // 0000 | unresolved -// 1000 | loaded -// 1100 | resolved, which implies loaded -// 1110 | hasMethods, which implies resolved (which in turn implies loaded) +// 1000 | lazyLoaded +// 1100 | resolved, which implies lazyLoaded +// 1110 | hasMethods, which implies resolved (which in turn implies lazyLoaded) // 1101 | hasUnder, which implies resolved ... // 1111 | both hasMethods and hasUnder which implies resolved ... // @@ -169,9 +169,9 @@ type stateMask uint32 const ( // before resolved, type parameters, RHS, underlying, and methods might be unavailable - resolved stateMask = 1 << iota // methods might be unexpanded (for instances) + lazyLoaded stateMask = 1 << iota // methods are available, but constraints might be unexpanded (for generic types) + resolved // methods might be unexpanded (for instances) hasMethods // methods are all expanded (for instances) - loaded // methods are available, but constraints might be unexpanded (for generic types) hasUnder // underlying type is available ) @@ -213,7 +213,7 @@ func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named { // All others: // Effectively, nothing happens. func (n *Named) resolve() *Named { - if n.stateHas(resolved | loaded) { // avoid locking below + if n.stateHas(resolved | lazyLoaded) { // avoid locking below return n } @@ -223,7 +223,7 @@ func (n *Named) resolve() *Named { defer n.mu.Unlock() // only atomic for consistency; we are holding the mutex - if n.stateHas(resolved | loaded) { + if n.stateHas(resolved | lazyLoaded) { return n } @@ -267,7 +267,7 @@ func (n *Named) resolve() *Named { n.fromRHS = underlying // for cycle detection n.methods = methods - n.setState(loaded) // avoid deadlock calling delayed functions + n.setState(lazyLoaded) // avoid deadlock calling delayed functions for _, f := range delayed { f() } @@ -716,7 +716,7 @@ func (n *Named) expandRHS() (rhs Type) { } assert(!n.stateHas(resolved)) - assert(n.inst.orig.stateHas(resolved | loaded)) + assert(n.inst.orig.stateHas(resolved | lazyLoaded)) if n.inst.ctxt == nil { n.inst.ctxt = NewContext() diff --git a/src/go/types/named.go b/src/go/types/named.go index a0cb9abba1a..afdd68ae7f6 100644 --- a/src/go/types/named.go +++ b/src/go/types/named.go @@ -145,7 +145,7 @@ type instance struct { // according to the below diagram: // // unresolved -// loaded +// lazyLoaded // resolved // └── hasMethods // └── hasUnder @@ -161,9 +161,9 @@ type instance struct { // set left-to-right, they are: // // 0000 | unresolved -// 1000 | loaded -// 1100 | resolved, which implies loaded -// 1110 | hasMethods, which implies resolved (which in turn implies loaded) +// 1000 | lazyLoaded +// 1100 | resolved, which implies lazyLoaded +// 1110 | hasMethods, which implies resolved (which in turn implies lazyLoaded) // 1101 | hasUnder, which implies resolved ... // 1111 | both hasMethods and hasUnder which implies resolved ... // @@ -172,9 +172,9 @@ type stateMask uint32 const ( // before resolved, type parameters, RHS, underlying, and methods might be unavailable - resolved stateMask = 1 << iota // methods might be unexpanded (for instances) + lazyLoaded stateMask = 1 << iota // methods are available, but constraints might be unexpanded (for generic types) + resolved // methods might be unexpanded (for instances) hasMethods // methods are all expanded (for instances) - loaded // methods are available, but constraints might be unexpanded (for generic types) hasUnder // underlying type is available ) @@ -216,7 +216,7 @@ func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named { // All others: // Effectively, nothing happens. func (n *Named) resolve() *Named { - if n.stateHas(resolved | loaded) { // avoid locking below + if n.stateHas(resolved | lazyLoaded) { // avoid locking below return n } @@ -226,7 +226,7 @@ func (n *Named) resolve() *Named { defer n.mu.Unlock() // only atomic for consistency; we are holding the mutex - if n.stateHas(resolved | loaded) { + if n.stateHas(resolved | lazyLoaded) { return n } @@ -270,7 +270,7 @@ func (n *Named) resolve() *Named { n.fromRHS = underlying // for cycle detection n.methods = methods - n.setState(loaded) // avoid deadlock calling delayed functions + n.setState(lazyLoaded) // avoid deadlock calling delayed functions for _, f := range delayed { f() } @@ -719,7 +719,7 @@ func (n *Named) expandRHS() (rhs Type) { } assert(!n.stateHas(resolved)) - assert(n.inst.orig.stateHas(resolved | loaded)) + assert(n.inst.orig.stateHas(resolved | lazyLoaded)) if n.inst.ctxt == nil { n.inst.ctxt = NewContext()