exceptions-freq.test 2.1 KB

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