Debian Codegraph @

internal/refactor/inline/testdata/substgroups.txtar

raw
1 This test checks that parameter shadowing is avoided for substitution groups,
2 as well as the examples of recursive pruning of these groups based on falcon
3 and effects analysis.
4
5 -- go.mod --
6 module testdata
7
8 go 1.20
9
10 -- falcon.go --
11 package a
12
13 var a [3]int
14
15 func falcon(x, y, z int) {
16 _ = x + a[y+z]
17 }
18
19 func _() {
20 var y int
21 const x, z = 1, 2
22 falcon(y, x, z) //@ inline(re"falcon", falcon)
23 }
24
25 -- falcon --
26 package a
27
28 var a [3]int
29
30 func falcon(x, y, z int) {
31 _ = x + a[y+z]
32 }
33
34 func _() {
35 var y int
36 const x, z = 1, 2
37 {
38 var x, y, z int = y, x, z
39 _ = x + a[y+z]
40 } //@ inline(re"falcon", falcon)
41 }
42
43 -- effects.go --
44 package a
45
46 func effects(w, x, y, z int) {
47 _ = x + w + y + z
48 }
49
50 func _() {
51 v := 0
52 w := func() int { v++; return 0 }
53 x := func() int { v++; return 0 }
54 y := func() int { v++; return 0 }
55 effects(x(), w(), y(), x()) //@ inline(re"effects", effects)
56 }
57
58 -- effects --
59 package a
60
61 func effects(w, x, y, z int) {
62 _ = x + w + y + z
63 }
64
65 func _() {
66 v := 0
67 w := func() int { v++; return 0 }
68 x := func() int { v++; return 0 }
69 y := func() int { v++; return 0 }
70 {
71 var w, x, y, z int = x(), w(), y(), x()
72 _ = x + w + y + z
73 } //@ inline(re"effects", effects)
74 }
75
76 -- negative.go --
77 package a
78
79 func _() {
80 i := -1
81 if negative1(i, i) { //@ inline(re"negative1", negative1)
82 i := 0
83 _ = i
84 }
85 }
86
87 func negative1(i, j int) bool {
88 return negative2(j, i)
89 }
90
91 func negative2(i, j int) bool {
92 return i < 0
93 }
94
95 -- negative1 --
96 package a
97
98 func _() {
99 i := -1
100 if negative2(i, i) { //@ inline(re"negative1", negative1)
101 i := 0
102 _ = i
103 }
104 }
105
106 func negative1(i, j int) bool {
107 return negative2(j, i)
108 }
109
110 func negative2(i, j int) bool {
111 return i < 0
112 }
113