Debian Codegraph @

mypyc/test-data/exceptions-freq.test

raw
1 -- Test cases for basic block execution frequency analysis.
2 --
3 -- These test cases are using exception transform test machinery for convenience.
4 --
5 -- NOTE: These must all have the _freq suffix
6
7 [case testSimpleError_freq]
8 from typing import List
9 def f(x: List[int]) -> int:
10 return x[0]
11 [out]
12 def f(x):
13 x :: list
14 r0 :: object
15 r1, r2 :: int
16 L0:
17 r0 = CPyList_GetItemShort(x, 0)
18 if is_error(r0) goto L3 (error at f:3) else goto L1
19 L1:
20 r1 = unbox(int, r0)
21 dec_ref r0
22 if is_error(r1) goto L3 (error at f:3) else goto L2
23 L2:
24 return r1
25 L3:
26 r2 = <error> :: int
27 return r2
28 hot blocks: [0, 1, 2]
29
30 [case testHotBranch_freq]
31 from typing import List
32 def f(x: bool) -> None:
33 if x:
34 y = 1
35 else:
36 y = 2
37 [out]
38 def f(x):
39 x :: bool
40 y :: int
41 L0:
42 if x goto L1 else goto L2 :: bool
43 L1:
44 y = 2
45 dec_ref y :: int
46 goto L3
47 L2:
48 y = 4
49 dec_ref y :: int
50 L3:
51 return 1
52 hot blocks: [0, 1, 2, 3]
53
54 [case testGoto_freq]
55 from typing import List
56 def f(x: bool) -> int:
57 if x:
58 y = 1
59 else:
60 return 2
61 return y
62 [out]
63 def f(x):
64 x :: bool
65 y :: int
66 L0:
67 if x goto L1 else goto L2 :: bool
68 L1:
69 y = 2
70 goto L3
71 L2:
72 return 4
73 L3:
74 return y
75 hot blocks: [0, 1, 2, 3]
76
77 [case testFalseOnError_freq]
78 from typing import List
79 def f(x: List[int]) -> None:
80 x[0] = 1
81 [out]
82 def f(x):
83 x :: list
84 r0 :: object
85 r1 :: bit
86 r2 :: None
87 L0:
88 r0 = object 1
89 inc_ref r0
90 r1 = CPyList_SetItem(x, 0, r0)
91 if not r1 goto L2 (error at f:3) else goto L1 :: bool
92 L1:
93 return 1
94 L2:
95 r2 = <error> :: None
96 return r2
97 hot blocks: [0, 1]
98
99 [case testRareBranch_freq]
100 from typing import Final
101
102 x: Final = str()
103
104 def f() -> str:
105 return x
106 [out]
107 def f():
108 r0 :: str
109 r1 :: bool
110 r2 :: str
111 L0:
112 r0 = __main__.x :: static
113 if is_error(r0) goto L1 else goto L3
114 L1:
115 r1 = raise NameError('value for final name "x" was not set')
116 if not r1 goto L4 (error at f:6) else goto L2 :: bool
117 L2:
118 unreachable
119 L3:
120 inc_ref r0
121 return r0
122 L4:
123 r2 = <error> :: str
124 return r2
125 hot blocks: [0, 3]