]> Cypherpunks repositories - gostls13.git/commitdiff
all: make sure *Pointer[T]'s methods are inlined as intended
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 5 Sep 2022 12:07:02 +0000 (19:07 +0700)
committerGopher Robot <gobot@golang.org>
Tue, 6 Sep 2022 18:16:03 +0000 (18:16 +0000)
Updates #50860

Change-Id: I65bced707e50364b16edf4b087c541cf19bb1778
Reviewed-on: https://go-review.googlesource.com/c/go/+/428362
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>

src/cmd/compile/internal/test/inl_test.go
src/sync/atomic/type.go

index 622224d85e1a1e0e5050c4155615b99d99fd6b15..fd3b489d1329d9af95363b0521941aa3c97bcba3 100644 (file)
@@ -6,6 +6,7 @@ package test
 
 import (
        "bufio"
+       "internal/buildcfg"
        "internal/testenv"
        "io"
        "math/bits"
@@ -205,11 +206,7 @@ func TestIntendedInlining(t *testing.T) {
                        "(*Uintptr).Load",
                        "(*Uintptr).Store",
                        "(*Uintptr).Swap",
-                       // TODO(rsc): Why are these not reported as inlined?
-                       // "(*Pointer[T]).CompareAndSwap",
-                       // "(*Pointer[T]).Load",
-                       // "(*Pointer[T]).Store",
-                       // "(*Pointer[T]).Swap",
+                       // (*Pointer[T])'s methods' handled below.
                },
        }
 
@@ -235,6 +232,14 @@ func TestIntendedInlining(t *testing.T) {
                // (*Bool).CompareAndSwap is just over budget on 32-bit systems (386, arm).
                want["sync/atomic"] = append(want["sync/atomic"], "(*Bool).CompareAndSwap")
        }
+       if buildcfg.Experiment.Unified {
+               // Non-unified IR does not report "inlining call ..." for atomic.Pointer[T]'s methods.
+               // TODO(cuonglm): remove once non-unified IR frontend gone.
+               want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).CompareAndSwap")
+               want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).Load")
+               want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).Store")
+               want["sync/atomic"] = append(want["sync/atomic"], "(*Pointer[go.shape.int]).Swap")
+       }
 
        switch runtime.GOARCH {
        case "386", "wasm", "arm":
index f7b8f5a3b749599d51b93e60e0731a5628046235..87c98b1e77e90780edcd38f8edc8856c43e3feff 100644 (file)
@@ -35,6 +35,10 @@ func b32(b bool) uint32 {
        return 0
 }
 
+// For testing *Pointer[T]'s methods can be inlined.
+// Keep in sync with cmd/compile/internal/test/inl_test.go:TestIntendedInlining.
+var _ = &Pointer[int]{}
+
 // A Pointer is an atomic pointer of type *T. The zero value is a nil *T.
 type Pointer[T any] struct {
        _ noCopy