dump_sem_ir_ranges.carbon 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // The default behavior should be `--dump-sem-ir-ranges=if-present`.
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/basics/no_prelude/dump_sem_ir_ranges.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/basics/no_prelude/dump_sem_ir_ranges.carbon
  12. // --- function.carbon
  13. library "[[@TEST_NAME]]";
  14. fn A() {
  15. var a: ();
  16. }
  17. fn B() -> () {
  18. var b: ();
  19. //@dump-sem-ir-begin
  20. b = A();
  21. //@dump-sem-ir-end
  22. return b;
  23. }
  24. //@dump-sem-ir-begin
  25. fn C() -> () {
  26. var c: ();
  27. c = B();
  28. return c;
  29. }
  30. //@dump-sem-ir-end
  31. // --- class.carbon
  32. library "[[@TEST_NAME]]";
  33. class A {
  34. fn F();
  35. //@dump-sem-ir-begin
  36. fn G();
  37. //@dump-sem-ir-end
  38. }
  39. class B {
  40. fn H();
  41. }
  42. //@dump-sem-ir-begin
  43. class C {
  44. fn I();
  45. //@dump-sem-ir-end
  46. fn J();
  47. }
  48. // --- call_params.carbon
  49. library "[[@TEST_NAME]]";
  50. fn F(a: (), b: (), c: ());
  51. fn A();
  52. fn B();
  53. fn C();
  54. fn G() {
  55. F(
  56. //@dump-sem-ir-begin
  57. A(),
  58. //@dump-sem-ir-end
  59. B(),
  60. //@dump-sem-ir-begin
  61. C()
  62. //@dump-sem-ir-end
  63. );
  64. }
  65. // --- file_without_ranges.carbon
  66. library "[[@TEST_NAME]]";
  67. fn F();
  68. // CHECK:STDOUT: --- function.carbon
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: constants {
  71. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  72. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  73. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  74. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_tuple.type [concrete]
  75. // CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
  76. // CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
  77. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  78. // CHECK:STDOUT: %C.type: type = fn_type @C [concrete]
  79. // CHECK:STDOUT: %C: %C.type = struct_value () [concrete]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: file {
  83. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [concrete = constants.%C] {
  84. // CHECK:STDOUT: %return.patt: %pattern_type = return_slot_pattern [concrete]
  85. // CHECK:STDOUT: %return.param_patt: %pattern_type = out_param_pattern %return.patt, call_param0 [concrete]
  86. // CHECK:STDOUT: } {
  87. // CHECK:STDOUT: %.loc17_12.1: %empty_tuple.type = tuple_literal ()
  88. // CHECK:STDOUT: %.loc17_12.2: type = converted %.loc17_12.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  89. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param call_param0
  90. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @B() -> %empty_tuple.type {
  95. // CHECK:STDOUT: !entry:
  96. // CHECK:STDOUT: <elided>
  97. // CHECK:STDOUT: %b.ref.loc11: ref %empty_tuple.type = name_ref b, %b
  98. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  99. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %A.ref()
  100. // CHECK:STDOUT: assign %b.ref.loc11, %A.call
  101. // CHECK:STDOUT: <elided>
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @C() -> %empty_tuple.type {
  105. // CHECK:STDOUT: !entry:
  106. // CHECK:STDOUT: name_binding_decl {
  107. // CHECK:STDOUT: %c.patt: %pattern_type = binding_pattern c [concrete]
  108. // CHECK:STDOUT: %c.var_patt: %pattern_type = var_pattern %c.patt [concrete]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %c.var: ref %empty_tuple.type = var %c.var_patt
  111. // CHECK:STDOUT: %.loc18_11.1: type = splice_block %.loc18_11.3 [concrete = constants.%empty_tuple.type] {
  112. // CHECK:STDOUT: %.loc18_11.2: %empty_tuple.type = tuple_literal ()
  113. // CHECK:STDOUT: %.loc18_11.3: type = converted %.loc18_11.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %c: ref %empty_tuple.type = bind_name c, %c.var
  116. // CHECK:STDOUT: %c.ref.loc19: ref %empty_tuple.type = name_ref c, %c
  117. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [concrete = constants.%B]
  118. // CHECK:STDOUT: %B.call: init %empty_tuple.type = call %B.ref()
  119. // CHECK:STDOUT: assign %c.ref.loc19, %B.call
  120. // CHECK:STDOUT: %c.ref.loc20: ref %empty_tuple.type = name_ref c, %c
  121. // CHECK:STDOUT: %tuple: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  122. // CHECK:STDOUT: %.loc20: %empty_tuple.type = converted %c.ref.loc20, %tuple [concrete = constants.%empty_tuple]
  123. // CHECK:STDOUT: return %.loc20
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: --- class.carbon
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: constants {
  129. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  130. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  131. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  132. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  133. // CHECK:STDOUT: %I.type: type = fn_type @I [concrete]
  134. // CHECK:STDOUT: %I: %I.type = struct_value () [concrete]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: file {
  138. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: class @A {
  142. // CHECK:STDOUT: <elided>
  143. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  144. // CHECK:STDOUT: <elided>
  145. // CHECK:STDOUT: complete_type_witness = %complete_type
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: !members:
  148. // CHECK:STDOUT: .Self = constants.%A
  149. // CHECK:STDOUT: .F = %F.decl
  150. // CHECK:STDOUT: .G = %G.decl
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: class @C {
  154. // CHECK:STDOUT: %I.decl: %I.type = fn_decl @I [concrete = constants.%I] {} {}
  155. // CHECK:STDOUT: <elided>
  156. // CHECK:STDOUT: complete_type_witness = %complete_type
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: !members:
  159. // CHECK:STDOUT: .Self = constants.%C
  160. // CHECK:STDOUT: .I = %I.decl
  161. // CHECK:STDOUT: .J = %J.decl
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: fn @G();
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: fn @I();
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: --- call_params.carbon
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: constants {
  171. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  172. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  173. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  174. // CHECK:STDOUT: %C.type: type = fn_type @C [concrete]
  175. // CHECK:STDOUT: %C: %C.type = struct_value () [concrete]
  176. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: fn @G() {
  180. // CHECK:STDOUT: !entry:
  181. // CHECK:STDOUT: <elided>
  182. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  183. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %A.ref()
  184. // CHECK:STDOUT: <elided>
  185. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [concrete = constants.%C]
  186. // CHECK:STDOUT: %C.call: init %empty_tuple.type = call %C.ref()
  187. // CHECK:STDOUT: %.loc13_7.1: ref %empty_tuple.type = temporary_storage
  188. // CHECK:STDOUT: %.loc13_7.2: ref %empty_tuple.type = temporary %.loc13_7.1, %A.call
  189. // CHECK:STDOUT: %tuple.loc13: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  190. // CHECK:STDOUT: %.loc13_7.3: %empty_tuple.type = converted %A.call, %tuple.loc13 [concrete = constants.%empty_tuple]
  191. // CHECK:STDOUT: <elided>
  192. // CHECK:STDOUT: %.loc17_7.1: ref %empty_tuple.type = temporary_storage
  193. // CHECK:STDOUT: %.loc17_7.2: ref %empty_tuple.type = temporary %.loc17_7.1, %C.call
  194. // CHECK:STDOUT: %tuple.loc17: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  195. // CHECK:STDOUT: %.loc17_7.3: %empty_tuple.type = converted %C.call, %tuple.loc17 [concrete = constants.%empty_tuple]
  196. // CHECK:STDOUT: <elided>
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: --- file_without_ranges.carbon
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: constants {
  202. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  203. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: file {
  207. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  208. // CHECK:STDOUT: .F = %F.decl
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: fn @F();
  214. // CHECK:STDOUT: