File: tailcall.txtar

package info (click to toggle)
golang-golang-x-tools 1%3A0.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 22,724 kB
  • sloc: javascript: 2,027; asm: 1,645; sh: 166; yacc: 155; makefile: 49; ansic: 8
file content (120 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Reduction of parameterless tail-call to functions.

1. a0 (sum) is reduced, despite the complexity of the callee.

2. a1 (conflict) is not reduced, because the caller and callee have
   intersecting sets of labels.

3. a2 (usesResult) is not reduced, because it refers to a result variable.

-- go.mod --
module testdata
go 1.12

-- a/a0.go --
package a

func _() int {
	return sum(1, 2) //@ inline(re"sum", sum)
}

func sum(lo, hi int) int {
	total := 0
start:
	for i := lo; i <= hi; i++ {
		total += i
		if i == 6 {
			goto start
		} else if i == 7 {
			return -1
		}
	}
	return total
}

-- sum --
package a

func _() int {
	total := 0
start:
	for i := 1; i <= 2; i++ {
		total += i
		if i == 6 {
			goto start
		} else if i == 7 {
			return -1
		}
	}
	return total //@ inline(re"sum", sum)
}

func sum(lo, hi int) int {
	total := 0
start:
	for i := lo; i <= hi; i++ {
		total += i
		if i == 6 {
			goto start
		} else if i == 7 {
			return -1
		}
	}
	return total
}

-- a/a1.go --
package a

func _() int {
	hello:
	return conflict(1, 2) //@ inline(re"conflict", conflict)
	goto hello
}

func conflict(lo, hi int) int {
hello:
	return lo + hi
}

-- conflict --
package a

func _() int {
hello:
	return func() int {
	hello:
		return 1 + 2
	}() //@ inline(re"conflict", conflict)
	goto hello
}

func conflict(lo, hi int) int {
hello:
	return lo + hi
}

-- a/a2.go --
package a

func _() int {
	return usesResult(1, 2) //@ inline(re"usesResult", usesResult)
}

func usesResult(lo, hi int) (z int) {
	z = y + x
	return
}

-- usesResult --
package a

func _() int {
	return func() (z int) { z = y + x; return }() //@ inline(re"usesResult", usesResult)
}

func usesResult(lo, hi int) (z int) {
	z = y + x
	return
}