File: analysis.test

package info (click to toggle)
mypy 0.812-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 18,596 kB
  • sloc: python: 74,869; cpp: 11,212; ansic: 3,935; makefile: 238; sh: 13
file content (607 lines) | stat: -rw-r--r-- 13,941 bytes parent folder | download
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
-- Test cases for data flow analysis.

[case testSimple_MaybeDefined]
def f(a: int) -> None:
    x = 1
    if x == a:
        y = 1
    else:
        z = 1
[out]
def f(a):
    a, x :: int
    r0 :: native_int
    r1, r2, r3 :: bit
    y, z :: int
L0:
    x = 2
    r0 = x & 1
    r1 = r0 != 0
    if r1 goto L1 else goto L2 :: bool
L1:
    r2 = CPyTagged_IsEq_(x, a)
    if r2 goto L3 else goto L4 :: bool
L2:
    r3 = x == a
    if r3 goto L3 else goto L4 :: bool
L3:
    y = 2
    goto L5
L4:
    z = 2
L5:
    return 1
(0, 0)   {a}                     {a, x}
(0, 1)   {a, x}                  {a, x}
(0, 2)   {a, x}                  {a, x}
(0, 3)   {a, x}                  {a, x}
(1, 0)   {a, x}                  {a, x}
(1, 1)   {a, x}                  {a, x}
(2, 0)   {a, x}                  {a, x}
(2, 1)   {a, x}                  {a, x}
(3, 0)   {a, x}                  {a, x, y}
(3, 1)   {a, x, y}               {a, x, y}
(4, 0)   {a, x}                  {a, x, z}
(4, 1)   {a, x, z}               {a, x, z}
(5, 0)   {a, x, y, z}            {a, x, y, z}

[case testSimple_Liveness]
def f(a: int) -> int:
    x = 1
    if x == 1:
        return a
    else:
        return x
[out]
def f(a):
    a, x :: int
    r0 :: bit
L0:
    x = 2
    r0 = x == 2
    if r0 goto L1 else goto L2 :: bool
L1:
    return a
L2:
    return x
L3:
    unreachable
(0, 0)   {a}                     {a, x}
(0, 1)   {a, x}                  {a, r0, x}
(0, 2)   {a, r0, x}              {a, x}
(1, 0)   {a}                     {}
(2, 0)   {x}                     {}
(3, 0)   {}                      {}

[case testSpecial_Liveness]
def f() -> int:
    x = 1
    y = 1
    x = 2
    return x
[out]
def f():
    x, y :: int
L0:
    x = 2
    y = 2
    x = 4
    return x
(0, 0)   {}                      {}
(0, 1)   {}                      {}
(0, 2)   {}                      {x}
(0, 3)   {x}                     {}

[case testSpecial2_Liveness]
def f(a: int) -> int:
    a = 1
    a = 2
    a = 3
    return a
[out]
def f(a):
    a :: int
L0:
    a = 2
    a = 4
    a = 6
    return a
(0, 0)   {}                      {}
(0, 1)   {}                      {}
(0, 2)   {}                      {a}
(0, 3)   {a}                     {}

[case testSimple_MustDefined]
def f(a: int) -> None:
    if a == 1:
        y = 1
        x = 2
    else:
        x = 2
[out]
def f(a):
    a :: int
    r0 :: bit
    y, x :: int
L0:
    r0 = a == 2
    if r0 goto L1 else goto L2 :: bool
L1:
    y = 2
    x = 4
    goto L3
L2:
    x = 4
L3:
    return 1
(0, 0)   {a}                     {a}
(0, 1)   {a}                     {a}
(1, 0)   {a}                     {a, y}
(1, 1)   {a, y}                  {a, x, y}
(1, 2)   {a, x, y}               {a, x, y}
(2, 0)   {a}                     {a, x}
(2, 1)   {a, x}                  {a, x}
(3, 0)   {a, x}                  {a, x}

[case testTwoArgs_MustDefined]
def f(x: int, y: int) -> int:
    return x
[out]
def f(x, y):
    x, y :: int
L0:
    return x
(0, 0)   {x, y}                  {x, y}

[case testLoop_MustDefined]
def f(n: int) -> None:
    while n < 5:
        n = n + 1
        m = n
[out]
def f(n):
    n :: int
    r0 :: native_int
    r1, r2, r3 :: bit
    r4, m :: int
L0:
L1:
    r0 = n & 1
    r1 = r0 != 0
    if r1 goto L2 else goto L3 :: bool
L2:
    r2 = CPyTagged_IsLt_(n, 10)
    if r2 goto L4 else goto L5 :: bool
L3:
    r3 = n < 10 :: signed
    if r3 goto L4 else goto L5 :: bool
L4:
    r4 = CPyTagged_Add(n, 2)
    n = r4
    m = n
    goto L1
L5:
    return 1
(0, 0)   {n}                     {n}
(1, 0)   {n}                     {n}
(1, 1)   {n}                     {n}
(1, 2)   {n}                     {n}
(2, 0)   {n}                     {n}
(2, 1)   {n}                     {n}
(3, 0)   {n}                     {n}
(3, 1)   {n}                     {n}
(4, 0)   {n}                     {n}
(4, 1)   {n}                     {n}
(4, 2)   {n}                     {m, n}
(4, 3)   {m, n}                  {m, n}
(5, 0)   {n}                     {n}

[case testMultiPass_Liveness]
def f(n: int) -> None:
    x = 1
    y = 1
    while n < 1:
        n = y
        while n < 2:
            n = 1
            n = x
[out]
def f(n):
    n, x, y :: int
    r0 :: native_int
    r1, r2, r3 :: bit
    r4 :: native_int
    r5, r6, r7 :: bit
L0:
    x = 2
    y = 2
L1:
    r0 = n & 1
    r1 = r0 != 0
    if r1 goto L2 else goto L3 :: bool
L2:
    r2 = CPyTagged_IsLt_(n, 2)
    if r2 goto L4 else goto L10 :: bool
L3:
    r3 = n < 2 :: signed
    if r3 goto L4 else goto L10 :: bool
L4:
    n = y
L5:
    r4 = n & 1
    r5 = r4 != 0
    if r5 goto L6 else goto L7 :: bool
L6:
    r6 = CPyTagged_IsLt_(n, 4)
    if r6 goto L8 else goto L9 :: bool
L7:
    r7 = n < 4 :: signed
    if r7 goto L8 else goto L9 :: bool
L8:
    n = 2
    n = x
    goto L5
L9:
    goto L1
L10:
    return 1
(0, 0)   {n}                     {n, x}
(0, 1)   {n, x}                  {n, x, y}
(0, 2)   {n, x, y}               {n, x, y}
(1, 0)   {n, x, y}               {n, r0, x, y}
(1, 1)   {n, r0, x, y}           {n, r1, x, y}
(1, 2)   {n, r1, x, y}           {n, x, y}
(2, 0)   {n, x, y}               {r2, x, y}
(2, 1)   {r2, x, y}              {x, y}
(3, 0)   {n, x, y}               {r3, x, y}
(3, 1)   {r3, x, y}              {x, y}
(4, 0)   {x, y}                  {n, x, y}
(4, 1)   {n, x, y}               {n, x, y}
(5, 0)   {n, x, y}               {n, r4, x, y}
(5, 1)   {n, r4, x, y}           {n, r5, x, y}
(5, 2)   {n, r5, x, y}           {n, x, y}
(6, 0)   {n, x, y}               {n, r6, x, y}
(6, 1)   {n, r6, x, y}           {n, x, y}
(7, 0)   {n, x, y}               {n, r7, x, y}
(7, 1)   {n, r7, x, y}           {n, x, y}
(8, 0)   {x, y}                  {x, y}
(8, 1)   {x, y}                  {n, x, y}
(8, 2)   {n, x, y}               {n, x, y}
(9, 0)   {n, x, y}               {n, x, y}
(10, 0)  {}                      {}

[case testCall_Liveness]
def f(x: int) -> int:
    a = f(1)
    return f(a) + a
[out]
def f(x):
    x, r0, a, r1, r2, r3 :: int
L0:
    r0 = f(2)
    if is_error(r0) goto L3 (error at f:2) else goto L1
L1:
    a = r0
    r1 = f(a)
    if is_error(r1) goto L3 (error at f:3) else goto L2
L2:
    r2 = CPyTagged_Add(r1, a)
    return r2
L3:
    r3 = <error> :: int
    return r3
(0, 0)   {}                      {r0}
(0, 1)   {r0}                    {r0}
(1, 0)   {r0}                    {a}
(1, 1)   {a}                     {a, r1}
(1, 2)   {a, r1}                 {a, r1}
(2, 0)   {a, r1}                 {r2}
(2, 1)   {r2}                    {}
(3, 0)   {}                      {r3}
(3, 1)   {r3}                    {}

[case testLoop_MaybeDefined]
def f(a: int) -> None:
    while a < a:
        while a < a:
            y = a
        x = a
[out]
def f(a):
    a :: int
    r0 :: native_int
    r1 :: bit
    r2 :: native_int
    r3, r4, r5 :: bit
    r6 :: native_int
    r7 :: bit
    r8 :: native_int
    r9, r10, r11 :: bit
    y, x :: int
L0:
L1:
    r0 = a & 1
    r1 = r0 != 0
    if r1 goto L3 else goto L2 :: bool
L2:
    r2 = a & 1
    r3 = r2 != 0
    if r3 goto L3 else goto L4 :: bool
L3:
    r4 = CPyTagged_IsLt_(a, a)
    if r4 goto L5 else goto L12 :: bool
L4:
    r5 = a < a :: signed
    if r5 goto L5 else goto L12 :: bool
L5:
L6:
    r6 = a & 1
    r7 = r6 != 0
    if r7 goto L8 else goto L7 :: bool
L7:
    r8 = a & 1
    r9 = r8 != 0
    if r9 goto L8 else goto L9 :: bool
L8:
    r10 = CPyTagged_IsLt_(a, a)
    if r10 goto L10 else goto L11 :: bool
L9:
    r11 = a < a :: signed
    if r11 goto L10 else goto L11 :: bool
L10:
    y = a
    goto L6
L11:
    x = a
    goto L1
L12:
    return 1
(0, 0)   {a}                     {a}
(1, 0)   {a, x, y}               {a, x, y}
(1, 1)   {a, x, y}               {a, x, y}
(1, 2)   {a, x, y}               {a, x, y}
(2, 0)   {a, x, y}               {a, x, y}
(2, 1)   {a, x, y}               {a, x, y}
(2, 2)   {a, x, y}               {a, x, y}
(3, 0)   {a, x, y}               {a, x, y}
(3, 1)   {a, x, y}               {a, x, y}
(4, 0)   {a, x, y}               {a, x, y}
(4, 1)   {a, x, y}               {a, x, y}
(5, 0)   {a, x, y}               {a, x, y}
(6, 0)   {a, x, y}               {a, x, y}
(6, 1)   {a, x, y}               {a, x, y}
(6, 2)   {a, x, y}               {a, x, y}
(7, 0)   {a, x, y}               {a, x, y}
(7, 1)   {a, x, y}               {a, x, y}
(7, 2)   {a, x, y}               {a, x, y}
(8, 0)   {a, x, y}               {a, x, y}
(8, 1)   {a, x, y}               {a, x, y}
(9, 0)   {a, x, y}               {a, x, y}
(9, 1)   {a, x, y}               {a, x, y}
(10, 0)  {a, x, y}               {a, x, y}
(10, 1)  {a, x, y}               {a, x, y}
(11, 0)  {a, x, y}               {a, x, y}
(11, 1)  {a, x, y}               {a, x, y}
(12, 0)  {a, x, y}               {a, x, y}

[case testTrivial_BorrowedArgument]
def f(a: int, b: int) -> int:
    return b
[out]
def f(a, b):
    a, b :: int
L0:
    return b
(0, 0)   {a, b}                  {a, b}

[case testSimple_BorrowedArgument]
def f(a: int) -> int:
    b = a
    a = 1
    return a
[out]
def f(a):
    a, b :: int
L0:
    b = a
    a = 2
    return a
(0, 0)   {a}                     {a}
(0, 1)   {a}                     {}
(0, 2)   {}                      {}

[case testConditional_BorrowedArgument]
def f(a: int) -> int:
    if a == a:
        x = 2
        a = 1
    else:
        x = 1
    return x
[out]
def f(a):
    a :: int
    r0 :: native_int
    r1, r2, r3 :: bit
    x :: int
L0:
    r0 = a & 1
    r1 = r0 != 0
    if r1 goto L1 else goto L2 :: bool
L1:
    r2 = CPyTagged_IsEq_(a, a)
    if r2 goto L3 else goto L4 :: bool
L2:
    r3 = a == a
    if r3 goto L3 else goto L4 :: bool
L3:
    x = 4
    a = 2
    goto L5
L4:
    x = 2
L5:
    return x
(0, 0)   {a}                     {a}
(0, 1)   {a}                     {a}
(0, 2)   {a}                     {a}
(1, 0)   {a}                     {a}
(1, 1)   {a}                     {a}
(2, 0)   {a}                     {a}
(2, 1)   {a}                     {a}
(3, 0)   {a}                     {a}
(3, 1)   {a}                     {}
(3, 2)   {}                      {}
(4, 0)   {a}                     {a}
(4, 1)   {a}                     {a}
(5, 0)   {}                      {}

[case testLoop_BorrowedArgument]
def f(a: int) -> int:
    sum = 0
    i = 0
    while i <= a:
        sum = sum + i
        i = i + 1
    return sum
[out]
def f(a):
    a, sum, i :: int
    r0 :: native_int
    r1 :: bit
    r2 :: native_int
    r3, r4, r5 :: bit
    r6, r7 :: int
L0:
    sum = 0
    i = 0
L1:
    r0 = i & 1
    r1 = r0 != 0
    if r1 goto L3 else goto L2 :: bool
L2:
    r2 = a & 1
    r3 = r2 != 0
    if r3 goto L3 else goto L4 :: bool
L3:
    r4 = CPyTagged_IsLt_(a, i)
    if r4 goto L6 else goto L5 :: bool
L4:
    r5 = i <= a :: signed
    if r5 goto L5 else goto L6 :: bool
L5:
    r6 = CPyTagged_Add(sum, i)
    sum = r6
    r7 = CPyTagged_Add(i, 2)
    i = r7
    goto L1
L6:
    return sum
(0, 0)   {a}                     {a}
(0, 1)   {a}                     {a}
(0, 2)   {a}                     {a}
(1, 0)   {a}                     {a}
(1, 1)   {a}                     {a}
(1, 2)   {a}                     {a}
(2, 0)   {a}                     {a}
(2, 1)   {a}                     {a}
(2, 2)   {a}                     {a}
(3, 0)   {a}                     {a}
(3, 1)   {a}                     {a}
(4, 0)   {a}                     {a}
(4, 1)   {a}                     {a}
(5, 0)   {a}                     {a}
(5, 1)   {a}                     {a}
(5, 2)   {a}                     {a}
(5, 3)   {a}                     {a}
(5, 4)   {a}                     {a}
(6, 0)   {a}                     {a}

[case testError]
def f(x: List[int]) -> None: pass # E: Name 'List' is not defined \
                                  # N: Did you forget to import it from "typing"? (Suggestion: "from typing import List")

[case testExceptUndefined_Liveness]
def lol(x: object) -> int:
    try:
        st = id(x)
    except Exception:
        return -1
    return st + 1
[out]
def lol(x):
    x :: object
    r0, st :: int
    r1 :: tuple[object, object, object]
    r2 :: object
    r3 :: str
    r4 :: object
    r5 :: bit
    r6 :: int
    r7 :: bit
    r8, r9 :: int
L0:
L1:
    r0 = CPyTagged_Id(x)
    st = r0
    goto L10
L2:
    r1 = CPy_CatchError()
    r2 = builtins :: module
    r3 = load_global CPyStatic_unicode_1 :: static  ('Exception')
    r4 = CPyObject_GetAttr(r2, r3)
    if is_error(r4) goto L8 (error at lol:4) else goto L3
L3:
    r5 = CPy_ExceptionMatches(r4)
    if r5 goto L4 else goto L5 :: bool
L4:
    r6 = CPyTagged_Negate(2)
    CPy_RestoreExcInfo(r1)
    return r6
L5:
    CPy_Reraise()
    if not 0 goto L8 else goto L6 :: bool
L6:
    unreachable
L7:
    CPy_RestoreExcInfo(r1)
    goto L10
L8:
    CPy_RestoreExcInfo(r1)
    r7 = CPy_KeepPropagating()
    if not r7 goto L11 else goto L9 :: bool
L9:
    unreachable
L10:
    r8 = CPyTagged_Add(st, 2)
    return r8
L11:
    r9 = <error> :: int
    return r9
(0, 0)   {x}                     {x}
(1, 0)   {x}                     {r0}
(1, 1)   {r0}                    {st}
(1, 2)   {st}                    {st}
(2, 0)   {}                      {r1}
(2, 1)   {r1}                    {r1, r2}
(2, 2)   {r1, r2}                {r1, r2, r3}
(2, 3)   {r1, r2, r3}            {r1, r4}
(2, 4)   {r1, r4}                {r1, r4}
(3, 0)   {r1, r4}                {r1, r5}
(3, 1)   {r1, r5}                {r1}
(4, 0)   {r1}                    {r1, r6}
(4, 1)   {r1, r6}                {r6}
(4, 2)   {r6}                    {}
(5, 0)   {r1}                    {r1}
(5, 1)   {r1}                    {r1}
(6, 0)   {}                      {}
(7, 0)   {r1, st}                {st}
(7, 1)   {st}                    {st}
(8, 0)   {r1}                    {}
(8, 1)   {}                      {r7}
(8, 2)   {r7}                    {}
(9, 0)   {}                      {}
(10, 0)  {st}                    {r8}
(10, 1)  {r8}                    {}
(11, 0)  {}                      {r9}
(11, 1)  {r9}                    {}