]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/types2: add loaded state between loader calls and constraint...
authorMark Freeman <mark@golang.org>
Fri, 13 Jun 2025 15:47:57 +0000 (11:47 -0400)
committerGo LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Fri, 25 Jul 2025 20:42:54 +0000 (13:42 -0700)
commit7b53d8d06ec432b1434b675b96a11526de6e6abe
treea5ae15be31f38be1ad9b53ca273a1f30d4ed9d1a
parent374e3be2eb9b546ef1340f750e343c15a8f87dde
cmd/compile/internal/types2: add loaded state between loader calls and constraint expansion

There is a deadlock issue when calling SetConstraint from a lazy loader
because the loader is called from resolve(), which is holding a lock on
the loaded type.

If the loaded type has a generic constraint which refers back to the
loaded type (such as an argument or result), then we will loop back to
the loaded type and deadlock.

This change postpones calls to SetConstraint and passes them back to
resolve(). At that point, the loaded type is mostly constructed, but
its constraints might be unexpanded.

Similar to how we handle resolved instances, we advance the state for
the loaded type to a, appropriately named, loaded state. When we expand
the constraint, we don't try to acquire the lock on the loaded type.
Thus, no deadlock.

Fixes #63285

Change-Id: Ie0204b58a5b433f6d839ce8fd8a99542246367b7
Reviewed-on: https://go-review.googlesource.com/c/go/+/681875
Commit-Queue: Mark Freeman <mark@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/compile/internal/importer/gcimporter_test.go
src/cmd/compile/internal/importer/testdata/issue63285.go [new file with mode: 0644]
src/cmd/compile/internal/importer/ureader.go
src/cmd/compile/internal/types2/named.go
src/cmd/compile/internal/types2/object.go
src/go/types/named.go
src/go/types/object.go