Debian Codegraph @

go/callgraph/vta/testdata/src/node_uniqueness.go

raw symbols SCIP
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 // TestNodeTypeUniqueness checks if semantically equivalent types
10 // are being represented using the same pointer value in vta nodes.
11 // If not, some edges become missing in the string representation
12 // of the graph.
13
14 type I interface {
15 Foo()
16 }
17
18 type A struct{}
19
20 func (a A) Foo() {}
21
22 func Baz(a *A) (I, I, interface{}, interface{}) {
23 var i I
24 i = a
25
26 var ii I
27 aa := &A{}
28 ii = aa
29
30 m := make(map[int]int)
31 var iii interface{}
32 iii = m
33
34 var iiii interface{}
35 iiii = m
36
37 return i, ii, iii, iiii
38 }
39
40 // Relevant SSA:
41 // func Baz(a *A) (I, I, interface{}, interface{}):
42 // t0 = make I <- *A (a)
43 // t1 = new A (complit)
44 // t2 = make I <- *A (t1)
45 // t3 = make map[int]int
46 // t4 = make interface{} <- map[int]int (t3)
47 // t5 = make interface{} <- map[int]int (t3)
48 // return t0, t2, t4, t5
49
50 // Without canon approach, one of Pointer(*A) -> Local(t0) and Pointer(*A) -> Local(t2) edges is
51 // missing in the graph string representation. The original graph has both of the edges but the
52 // source node Pointer(*A) is not the same; two occurrences of Pointer(*A) are considered separate
53 // nodes. Since they have the same string representation, one edge gets overridden by the other
54 // during the graph stringification, instead of being joined together as in below.
55
56 // WANT:
57 // Pointer(*testdata.A) -> Local(t0), Local(t2)
58 // Local(t3) -> Local(t4), Local(t5)