dump_sem_ir_ranges.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. // --- explicit_dump_file.carbon
  74. library "[[@TEST_NAME]]";
  75. //@include-in-dumps
  76. // CHECK:STDOUT: --- function.carbon
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: constants {
  79. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  80. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  81. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  82. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  83. // CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
  84. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  85. // CHECK:STDOUT: %facet_value: %type_where = facet_value %empty_tuple.type, () [concrete]
  86. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  87. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.72f: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8 = struct_value () [concrete]
  88. // CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
  89. // CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
  90. // CHECK:STDOUT: %C.type: type = fn_type @C [concrete]
  91. // CHECK:STDOUT: %C: %C.type = struct_value () [concrete]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: imports {
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: file {
  98. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [concrete = constants.%C] {
  99. // CHECK:STDOUT: %return.patt: %pattern_type.cb1 = return_slot_pattern [concrete]
  100. // CHECK:STDOUT: %return.param_patt: %pattern_type.cb1 = out_param_pattern %return.patt, call_param0 [concrete]
  101. // CHECK:STDOUT: } {
  102. // CHECK:STDOUT: %.loc17_12.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  103. // CHECK:STDOUT: %.loc17_12.2: type = converted %.loc17_12.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  104. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param call_param0
  105. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn @B() -> %empty_tuple.type {
  110. // CHECK:STDOUT: !entry:
  111. // CHECK:STDOUT: <elided>
  112. // CHECK:STDOUT: %b.ref.loc11: ref %empty_tuple.type = name_ref b, %b
  113. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  114. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %A.ref()
  115. // CHECK:STDOUT: assign %b.ref.loc11, %A.call
  116. // CHECK:STDOUT: <elided>
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @C() -> %empty_tuple.type {
  120. // CHECK:STDOUT: !entry:
  121. // CHECK:STDOUT: name_binding_decl {
  122. // CHECK:STDOUT: %c.patt: %pattern_type.cb1 = ref_binding_pattern c [concrete]
  123. // CHECK:STDOUT: %c.var_patt: %pattern_type.cb1 = var_pattern %c.patt [concrete]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: %c.var: ref %empty_tuple.type = var %c.var_patt
  126. // CHECK:STDOUT: %.loc18_11.1: type = splice_block %.loc18_11.3 [concrete = constants.%empty_tuple.type] {
  127. // CHECK:STDOUT: %.loc18_11.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  128. // CHECK:STDOUT: %.loc18_11.3: type = converted %.loc18_11.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %c: ref %empty_tuple.type = ref_binding c, %c.var
  131. // CHECK:STDOUT: %c.ref.loc19: ref %empty_tuple.type = name_ref c, %c
  132. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [concrete = constants.%B]
  133. // CHECK:STDOUT: %B.call: init %empty_tuple.type = call %B.ref()
  134. // CHECK:STDOUT: assign %c.ref.loc19, %B.call
  135. // CHECK:STDOUT: %c.ref.loc20: ref %empty_tuple.type = name_ref c, %c
  136. // CHECK:STDOUT: %.loc20_10: init %empty_tuple.type = tuple_init () to %return [concrete = constants.%empty_tuple]
  137. // CHECK:STDOUT: %.loc20_11: init %empty_tuple.type = converted %c.ref.loc20, %.loc20_10 [concrete = constants.%empty_tuple]
  138. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %c.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f
  139. // CHECK:STDOUT: <elided>
  140. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %c.var, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
  141. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%c.var)
  142. // CHECK:STDOUT: return %.loc20_11 to %return
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: --- class.carbon
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: constants {
  148. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  149. // CHECK:STDOUT: %A.G.type: type = fn_type @A.G [concrete]
  150. // CHECK:STDOUT: %A.G: %A.G.type = struct_value () [concrete]
  151. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  152. // CHECK:STDOUT: %C.I.type: type = fn_type @C.I [concrete]
  153. // CHECK:STDOUT: %C.I: %C.I.type = struct_value () [concrete]
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: imports {
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: file {
  160. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: class @A {
  164. // CHECK:STDOUT: <elided>
  165. // CHECK:STDOUT: %A.G.decl: %A.G.type = fn_decl @A.G [concrete = constants.%A.G] {} {}
  166. // CHECK:STDOUT: <elided>
  167. // CHECK:STDOUT: complete_type_witness = %complete_type
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: !members:
  170. // CHECK:STDOUT: .Self = constants.%A
  171. // CHECK:STDOUT: .F = %A.F.decl
  172. // CHECK:STDOUT: .G = %A.G.decl
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: class @C {
  176. // CHECK:STDOUT: %C.I.decl: %C.I.type = fn_decl @C.I [concrete = constants.%C.I] {} {}
  177. // CHECK:STDOUT: <elided>
  178. // CHECK:STDOUT: complete_type_witness = %complete_type
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: !members:
  181. // CHECK:STDOUT: .Self = constants.%C
  182. // CHECK:STDOUT: .I = %C.I.decl
  183. // CHECK:STDOUT: .J = %C.J.decl
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: fn @A.G();
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: fn @C.I();
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: --- call_params.carbon
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: constants {
  193. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  194. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  195. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  196. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  197. // CHECK:STDOUT: %C.type: type = fn_type @C [concrete]
  198. // CHECK:STDOUT: %C: %C.type = struct_value () [concrete]
  199. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
  200. // CHECK:STDOUT: %facet_value: %type_where = facet_value %empty_tuple.type, () [concrete]
  201. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
  202. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.72f: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.bb8 = struct_value () [concrete]
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: imports {
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: fn @G() {
  209. // CHECK:STDOUT: !entry:
  210. // CHECK:STDOUT: <elided>
  211. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
  212. // CHECK:STDOUT: %A.call: init %empty_tuple.type = call %A.ref()
  213. // CHECK:STDOUT: <elided>
  214. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [concrete = constants.%C]
  215. // CHECK:STDOUT: %C.call: init %empty_tuple.type = call %C.ref()
  216. // CHECK:STDOUT: %.loc13_7.1: ref %empty_tuple.type = temporary_storage
  217. // CHECK:STDOUT: %.loc13_7.2: ref %empty_tuple.type = temporary %.loc13_7.1, %A.call
  218. // CHECK:STDOUT: %tuple.loc13: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  219. // CHECK:STDOUT: %.loc13_7.3: %empty_tuple.type = converted %A.call, %tuple.loc13 [concrete = constants.%empty_tuple]
  220. // CHECK:STDOUT: <elided>
  221. // CHECK:STDOUT: %.loc17_7.1: ref %empty_tuple.type = temporary_storage
  222. // CHECK:STDOUT: %.loc17_7.2: ref %empty_tuple.type = temporary %.loc17_7.1, %C.call
  223. // CHECK:STDOUT: %tuple.loc17: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  224. // CHECK:STDOUT: %.loc17_7.3: %empty_tuple.type = converted %C.call, %tuple.loc17 [concrete = constants.%empty_tuple]
  225. // CHECK:STDOUT: <elided>
  226. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound.loc17: <bound method> = bound_method %.loc17_7.2, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f
  227. // CHECK:STDOUT: <elided>
  228. // CHECK:STDOUT: %bound_method.loc17: <bound method> = bound_method %.loc17_7.2, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn.1
  229. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call.loc17: init %empty_tuple.type = call %bound_method.loc17(%.loc17_7.2)
  230. // CHECK:STDOUT: <elided>
  231. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound.loc13: <bound method> = bound_method %.loc13_7.2, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.72f
  232. // CHECK:STDOUT: <elided>
  233. // CHECK:STDOUT: %bound_method.loc13: <bound method> = bound_method %.loc13_7.2, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn.3
  234. // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call.loc13: init %empty_tuple.type = call %bound_method.loc13(%.loc13_7.2)
  235. // CHECK:STDOUT: <elided>
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: --- file_without_ranges.carbon
  239. // CHECK:STDOUT:
  240. // CHECK:STDOUT: constants {
  241. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  242. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT:
  245. // CHECK:STDOUT: imports {
  246. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  247. // CHECK:STDOUT: import Core//prelude
  248. // CHECK:STDOUT: import Core//prelude/...
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT: }
  251. // CHECK:STDOUT:
  252. // CHECK:STDOUT: file {
  253. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  254. // CHECK:STDOUT: .Core = imports.%Core
  255. // CHECK:STDOUT: .F = %F.decl
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT: %Core.import = import Core
  258. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  259. // CHECK:STDOUT: }
  260. // CHECK:STDOUT:
  261. // CHECK:STDOUT: fn @F();
  262. // CHECK:STDOUT:
  263. // CHECK:STDOUT: --- explicit_dump_file.carbon
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: imports {
  266. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  267. // CHECK:STDOUT: import Core//prelude
  268. // CHECK:STDOUT: import Core//prelude/...
  269. // CHECK:STDOUT: }
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: file {
  273. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  274. // CHECK:STDOUT: .Core = imports.%Core
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT: %Core.import = import Core
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT: