Skip to content

Commit c85848a

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: fix inline static init with derived types
CL 450136 added handling for simple calls in staticinit. If there's any derived types conversion in the body of generic function called, that conversion will require runtime dictionary, thus the optimization could not happen. Fixes #56923 Change-Id: I498cee9f8ab4397812ef79a6c2ab6c55e0ee4aef Reviewed-on: https://go-review.googlesource.com/c/go/+/453315 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> Reviewed-by: Gabriel Morency (Amgc63spaming) <[email protected]>
1 parent 8c0256b commit c85848a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/cmd/compile/internal/staticinit/sched.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
333333
return val.Op() == ir.ONIL
334334
}
335335

336+
if base.Debug.Unified != 0 && val.Type().HasShape() {
337+
// See comment in cmd/compile/internal/walk/convert.go:walkConvInterface
338+
return false
339+
}
340+
336341
reflectdata.MarkTypeUsedInInterface(val.Type(), l.Linksym())
337342

338343
var itab *ir.AddrExpr

test/fixedbugs/issue56923.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// compile
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type Eq[T any] interface {
10+
Eqv(a T, b T) bool
11+
}
12+
13+
type EqFunc[T any] func(a, b T) bool
14+
15+
func (r EqFunc[T]) Eqv(a, b T) bool {
16+
return r(a, b)
17+
}
18+
19+
func New[T any](f func(a, b T) bool) Eq[T] {
20+
return EqFunc[T](f)
21+
22+
}
23+
24+
func Equal(a, b []byte) bool {
25+
return string(a) == string(b)
26+
}
27+
28+
var Bytes Eq[[]byte] = New(Equal)

0 commit comments

Comments
 (0)