aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal
diff options
context:
space:
mode:
authorRobert Griesemer <gri@google.com>2025-10-16 16:58:25 -0700
committerGopher Robot <gobot@golang.org>2025-10-22 08:20:32 -0700
commit4bdb55b5b86fc96addd43a845dabf6b76d100202 (patch)
tree40e1af998e765337967fcd1ea855bf461e020a7b /src/cmd/compile/internal
parent29d43df8ab212910487345c354491b67780798cf (diff)
downloadgo-4bdb55b5b86fc96addd43a845dabf6b76d100202.tar.xz
go/types, types2: rename Named.under to Named.resolveUnderlying
Named.resolveUnderlying is now just a helper function for Underlying and only called from there. The name makes is clearer what this function does; it also doesn't need to return a result anymore. While at it, slightly simplify the function body. Change-Id: I167c4be89b1bfcc69f6b528ddb6ed4c90481194a Reviewed-on: https://go-review.googlesource.com/c/go/+/712521 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/cmd/compile/internal')
-rw-r--r--src/cmd/compile/internal/types2/named.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go
index 8f3249e44e..856f33028a 100644
--- a/src/cmd/compile/internal/types2/named.go
+++ b/src/cmd/compile/internal/types2/named.go
@@ -335,7 +335,7 @@ func (n *Named) cleanup() {
// Instances can have a nil underlying at the end of type checking — they
// will lazily expand it as needed. All other types must have one.
if n.inst == nil {
- n.resolve().under()
+ n.Underlying()
}
n.check = nil
}
@@ -562,7 +562,8 @@ func (n *Named) Underlying() Type {
}
}
- return n.under()
+ n.resolveUnderlying()
+ return n.underlying
}
func (t *Named) String() string { return TypeString(t, nil) }
@@ -573,7 +574,7 @@ func (t *Named) String() string { return TypeString(t, nil) }
// TODO(rfindley): reorganize the loading and expansion methods under this
// heading.
-// under returns the (possibly expanded) underlying type of n.
+// resolveUnderlying computes the underlying type of n.
//
// It does so by following RHS type chains. If a type literal is found, each
// named type in the chain has its underlying set to that type. Aliases are
@@ -581,24 +582,22 @@ func (t *Named) String() string { return TypeString(t, nil) }
//
// This function also checks for instantiated layout cycles, which are
// reachable only in the case where resolve() expanded an instantiated
-// type which became self-referencing without indirection. If such a
-// cycle is found, the result is Typ[Invalid]; if n.check != nil, the
-// cycle is also reported.
-func (n *Named) under() Type {
+// type which became self-referencing without indirection.
+// If such a cycle is found, the underlying type is set to Typ[Invalid]
+// and a cycle is reported.
+func (n *Named) resolveUnderlying() {
assert(n.stateHas(resolved))
// optimization for likely case
if n.stateHas(underlying) {
- return n.underlying
+ return
}
- var rhs Type = n
- var u Type
-
seen := make(map[*Named]int)
var path []Object
- for u == nil {
+ var u Type
+ for rhs := Type(n); u == nil; {
switch t := rhs.(type) {
case nil:
u = Typ[Invalid]
@@ -608,6 +607,8 @@ func (n *Named) under() Type {
case *Named:
if i, ok := seen[t]; ok {
+ // Note: This code may only be called during type checking,
+ // hence n.check != nil.
n.check.cycleError(path[i:], firstInSrc(path[i:]))
u = Typ[Invalid]
break
@@ -635,13 +636,11 @@ func (n *Named) under() Type {
}
}
- // go back up the chain
+ // set underlying for all Named types in the chain
for t := range seen {
t.underlying = u
t.setState(underlying)
}
-
- return u
}
func (n *Named) lookupMethod(pkg *Package, name string, foldCase bool) (int, *Func) {