]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compiler: make decompose shortcuts apply for PtrShaped, not just Ptr
authorDavid Chase <drchase@google.com>
Wed, 11 Oct 2023 21:28:02 +0000 (17:28 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 12 Oct 2023 00:48:31 +0000 (00:48 +0000)
The immediate-data interface shortcuts also apply to pointer-shaped
things like maps, channels, and functions.

Fixes #63505.

Change-Id: I43982441bf523f53e9e5d183e95aea7c6655dd6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/534657
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
Auto-Submit: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/compile/internal/ssa/_gen/dec.rules
src/cmd/compile/internal/ssa/rewritedec.go
test/fixedbugs/issue63505.go [new file with mode: 0644]

index 2adf061874ccfd45e7f4c314183647836d117faf..7944947e062b9134a320c82ac57327bb95f2ea4e 100644 (file)
 // More annoying case: (ArraySelect[0] (StructSelect[0] isAPtr))
 // There, result of the StructSelect is an Array (not a pointer) and
 // the pre-rewrite input to the ArraySelect is a struct, not a pointer.
-(StructSelect [0] x) && x.Type.IsPtr()  => x
-(ArraySelect [0] x) && x.Type.IsPtr()  => x
+(StructSelect [0] x) && x.Type.IsPtrShaped()  => x
+(ArraySelect [0] x) && x.Type.IsPtrShaped()  => x
 
 // These, too.  Bits is bits.
-(ArrayMake1 x) && x.Type.IsPtr() => x
-(StructMake1 x) && x.Type.IsPtr() => x
+(ArrayMake1 x) && x.Type.IsPtrShaped() => x
+(StructMake1 x) && x.Type.IsPtrShaped() => x
 
 (Store dst (StructMake1 <t> f0) mem) =>
   (Store {t.FieldType(0)} (OffPtr <t.FieldType(0).PtrTo()> [0] dst) f0 mem)
index 7468518246dde8d76f353b910a36d49ae8dba2ad..3c481adc15879f92dac313e50c7bbbb1976e3e1b 100644 (file)
@@ -46,11 +46,11 @@ func rewriteValuedec(v *Value) bool {
 func rewriteValuedec_OpArrayMake1(v *Value) bool {
        v_0 := v.Args[0]
        // match: (ArrayMake1 x)
-       // cond: x.Type.IsPtr()
+       // cond: x.Type.IsPtrShaped()
        // result: x
        for {
                x := v_0
-               if !(x.Type.IsPtr()) {
+               if !(x.Type.IsPtrShaped()) {
                        break
                }
                v.copyOf(x)
@@ -62,14 +62,14 @@ func rewriteValuedec_OpArraySelect(v *Value) bool {
        v_0 := v.Args[0]
        b := v.Block
        // match: (ArraySelect [0] x)
-       // cond: x.Type.IsPtr()
+       // cond: x.Type.IsPtrShaped()
        // result: x
        for {
                if auxIntToInt64(v.AuxInt) != 0 {
                        break
                }
                x := v_0
-               if !(x.Type.IsPtr()) {
+               if !(x.Type.IsPtrShaped()) {
                        break
                }
                v.copyOf(x)
@@ -927,11 +927,11 @@ func rewriteValuedec_OpStringPtr(v *Value) bool {
 func rewriteValuedec_OpStructMake1(v *Value) bool {
        v_0 := v.Args[0]
        // match: (StructMake1 x)
-       // cond: x.Type.IsPtr()
+       // cond: x.Type.IsPtrShaped()
        // result: x
        for {
                x := v_0
-               if !(x.Type.IsPtr()) {
+               if !(x.Type.IsPtrShaped()) {
                        break
                }
                v.copyOf(x)
@@ -1054,14 +1054,14 @@ func rewriteValuedec_OpStructSelect(v *Value) bool {
                return true
        }
        // match: (StructSelect [0] x)
-       // cond: x.Type.IsPtr()
+       // cond: x.Type.IsPtrShaped()
        // result: x
        for {
                if auxIntToInt64(v.AuxInt) != 0 {
                        break
                }
                x := v_0
-               if !(x.Type.IsPtr()) {
+               if !(x.Type.IsPtrShaped()) {
                        break
                }
                v.copyOf(x)
diff --git a/test/fixedbugs/issue63505.go b/test/fixedbugs/issue63505.go
new file mode 100644 (file)
index 0000000..2bec17d
--- /dev/null
@@ -0,0 +1,45 @@
+// compile
+
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+type explainer struct {
+       m map[string]string
+}
+
+func init() {
+       RegisterExplainer(newExplainer())
+}
+
+type Explainer interface {
+       Name() string
+       Map() map[string]string
+}
+
+func (e explainer) Name() string {
+       return "HelloWorldExplainer"
+}
+
+func (e explainer) Map() map[string]string {
+       return e.m
+}
+
+//go:noinline
+func newExplainer() explainer {
+       m := make(map[string]string)
+       m["Hello"] = "World!"
+       return explainer{m}
+}
+
+var explainers = make(map[string]Explainer)
+
+func RegisterExplainer(e Explainer) {
+       explainers[e.Name()] = e
+}
+
+func main() {
+
+}