[go] go/types, types2: guard t.underlying with t.mu

1 view
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Oct 21, 2025, 4:51:38 PM (2 days ago) Oct 21
to Mark Freeman, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Robert Griesemer, Robert Findley, Michael Pratt, Alan Donovan, golang-co...@googlegroups.com

Gopher Robot submitted the change with unreviewed changes

Unreviewed changes

12 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/cmd/compile/internal/types2/named.go
Insertions: 1, Deletions: 2.

@@ -587,6 +587,7 @@
func (n *Named) under() Type {
assert(n.stateHas(resolved))

+ // optimization for likely case
if n.stateHas(underlying) {
return n.underlying
}
@@ -613,8 +614,6 @@
}

// acquire the lock without checking; performance is probably fine
-
- // else, we must also lock t and calculate t.underlying
t.resolve()
t.mu.Lock()
defer t.mu.Unlock()
```
```
The name of the file: src/go/types/named.go
Insertions: 1, Deletions: 2.

@@ -590,6 +590,7 @@
func (n *Named) under() Type {
assert(n.stateHas(resolved))

+ // optimization for likely case
if n.stateHas(underlying) {
return n.underlying
}
@@ -616,8 +617,6 @@
}

// acquire the lock without checking; performance is probably fine
-
- // else, we must also lock t and calculate t.underlying
t.resolve()
t.mu.Lock()
defer t.mu.Unlock()
```

Change information

Commit message:
go/types, types2: guard Named.underlying with Named.mu

It appears that CL 695977 introduced a data race on Named.underlying.
This fixes that race by specifying a new namedState called underlying,
which, perhaps unsurprisingly, signals that Named.underlying is populated.

Unfortunately, the underlying namedState is independent of the complete
namedState (unsurprising since methods and the underlying type are not related).

Hence, they cannot be ordered and thus do not fit the current integer-based
state representation. To account for combinations of states, we introduce a
bit set representation for namedState instead. The namedState field is also
renamed to stateMask to reflect this new representation.

Methods that operate on the stateMask are adjusted and exposition is added
throughout.

Fixes #75963
Change-Id: Icfa188ea2fa7916804c06f80668e99176bf4e978
Auto-Submit: Mark Freeman <markf...@google.com>
Reviewed-by: Robert Griesemer <g...@google.com>
Files:
  • M src/cmd/compile/internal/types2/named.go
  • M src/go/types/named.go
Change size: L
Delta: 2 files changed, 184 insertions(+), 90 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Robert Griesemer
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Icfa188ea2fa7916804c06f80668e99176bf4e978
Gerrit-Change-Number: 712720
Gerrit-PatchSet: 14
Gerrit-Owner: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
Gerrit-CC: Alan Donovan <adon...@google.com>
Gerrit-CC: Michael Pratt <mpr...@google.com>
Gerrit-CC: Robert Findley <rfin...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages