go/types, types2: rename Named.finite to Named.varSize

Change-Id: I81646c2753c2e44953b116138cb41d41a011ff08
Reviewed-on: https://go-review.googlesource.com/c/go/+/739561
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Mark Freeman <markfreeman@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Mark Freeman 2026-01-27 10:53:21 -05:00 committed by Gopher Robot
parent d8d2b90a46
commit ffb50fb716
4 changed files with 30 additions and 32 deletions

View file

@ -1012,9 +1012,8 @@ func (check *Checker) hasVarSize(t Type) bool {
// better error messages.
switch t := Unalias(t).(type) {
case *Named:
if t.stateHas(hasFinite) {
// TODO(mark): Rename t.finite to t.varSize to avoid inversion.
return !t.finite
if t.stateHas(hasVarSize) {
return t.varSize
}
if i, ok := check.objPathIdx[t.obj]; ok {
@ -1031,19 +1030,19 @@ func (check *Checker) hasVarSize(t Type) bool {
t.mu.Lock()
defer t.mu.Unlock()
// Careful, t.finite has lock-free readers. Since we might be racing
// another call to finiteSize, we have to avoid overwriting t.finite.
// Careful, t.varSize has lock-free readers. Since we might be racing
// another call to hasVarSize, we have to avoid overwriting t.varSize.
// Otherwise, the race detector will be tripped.
if !t.stateHas(hasFinite) {
t.finite = !varSize
t.setState(hasFinite)
if !t.stateHas(hasVarSize) {
t.varSize = varSize
t.setState(hasVarSize)
}
return varSize
case *Array:
// The array length is already computed. If it was a valid length, it
// is finite; else, an error was reported in the computation.
// is constant; else, an error was reported in the computation.
return check.hasVarSize(t.elem)
case *Struct:

View file

@ -115,7 +115,7 @@ type Named struct {
fromRHS Type // the declaration RHS this type is derived from
tparams *TypeParamList // type parameters, or nil
underlying Type // underlying type, or nil
finite bool // whether the type has finite size
varSize bool // whether the type has variable size
// methods declared for this type (not the method set of this type)
// Signatures are type-checked lazily.
@ -147,10 +147,10 @@ type instance struct {
// unpacked
// └── hasMethods
// └── hasUnder
// └── hasFinite
// └── hasVarSize
//
// That is, descent down the tree is mostly linear (initial through unpacked), except upon
// reaching the leaves (hasMethods, hasUnder, and hasFinite). A type may occupy any
// reaching the leaves (hasMethods, hasUnder, and hasVarSize). A type may occupy any
// combination of the leaf states at once (they are independent states).
//
// To represent this independence, the set of active states is represented with a bit set. State
@ -164,7 +164,7 @@ type instance struct {
// 11000 | unpacked, which implies lazyLoaded
// 11100 | hasMethods, which implies unpacked (which in turn implies lazyLoaded)
// 11010 | hasUnder, which implies unpacked ...
// 11001 | hasFinite, which implies unpacked ...
// 11001 | hasVarSize, which implies unpacked ...
// 11110 | both hasMethods and hasUnder which implies unpacked ...
// ... | (other combinations of leaf states)
//
@ -177,7 +177,7 @@ const (
unpacked // methods might be unexpanded (for instances)
hasMethods // methods are all expanded (for instances)
hasUnder // underlying type is available
hasFinite // size finiteness is available
hasVarSize // varSize is available
)
// NewNamed returns a new named type for the given type name, underlying type, and associated methods.
@ -306,8 +306,8 @@ func (n *Named) setState(m stateMask) {
if m&hasUnder != 0 {
assert(u)
}
// hasFinite => unpacked
if m&hasFinite != 0 {
// hasVarSize => unpacked
if m&hasVarSize != 0 {
assert(u)
}
}

View file

@ -1015,9 +1015,8 @@ func (check *Checker) hasVarSize(t Type) bool {
// better error messages.
switch t := Unalias(t).(type) {
case *Named:
if t.stateHas(hasFinite) {
// TODO(mark): Rename t.finite to t.varSize to avoid inversion.
return !t.finite
if t.stateHas(hasVarSize) {
return t.varSize
}
if i, ok := check.objPathIdx[t.obj]; ok {
@ -1034,19 +1033,19 @@ func (check *Checker) hasVarSize(t Type) bool {
t.mu.Lock()
defer t.mu.Unlock()
// Careful, t.finite has lock-free readers. Since we might be racing
// another call to finiteSize, we have to avoid overwriting t.finite.
// Careful, t.varSize has lock-free readers. Since we might be racing
// another call to hasVarSize, we have to avoid overwriting t.varSize.
// Otherwise, the race detector will be tripped.
if !t.stateHas(hasFinite) {
t.finite = !varSize
t.setState(hasFinite)
if !t.stateHas(hasVarSize) {
t.varSize = varSize
t.setState(hasVarSize)
}
return varSize
case *Array:
// The array length is already computed. If it was a valid length, it
// is finite; else, an error was reported in the computation.
// is constant; else, an error was reported in the computation.
return check.hasVarSize(t.elem)
case *Struct:

View file

@ -118,7 +118,7 @@ type Named struct {
fromRHS Type // the declaration RHS this type is derived from
tparams *TypeParamList // type parameters, or nil
underlying Type // underlying type, or nil
finite bool // whether the type has finite size
varSize bool // whether the type has variable size
// methods declared for this type (not the method set of this type)
// Signatures are type-checked lazily.
@ -150,10 +150,10 @@ type instance struct {
// unpacked
// └── hasMethods
// └── hasUnder
// └── hasFinite
// └── hasVarSize
//
// That is, descent down the tree is mostly linear (initial through unpacked), except upon
// reaching the leaves (hasMethods, hasUnder, and hasFinite). A type may occupy any
// reaching the leaves (hasMethods, hasUnder, and hasVarSize). A type may occupy any
// combination of the leaf states at once (they are independent states).
//
// To represent this independence, the set of active states is represented with a bit set. State
@ -167,7 +167,7 @@ type instance struct {
// 11000 | unpacked, which implies lazyLoaded
// 11100 | hasMethods, which implies unpacked (which in turn implies lazyLoaded)
// 11010 | hasUnder, which implies unpacked ...
// 11001 | hasFinite, which implies unpacked ...
// 11001 | hasVarSize, which implies unpacked ...
// 11110 | both hasMethods and hasUnder which implies unpacked ...
// ... | (other combinations of leaf states)
//
@ -180,7 +180,7 @@ const (
unpacked // methods might be unexpanded (for instances)
hasMethods // methods are all expanded (for instances)
hasUnder // underlying type is available
hasFinite // size finiteness is available
hasVarSize // varSize is available
)
// NewNamed returns a new named type for the given type name, underlying type, and associated methods.
@ -309,8 +309,8 @@ func (n *Named) setState(m stateMask) {
if m&hasUnder != 0 {
assert(u)
}
// hasFinite => unpacked
if m&hasFinite != 0 {
// hasVarSize => unpacked
if m&hasVarSize != 0 {
assert(u)
}
}