mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: do not shapify when reading reshaping expr
Fixes #71184 Change-Id: I22e7ae5203311e86a90502bfe155b0597007887d Reviewed-on: https://go-review.googlesource.com/c/go/+/641955 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
b1f259b1b4
commit
bfbf736564
2 changed files with 31 additions and 1 deletions
|
|
@ -49,6 +49,9 @@ type pkgReader struct {
|
||||||
// but bitwise inverted so we can detect if we're missing the entry
|
// but bitwise inverted so we can detect if we're missing the entry
|
||||||
// or not.
|
// or not.
|
||||||
newindex []index
|
newindex []index
|
||||||
|
|
||||||
|
// indicates whether the data is reading during reshaping.
|
||||||
|
reshaping bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPkgReader(pr pkgbits.PkgDecoder) *pkgReader {
|
func newPkgReader(pr pkgbits.PkgDecoder) *pkgReader {
|
||||||
|
|
@ -116,6 +119,10 @@ type reader struct {
|
||||||
// find parameters/results.
|
// find parameters/results.
|
||||||
funarghack bool
|
funarghack bool
|
||||||
|
|
||||||
|
// reshaping is used during reading exprReshape code, preventing
|
||||||
|
// the reader from shapifying the re-shaped type.
|
||||||
|
reshaping bool
|
||||||
|
|
||||||
// methodSym is the name of method's name, if reading a method.
|
// methodSym is the name of method's name, if reading a method.
|
||||||
// It's nil if reading a normal function or closure body.
|
// It's nil if reading a normal function or closure body.
|
||||||
methodSym *types.Sym
|
methodSym *types.Sym
|
||||||
|
|
@ -1007,7 +1014,7 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx index, implicits, explicits
|
||||||
// arguments.
|
// arguments.
|
||||||
for i, targ := range dict.targs {
|
for i, targ := range dict.targs {
|
||||||
basic := r.Bool()
|
basic := r.Bool()
|
||||||
if dict.shaped {
|
if dict.shaped && !pr.reshaping {
|
||||||
dict.targs[i] = shapify(targ, basic)
|
dict.targs[i] = shapify(targ, basic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2445,7 +2452,10 @@ func (r *reader) expr() (res ir.Node) {
|
||||||
|
|
||||||
case exprReshape:
|
case exprReshape:
|
||||||
typ := r.typ()
|
typ := r.typ()
|
||||||
|
old := r.reshaping
|
||||||
|
r.reshaping = true
|
||||||
x := r.expr()
|
x := r.expr()
|
||||||
|
r.reshaping = old
|
||||||
|
|
||||||
if types.IdenticalStrict(x.Type(), typ) {
|
if types.IdenticalStrict(x.Type(), typ) {
|
||||||
return x
|
return x
|
||||||
|
|
@ -2568,7 +2578,10 @@ func (r *reader) funcInst(pos src.XPos) (wrapperFn, baseFn, dictPtr ir.Node) {
|
||||||
info := r.dict.subdicts[idx]
|
info := r.dict.subdicts[idx]
|
||||||
explicits := r.p.typListIdx(info.explicits, r.dict)
|
explicits := r.p.typListIdx(info.explicits, r.dict)
|
||||||
|
|
||||||
|
old := r.p.reshaping
|
||||||
|
r.p.reshaping = r.reshaping
|
||||||
baseFn = r.p.objIdx(info.idx, implicits, explicits, true).(*ir.Name)
|
baseFn = r.p.objIdx(info.idx, implicits, explicits, true).(*ir.Name)
|
||||||
|
r.p.reshaping = old
|
||||||
|
|
||||||
// TODO(mdempsky): Is there a more robust way to get the
|
// TODO(mdempsky): Is there a more robust way to get the
|
||||||
// dictionary pointer type here?
|
// dictionary pointer type here?
|
||||||
|
|
|
||||||
17
test/fixedbugs/issue71184.go
Normal file
17
test/fixedbugs/issue71184.go
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
// compile
|
||||||
|
|
||||||
|
// Copyright 2024 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 x
|
||||||
|
|
||||||
|
func F[T int32]() {
|
||||||
|
_ = G[*[0]T]()[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func G[T any]() (v T) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = F[int32]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue