1 | // Copyright 2021 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. |
4 | |
5 | // go:build ignore |
6 | |
7 | package testdata |
8 | |
9 | type I interface { |
10 | foo(I) |
11 | } |
12 | |
13 | type A struct{} |
14 | |
15 | func (a A) foo(ai I) {} |
16 | |
17 | type B struct{} |
18 | |
19 | func (b B) foo(bi I) {} |
20 | |
21 | func doWork() I { return nil } |
22 | func close() I { return nil } |
23 | |
24 | func Baz(x B, h func() I, i I) I { |
25 | i.foo(x) |
26 | |
27 | return h() |
28 | } |
29 | |
30 | // Relevant SSA: |
31 | // func Baz(x B, h func() I, i I) I: |
32 | // t0 = local B (x) |
33 | // *t0 = x |
34 | // t1 = *t0 |
35 | // t2 = make I <- B (t1) |
36 | // t3 = invoke i.foo(t2) |
37 | // t4 = h() |
38 | // return t4 |
39 | |
40 | // Local(t2) has seemingly duplicates of successors. This |
41 | // happens in stringification of type propagation graph. |
42 | // Due to CHA, we analyze A.foo and *A.foo as well as B.foo |
43 | // and *B.foo, which have similar bodies and hence similar |
44 | // type flow that gets merged together during stringification. |
45 | |
46 | // WANT: |
47 | // Local(t2) -> Local(ai), Local(ai), Local(bi), Local(bi) |
48 | // Constant(testdata.I) -> Local(t4) |
49 | // Local(t1) -> Local(t2) |
50 |