1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // WARNING: Please avoid updating this file. If this file needs to be updated,
6 // then a new devirt.pprof file should be generated:
8 // $ cd $GOROOT/src/cmd/compile/internal/test/testdata/pgo/devirtualize/
9 // $ go mod init example.com/pgo/devirtualize
10 // $ go test -bench=. -cpuprofile ./devirt.pprof
14 // Devirtualization of callees from transitive dependencies should work even if
15 // they aren't directly referenced in the package. See #61577.
17 // Dots in the last package path component are escaped in symbol names. Use one
18 // to ensure the escaping doesn't break lookup.
19 import "example.com/pgo/devirtualize/mult.pkg"
23 type Adder interface {
29 func (Add) Add(a, b int) int {
30 for i := 0; i < 1000; i++ {
38 func (Sub) Add(a, b int) int {
39 for i := 0; i < 1000; i++ {
45 // Exercise calls mostly a1 and m1.
48 func Exercise(iter int, a1, a2 Adder, m1, m2 mult.Multiplier) {
49 for i := 0; i < iter; i++ {
57 // N.B. Profiles only distinguish calls on a per-line level,
58 // making the two calls ambiguous. However because the
59 // interfaces and implementations are mutually exclusive,
60 // devirtualization can still select the correct callee for
63 // If they were not mutually exclusive (for example, two Add
64 // calls), then we could not definitively select the correct
66 sink += m.Multiply(42, a.Add(1, 2))