dump_sem_ir_ranges.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon
  6. //
  7. // The default behavior should be `--dump-sem-ir-ranges=if-present`, although
  8. // tests set it to `only`. This explicitly tests the default of the toolchain,
  9. // not of file_test.
  10. // ARGS: compile --phase=check --dump-sem-ir %s
  11. //
  12. // AUTOUPDATE
  13. // TIP: To test this file alone, run:
  14. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/basics/dump_sem_ir_ranges.carbon
  15. // TIP: To dump output, run:
  16. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/basics/dump_sem_ir_ranges.carbon
  17. // --- function.carbon
  18. library "[[@TEST_NAME]]";
  19. fn A() {
  20. var a: ();
  21. }
  22. fn B() -> () {
  23. var b: ();
  24. //@dump-sem-ir-begin
  25. b = A();
  26. //@dump-sem-ir-end
  27. return b;
  28. }
  29. //@dump-sem-ir-begin
  30. fn C() -> () {
  31. var c: ();
  32. c = B();
  33. return c;
  34. }
  35. //@dump-sem-ir-end
  36. // --- class.carbon
  37. library "[[@TEST_NAME]]";
  38. class A {
  39. fn F();
  40. //@dump-sem-ir-begin
  41. fn G();
  42. //@dump-sem-ir-end
  43. }
  44. class B {
  45. fn H();
  46. }
  47. //@dump-sem-ir-begin
  48. class C {
  49. fn I();
  50. //@dump-sem-ir-end
  51. fn J();
  52. }
  53. // --- call_params.carbon
  54. library "[[@TEST_NAME]]";
  55. fn F(a: (), b: (), c: ());
  56. fn A();
  57. fn B();
  58. fn C();
  59. fn G() {
  60. F(
  61. //@dump-sem-ir-begin
  62. A(),
  63. //@dump-sem-ir-end
  64. B(),
  65. //@dump-sem-ir-begin
  66. C()
  67. //@dump-sem-ir-end
  68. );
  69. }
  70. // --- file_without_ranges.carbon
  71. library "[[@TEST_NAME]]";
  72. fn F();
  73. // CHECK:STDOUT: --- function.carbon
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: constants {
  76. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  77. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  78. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  79. // CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
  80. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  81. // CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
  82. // CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
  83. // CHECK:STDOUT: %C.type: type = fn_type @C [concrete]
  84. // CHECK:STDOUT: %C: %C.type = struct_value () [concrete]
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: imports {
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: file {
  91. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [concrete = constants.%C] {
  92. // CHECK:STDOUT: %return.patt: %pattern_type.cb1 = return_slot_pattern [concrete]
  93. // CHECK:STDOUT: %return.param_patt: %pattern_type.cb1 = out_param_pattern %return.patt, call_param0 [concrete]
  94. // CHECK:STDOUT: } {
  95. // CHECK:STDOUT: %.loc17_12.1: %empty_tuple.type = tuple_literal ()
  96. // CHECK:STDOUT: %.loc17_12.2: type = converted %.loc17_12.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  97. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param call_param0
  98. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @B() -> %empty_tuple.type {
  103. // CHECK:STDOUT: !entry:
  104. // CHECK:STDOUT: <elided>
  105. // CHECK:STDOUT: %b.ref.loc11: ref %empty_tuple.type = name_ref b, %b
  106. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  107. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %A.ref()
  108. // CHECK:STDOUT: assign %b.ref.loc11, %A.call
  109. // CHECK:STDOUT: <elided>
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: fn @C() -> %empty_tuple.type {
  113. // CHECK:STDOUT: !entry:
  114. // CHECK:STDOUT: name_binding_decl {
  115. // CHECK:STDOUT: %c.patt: %pattern_type.cb1 = binding_pattern c [concrete]
  116. // CHECK:STDOUT: %c.var_patt: %pattern_type.cb1 = var_pattern %c.patt [concrete]
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %c.var: ref %empty_tuple.type = var %c.var_patt
  119. // CHECK:STDOUT: %.loc18_11.1: type = splice_block %.loc18_11.3 [concrete = constants.%empty_tuple.type] {
  120. // CHECK:STDOUT: %.loc18_11.2: %empty_tuple.type = tuple_literal ()
  121. // CHECK:STDOUT: %.loc18_11.3: type = converted %.loc18_11.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %c: ref %empty_tuple.type = bind_name c, %c.var
  124. // CHECK:STDOUT: %c.ref.loc19: ref %empty_tuple.type = name_ref c, %c
  125. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [concrete = constants.%B]
  126. // CHECK:STDOUT: %B.call: init %empty_tuple.type = call %B.ref()
  127. // CHECK:STDOUT: assign %c.ref.loc19, %B.call
  128. // CHECK:STDOUT: %c.ref.loc20: ref %empty_tuple.type = name_ref c, %c
  129. // CHECK:STDOUT: %tuple: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  130. // CHECK:STDOUT: %.loc20: %empty_tuple.type = converted %c.ref.loc20, %tuple [concrete = constants.%empty_tuple]
  131. // CHECK:STDOUT: return %.loc20
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: --- class.carbon
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: constants {
  137. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  138. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  139. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  140. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  141. // CHECK:STDOUT: %I.type: type = fn_type @I [concrete]
  142. // CHECK:STDOUT: %I: %I.type = struct_value () [concrete]
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: imports {
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: file {
  149. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: class @A {
  153. // CHECK:STDOUT: <elided>
  154. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  155. // CHECK:STDOUT: <elided>
  156. // CHECK:STDOUT: complete_type_witness = %complete_type
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: !members:
  159. // CHECK:STDOUT: .Self = constants.%A
  160. // CHECK:STDOUT: .F = %F.decl
  161. // CHECK:STDOUT: .G = %G.decl
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: class @C {
  165. // CHECK:STDOUT: %I.decl: %I.type = fn_decl @I [concrete = constants.%I] {} {}
  166. // CHECK:STDOUT: <elided>
  167. // CHECK:STDOUT: complete_type_witness = %complete_type
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: !members:
  170. // CHECK:STDOUT: .Self = constants.%C
  171. // CHECK:STDOUT: .I = %I.decl
  172. // CHECK:STDOUT: .J = %J.decl
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: fn @G();
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: fn @I();
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: --- call_params.carbon
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: constants {
  182. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  183. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  184. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  185. // CHECK:STDOUT: %C.type: type = fn_type @C [concrete]
  186. // CHECK:STDOUT: %C: %C.type = struct_value () [concrete]
  187. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  188. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  189. // CHECK:STDOUT: %Op.type.bae: type = fn_type @Op.1 [concrete]
  190. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  191. // CHECK:STDOUT: %Op.type.bc9: type = fn_type @Op.2, @impl(%T) [symbolic]
  192. // CHECK:STDOUT: %Op.46f: %Op.type.bc9 = struct_value () [symbolic]
  193. // CHECK:STDOUT: %Destroy.impl_witness.1dc: <witness> = impl_witness imports.%Destroy.impl_witness_table, @impl(%empty_tuple.type) [concrete]
  194. // CHECK:STDOUT: %Op.type.a63: type = fn_type @Op.2, @impl(%empty_tuple.type) [concrete]
  195. // CHECK:STDOUT: %Op.ea3: %Op.type.a63 = struct_value () [concrete]
  196. // CHECK:STDOUT: %Destroy.facet: %Destroy.type = facet_value %empty_tuple.type, (%Destroy.impl_witness.1dc) [concrete]
  197. // CHECK:STDOUT: %.346: type = fn_type_with_self_type %Op.type.bae, %Destroy.facet [concrete]
  198. // CHECK:STDOUT: %Op.specific_fn: <specific function> = specific_function %Op.ea3, @Op.2(%empty_tuple.type) [concrete]
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: imports {
  202. // CHECK:STDOUT: %Core.import_ref.0b9: @impl.%Op.type (%Op.type.bc9) = import_ref Core//prelude/parts/destroy, loc8_23, loaded [symbolic = @impl.%Op (constants.%Op.46f)]
  203. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (%Core.import_ref.0b9), @impl [concrete]
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: fn @G() {
  207. // CHECK:STDOUT: !entry:
  208. // CHECK:STDOUT: <elided>
  209. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  210. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %A.ref()
  211. // CHECK:STDOUT: <elided>
  212. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [concrete = constants.%C]
  213. // CHECK:STDOUT: %C.call: init %empty_tuple.type = call %C.ref()
  214. // CHECK:STDOUT: %.loc13_7.1: ref %empty_tuple.type = temporary_storage
  215. // CHECK:STDOUT: %.loc13_7.2: ref %empty_tuple.type = temporary %.loc13_7.1, %A.call
  216. // CHECK:STDOUT: %tuple.loc13_7.1: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  217. // CHECK:STDOUT: %.loc13_7.3: %empty_tuple.type = converted %A.call, %tuple.loc13_7.1 [concrete = constants.%empty_tuple]
  218. // CHECK:STDOUT: <elided>
  219. // CHECK:STDOUT: %.loc17_7.1: ref %empty_tuple.type = temporary_storage
  220. // CHECK:STDOUT: %.loc17_7.2: ref %empty_tuple.type = temporary %.loc17_7.1, %C.call
  221. // CHECK:STDOUT: %tuple.loc17_7.1: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  222. // CHECK:STDOUT: %.loc17_7.3: %empty_tuple.type = converted %C.call, %tuple.loc17_7.1 [concrete = constants.%empty_tuple]
  223. // CHECK:STDOUT: <elided>
  224. // CHECK:STDOUT: %impl.elem0.loc17: %.346 = impl_witness_access constants.%Destroy.impl_witness.1dc, element0 [concrete = constants.%Op.ea3]
  225. // CHECK:STDOUT: %bound_method.loc17_7.1: <bound method> = bound_method %.loc17_7.1, %impl.elem0.loc17
  226. // CHECK:STDOUT: %specific_fn.loc17: <specific function> = specific_function %impl.elem0.loc17, @Op.2(constants.%empty_tuple.type) [concrete = constants.%Op.specific_fn]
  227. // CHECK:STDOUT: %bound_method.loc17_7.2: <bound method> = bound_method %.loc17_7.1, %specific_fn.loc17
  228. // CHECK:STDOUT: %tuple.loc17_7.2: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  229. // CHECK:STDOUT: %.loc17_7.4: %empty_tuple.type = converted %.loc17_7.1, %tuple.loc17_7.2 [concrete = constants.%empty_tuple]
  230. // CHECK:STDOUT: %no_op.loc17: init %empty_tuple.type = call %bound_method.loc17_7.2(%.loc17_7.4)
  231. // CHECK:STDOUT: <elided>
  232. // CHECK:STDOUT: %impl.elem0.loc13: %.346 = impl_witness_access constants.%Destroy.impl_witness.1dc, element0 [concrete = constants.%Op.ea3]
  233. // CHECK:STDOUT: %bound_method.loc13_7.1: <bound method> = bound_method %.loc13_7.1, %impl.elem0.loc13
  234. // CHECK:STDOUT: %specific_fn.loc13: <specific function> = specific_function %impl.elem0.loc13, @Op.2(constants.%empty_tuple.type) [concrete = constants.%Op.specific_fn]
  235. // CHECK:STDOUT: %bound_method.loc13_7.2: <bound method> = bound_method %.loc13_7.1, %specific_fn.loc13
  236. // CHECK:STDOUT: %tuple.loc13_7.2: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  237. // CHECK:STDOUT: %.loc13_7.4: %empty_tuple.type = converted %.loc13_7.1, %tuple.loc13_7.2 [concrete = constants.%empty_tuple]
  238. // CHECK:STDOUT: %no_op.loc13: init %empty_tuple.type = call %bound_method.loc13_7.2(%.loc13_7.4)
  239. // CHECK:STDOUT: <elided>
  240. // CHECK:STDOUT: }
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: --- file_without_ranges.carbon
  243. // CHECK:STDOUT:
  244. // CHECK:STDOUT: constants {
  245. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  246. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  247. // CHECK:STDOUT: }
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: imports {
  250. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  251. // CHECK:STDOUT: import Core//prelude
  252. // CHECK:STDOUT: import Core//prelude/...
  253. // CHECK:STDOUT: }
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: file {
  257. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  258. // CHECK:STDOUT: .Core = imports.%Core
  259. // CHECK:STDOUT: .F = %F.decl
  260. // CHECK:STDOUT: }
  261. // CHECK:STDOUT: %Core.import = import Core
  262. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: fn @F();
  266. // CHECK:STDOUT: