mirror of
https://github.com/golang/go
synced 2024-11-22 22:10:03 -07:00
cmd/compiler: make decompose shortcuts apply for PtrShaped, not just Ptr
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>
This commit is contained in:
parent
872d7181f4
commit
eb832afb23
@ -118,12 +118,12 @@
|
|||||||
// More annoying case: (ArraySelect[0] (StructSelect[0] isAPtr))
|
// More annoying case: (ArraySelect[0] (StructSelect[0] isAPtr))
|
||||||
// There, result of the StructSelect is an Array (not a pointer) and
|
// 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.
|
// the pre-rewrite input to the ArraySelect is a struct, not a pointer.
|
||||||
(StructSelect [0] x) && x.Type.IsPtr() => x
|
(StructSelect [0] x) && x.Type.IsPtrShaped() => x
|
||||||
(ArraySelect [0] x) && x.Type.IsPtr() => x
|
(ArraySelect [0] x) && x.Type.IsPtrShaped() => x
|
||||||
|
|
||||||
// These, too. Bits is bits.
|
// These, too. Bits is bits.
|
||||||
(ArrayMake1 x) && x.Type.IsPtr() => x
|
(ArrayMake1 x) && x.Type.IsPtrShaped() => x
|
||||||
(StructMake1 x) && x.Type.IsPtr() => x
|
(StructMake1 x) && x.Type.IsPtrShaped() => x
|
||||||
|
|
||||||
(Store dst (StructMake1 <t> f0) mem) =>
|
(Store dst (StructMake1 <t> f0) mem) =>
|
||||||
(Store {t.FieldType(0)} (OffPtr <t.FieldType(0).PtrTo()> [0] dst) f0 mem)
|
(Store {t.FieldType(0)} (OffPtr <t.FieldType(0).PtrTo()> [0] dst) f0 mem)
|
||||||
|
@ -46,11 +46,11 @@ func rewriteValuedec(v *Value) bool {
|
|||||||
func rewriteValuedec_OpArrayMake1(v *Value) bool {
|
func rewriteValuedec_OpArrayMake1(v *Value) bool {
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
// match: (ArrayMake1 x)
|
// match: (ArrayMake1 x)
|
||||||
// cond: x.Type.IsPtr()
|
// cond: x.Type.IsPtrShaped()
|
||||||
// result: x
|
// result: x
|
||||||
for {
|
for {
|
||||||
x := v_0
|
x := v_0
|
||||||
if !(x.Type.IsPtr()) {
|
if !(x.Type.IsPtrShaped()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
v.copyOf(x)
|
v.copyOf(x)
|
||||||
@ -62,14 +62,14 @@ func rewriteValuedec_OpArraySelect(v *Value) bool {
|
|||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
b := v.Block
|
b := v.Block
|
||||||
// match: (ArraySelect [0] x)
|
// match: (ArraySelect [0] x)
|
||||||
// cond: x.Type.IsPtr()
|
// cond: x.Type.IsPtrShaped()
|
||||||
// result: x
|
// result: x
|
||||||
for {
|
for {
|
||||||
if auxIntToInt64(v.AuxInt) != 0 {
|
if auxIntToInt64(v.AuxInt) != 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
x := v_0
|
x := v_0
|
||||||
if !(x.Type.IsPtr()) {
|
if !(x.Type.IsPtrShaped()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
v.copyOf(x)
|
v.copyOf(x)
|
||||||
@ -927,11 +927,11 @@ func rewriteValuedec_OpStringPtr(v *Value) bool {
|
|||||||
func rewriteValuedec_OpStructMake1(v *Value) bool {
|
func rewriteValuedec_OpStructMake1(v *Value) bool {
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
// match: (StructMake1 x)
|
// match: (StructMake1 x)
|
||||||
// cond: x.Type.IsPtr()
|
// cond: x.Type.IsPtrShaped()
|
||||||
// result: x
|
// result: x
|
||||||
for {
|
for {
|
||||||
x := v_0
|
x := v_0
|
||||||
if !(x.Type.IsPtr()) {
|
if !(x.Type.IsPtrShaped()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
v.copyOf(x)
|
v.copyOf(x)
|
||||||
@ -1054,14 +1054,14 @@ func rewriteValuedec_OpStructSelect(v *Value) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match: (StructSelect [0] x)
|
// match: (StructSelect [0] x)
|
||||||
// cond: x.Type.IsPtr()
|
// cond: x.Type.IsPtrShaped()
|
||||||
// result: x
|
// result: x
|
||||||
for {
|
for {
|
||||||
if auxIntToInt64(v.AuxInt) != 0 {
|
if auxIntToInt64(v.AuxInt) != 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
x := v_0
|
x := v_0
|
||||||
if !(x.Type.IsPtr()) {
|
if !(x.Type.IsPtrShaped()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
v.copyOf(x)
|
v.copyOf(x)
|
||||||
|
45
test/fixedbugs/issue63505.go
Normal file
45
test/fixedbugs/issue63505.go
Normal file
@ -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() {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user