]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: check for direct cycles as a separate phase
authorRobert Griesemer <gri@google.com>
Tue, 4 Nov 2025 00:54:43 +0000 (16:54 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 13 Nov 2025 19:39:17 +0000 (11:39 -0800)
commit57362e98140bdb964d05017690fb0aba37af6b48
treeb801790c28eaafebceacf3f789c0955265f4f2a9
parent099e0027bd7d282c400b1f5930d19a4652a265eb
go/types, types2: check for direct cycles as a separate phase

A direct cycle is the most basic form of cycle, where no type literal or
predeclared type is reached. It is formed by a series of only TypeNames.

To illustrate, type T T is a direct cycle, but type T [1]T and type T *T
are not. Likewise, the below is also a direct cycle:

  type A B
  type B C
  type C = A

Direct cycles are handled explicitly as part of resolveUnderlying, since
they are the only cycle which can prevent reaching an underlying type.
If we move this check to an earlier compiler phase, we can simplify
resolveUnderlying.

This is the first of (hopefully) several cycle kinds to be moved into a
preliminary phase, with the goal of simplifying the main type-checking
pass. For that reason, the bulk of the logic is placed in cycles.go.

CL based on an earlier version by Mark Freeman.

Change-Id: I3044c383278deb6acb8767c498d8cb68099ba8ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/717343
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/cycles.go [new file with mode: 0644]
src/cmd/compile/internal/types2/named.go
src/go/types/check.go
src/go/types/cycles.go [new file with mode: 0644]
src/go/types/named.go