Skip to content

Commit ef69718

Browse files
cuonglmgopherbot
authored andcommitted
all: make sure *Pointer[T]'s methods are inlined as intended
Updates #50860 Change-Id: I65bced707e50364b16edf4b087c541cf19bb1778 Reviewed-on: https://go-review.googlesource.com/c/go/+/428362 Run-TryBot: Cuong Manh Le <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]>
1 parent 00234b0 commit ef69718

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/cmd/compile/internal/test/inl_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package test
66

77
import (
88
"bufio"
9+
"internal/buildcfg"
910
"internal/testenv"
1011
"io"
1112
"math/bits"
@@ -205,11 +206,7 @@ func TestIntendedInlining(t *testing.T) {
205206
"(*Uintptr).Load",
206207
"(*Uintptr).Store",
207208
"(*Uintptr).Swap",
208-
// TODO(rsc): Why are these not reported as inlined?
209-
// "(*Pointer[T]).CompareAndSwap",
210-
// "(*Pointer[T]).Load",
211-
// "(*Pointer[T]).Store",
212-
// "(*Pointer[T]).Swap",
209+
// (*Pointer[T])'s methods' handled below.
213210
},
214211
}
215212

@@ -235,6 +232,14 @@ func TestIntendedInlining(t *testing.T) {
235232
// (*Bool).CompareAndSwap is just over budget on 32-bit systems (386, arm).
236233
want["sync/atomic"] = append(want["sync/atomic"], "(*Bool).CompareAndSwap")
237234
}
235+
if buildcfg.Experiment.Unified {
236+
// Non-unified IR does not report "inlining call ..." for atomic.Pointer[T]'s methods.
237+
// TODO(cuonglm): remove once non-unified IR frontend gone.
238+
want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).CompareAndSwap")
239+
want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).Load")
240+
want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).Store")
241+
want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).Swap")
242+
}
238243

239244
switch runtime.GOARCH {
240245
case "386", "wasm", "arm":

src/sync/atomic/type.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func b32(b bool) uint32 {
3535
return 0
3636
}
3737

38+
// For testing *Pointer[T]'s methods can be inlined.
39+
// Keep in sync with cmd/compile/internal/test/inl_test.go:TestIntendedInlining.
40+
var _ = &Pointer[int]{}
41+
3842
// A Pointer is an atomic pointer of type *T. The zero value is a nil *T.
3943
type Pointer[T any] struct {
4044
_ noCopy

0 commit comments

Comments
 (0)