raw_and_textual_ir.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. // ARGS: --include-diagnostic-kind compile --no-prelude-import --phase=check --dump-sem-ir --dump-raw-sem-ir %s
  6. //
  7. // Check that we can combine textual IR and raw IR dumping in one compile.
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/driver/testdata/compile/raw_and_textual_ir.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/driver/testdata/compile/raw_and_textual_ir.carbon
  14. fn Foo(n: ()) -> ((), ()) {
  15. return (n, ());
  16. }
  17. // CHECK:STDOUT: ---
  18. // CHECK:STDOUT: filename: raw_and_textual_ir.carbon
  19. // CHECK:STDOUT: sem_ir:
  20. // CHECK:STDOUT: import_irs:
  21. // CHECK:STDOUT: ir0: {decl_id: inst<none>, is_export: false}
  22. // CHECK:STDOUT: import_ir_insts: {}
  23. // CHECK:STDOUT: name_scopes:
  24. // CHECK:STDOUT: name_scope0: {inst: inst14, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst34}}
  25. // CHECK:STDOUT: entity_names:
  26. // CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope<none>, index: -1, is_template: 0}
  27. // CHECK:STDOUT: functions:
  28. // CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, call_params_id: inst_block9, return_slot_pattern: inst29, body: [inst_block12]}
  29. // CHECK:STDOUT: classes: {}
  30. // CHECK:STDOUT: generics: {}
  31. // CHECK:STDOUT: specifics: {}
  32. // CHECK:STDOUT: struct_type_fields:
  33. // CHECK:STDOUT: struct_type_fields0: {}
  34. // CHECK:STDOUT: types:
  35. // CHECK:STDOUT: 'type(TypeType)':
  36. // CHECK:STDOUT: value_repr: {kind: copy, type: type(TypeType)}
  37. // CHECK:STDOUT: 'type(Error)':
  38. // CHECK:STDOUT: value_repr: {kind: copy, type: type(Error)}
  39. // CHECK:STDOUT: 'type(inst(NamespaceType))':
  40. // CHECK:STDOUT: value_repr: {kind: copy, type: type(inst(NamespaceType))}
  41. // CHECK:STDOUT: 'type(inst35)':
  42. // CHECK:STDOUT: value_repr: {kind: none, type: type(inst15)}
  43. // CHECK:STDOUT: 'type(inst15)':
  44. // CHECK:STDOUT: value_repr: {kind: none, type: type(inst15)}
  45. // CHECK:STDOUT: 'type(inst23)':
  46. // CHECK:STDOUT: value_repr: {kind: pointer, type: type(inst37)}
  47. // CHECK:STDOUT: 'type(inst37)':
  48. // CHECK:STDOUT: value_repr: {kind: copy, type: type(inst37)}
  49. // CHECK:STDOUT: insts:
  50. // CHECK:STDOUT: inst14: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
  51. // CHECK:STDOUT: inst15: {kind: TupleType, arg0: inst_block_empty, type: type(TypeType)}
  52. // CHECK:STDOUT: inst16: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst15)}
  53. // CHECK:STDOUT: inst17: {kind: Converted, arg0: inst16, arg1: inst15, type: type(TypeType)}
  54. // CHECK:STDOUT: inst18: {kind: BindName, arg0: entity_name0, arg1: inst30, type: type(inst15)}
  55. // CHECK:STDOUT: inst19: {kind: BindingPattern, arg0: entity_name0, type: type(inst15)}
  56. // CHECK:STDOUT: inst20: {kind: ValueParamPattern, arg0: inst19, arg1: call_param0, type: type(inst15)}
  57. // CHECK:STDOUT: inst21: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst15)}
  58. // CHECK:STDOUT: inst22: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst15)}
  59. // CHECK:STDOUT: inst23: {kind: TupleType, arg0: inst_block7, type: type(TypeType)}
  60. // CHECK:STDOUT: inst24: {kind: TupleLiteral, arg0: inst_block6, type: type(inst23)}
  61. // CHECK:STDOUT: inst25: {kind: Converted, arg0: inst21, arg1: inst15, type: type(TypeType)}
  62. // CHECK:STDOUT: inst26: {kind: Converted, arg0: inst22, arg1: inst15, type: type(TypeType)}
  63. // CHECK:STDOUT: inst27: {kind: Converted, arg0: inst24, arg1: inst23, type: type(TypeType)}
  64. // CHECK:STDOUT: inst28: {kind: ReturnSlotPattern, arg0: inst27, type: type(inst23)}
  65. // CHECK:STDOUT: inst29: {kind: OutParamPattern, arg0: inst28, arg1: call_param1, type: type(inst23)}
  66. // CHECK:STDOUT: inst30: {kind: ValueParam, arg0: call_param0, arg1: name1, type: type(inst15)}
  67. // CHECK:STDOUT: inst31: {kind: SpliceBlock, arg0: inst_block4, arg1: inst17, type: type(TypeType)}
  68. // CHECK:STDOUT: inst32: {kind: OutParam, arg0: call_param1, arg1: name(ReturnSlot), type: type(inst23)}
  69. // CHECK:STDOUT: inst33: {kind: ReturnSlot, arg0: inst27, arg1: inst32, type: type(inst23)}
  70. // CHECK:STDOUT: inst34: {kind: FunctionDecl, arg0: function0, arg1: inst_block11, type: type(inst35)}
  71. // CHECK:STDOUT: inst35: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
  72. // CHECK:STDOUT: inst36: {kind: StructValue, arg0: inst_block_empty, type: type(inst35)}
  73. // CHECK:STDOUT: inst37: {kind: PointerType, arg0: inst23, type: type(TypeType)}
  74. // CHECK:STDOUT: inst38: {kind: NameRef, arg0: name1, arg1: inst18, type: type(inst15)}
  75. // CHECK:STDOUT: inst39: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst15)}
  76. // CHECK:STDOUT: inst40: {kind: TupleLiteral, arg0: inst_block13, type: type(inst23)}
  77. // CHECK:STDOUT: inst41: {kind: TupleAccess, arg0: inst33, arg1: element0, type: type(inst15)}
  78. // CHECK:STDOUT: inst42: {kind: TupleInit, arg0: inst_block14, arg1: inst41, type: type(inst15)}
  79. // CHECK:STDOUT: inst43: {kind: TupleValue, arg0: inst_block_empty, type: type(inst15)}
  80. // CHECK:STDOUT: inst44: {kind: Converted, arg0: inst38, arg1: inst42, type: type(inst15)}
  81. // CHECK:STDOUT: inst45: {kind: TupleAccess, arg0: inst33, arg1: element1, type: type(inst15)}
  82. // CHECK:STDOUT: inst46: {kind: TupleInit, arg0: inst_block_empty, arg1: inst45, type: type(inst15)}
  83. // CHECK:STDOUT: inst47: {kind: Converted, arg0: inst39, arg1: inst46, type: type(inst15)}
  84. // CHECK:STDOUT: inst48: {kind: TupleInit, arg0: inst_block15, arg1: inst33, type: type(inst23)}
  85. // CHECK:STDOUT: inst49: {kind: TupleValue, arg0: inst_block16, type: type(inst23)}
  86. // CHECK:STDOUT: inst50: {kind: Converted, arg0: inst40, arg1: inst48, type: type(inst23)}
  87. // CHECK:STDOUT: inst51: {kind: ReturnExpr, arg0: inst50, arg1: inst33}
  88. // CHECK:STDOUT: constant_values:
  89. // CHECK:STDOUT: inst14: concrete_constant(inst14)
  90. // CHECK:STDOUT: inst15: concrete_constant(inst15)
  91. // CHECK:STDOUT: inst17: concrete_constant(inst15)
  92. // CHECK:STDOUT: inst23: concrete_constant(inst23)
  93. // CHECK:STDOUT: inst25: concrete_constant(inst15)
  94. // CHECK:STDOUT: inst26: concrete_constant(inst15)
  95. // CHECK:STDOUT: inst27: concrete_constant(inst23)
  96. // CHECK:STDOUT: inst31: concrete_constant(inst15)
  97. // CHECK:STDOUT: inst34: concrete_constant(inst36)
  98. // CHECK:STDOUT: inst35: concrete_constant(inst35)
  99. // CHECK:STDOUT: inst36: concrete_constant(inst36)
  100. // CHECK:STDOUT: inst37: concrete_constant(inst37)
  101. // CHECK:STDOUT: inst42: concrete_constant(inst43)
  102. // CHECK:STDOUT: inst43: concrete_constant(inst43)
  103. // CHECK:STDOUT: inst44: concrete_constant(inst43)
  104. // CHECK:STDOUT: inst46: concrete_constant(inst43)
  105. // CHECK:STDOUT: inst47: concrete_constant(inst43)
  106. // CHECK:STDOUT: inst48: concrete_constant(inst49)
  107. // CHECK:STDOUT: inst49: concrete_constant(inst49)
  108. // CHECK:STDOUT: inst50: concrete_constant(inst49)
  109. // CHECK:STDOUT: symbolic_constants: {}
  110. // CHECK:STDOUT: inst_blocks:
  111. // CHECK:STDOUT: inst_block_empty: {}
  112. // CHECK:STDOUT: exports:
  113. // CHECK:STDOUT: 0: inst34
  114. // CHECK:STDOUT: import_refs: {}
  115. // CHECK:STDOUT: global_init: {}
  116. // CHECK:STDOUT: inst_block4:
  117. // CHECK:STDOUT: 0: inst16
  118. // CHECK:STDOUT: 1: inst17
  119. // CHECK:STDOUT: inst_block5:
  120. // CHECK:STDOUT: 0: inst20
  121. // CHECK:STDOUT: inst_block6:
  122. // CHECK:STDOUT: 0: inst21
  123. // CHECK:STDOUT: 1: inst22
  124. // CHECK:STDOUT: inst_block7:
  125. // CHECK:STDOUT: 0: inst15
  126. // CHECK:STDOUT: 1: inst15
  127. // CHECK:STDOUT: inst_block8:
  128. // CHECK:STDOUT: 0: inst25
  129. // CHECK:STDOUT: 1: inst26
  130. // CHECK:STDOUT: inst_block9:
  131. // CHECK:STDOUT: 0: inst30
  132. // CHECK:STDOUT: 1: inst32
  133. // CHECK:STDOUT: inst_block10:
  134. // CHECK:STDOUT: 0: inst19
  135. // CHECK:STDOUT: 1: inst20
  136. // CHECK:STDOUT: 2: inst28
  137. // CHECK:STDOUT: 3: inst29
  138. // CHECK:STDOUT: inst_block11:
  139. // CHECK:STDOUT: 0: inst21
  140. // CHECK:STDOUT: 1: inst22
  141. // CHECK:STDOUT: 2: inst24
  142. // CHECK:STDOUT: 3: inst25
  143. // CHECK:STDOUT: 4: inst26
  144. // CHECK:STDOUT: 5: inst27
  145. // CHECK:STDOUT: 6: inst30
  146. // CHECK:STDOUT: 7: inst31
  147. // CHECK:STDOUT: 8: inst18
  148. // CHECK:STDOUT: 9: inst32
  149. // CHECK:STDOUT: 10: inst33
  150. // CHECK:STDOUT: inst_block12:
  151. // CHECK:STDOUT: 0: inst38
  152. // CHECK:STDOUT: 1: inst39
  153. // CHECK:STDOUT: 2: inst40
  154. // CHECK:STDOUT: 3: inst41
  155. // CHECK:STDOUT: 4: inst42
  156. // CHECK:STDOUT: 5: inst44
  157. // CHECK:STDOUT: 6: inst45
  158. // CHECK:STDOUT: 7: inst46
  159. // CHECK:STDOUT: 8: inst47
  160. // CHECK:STDOUT: 9: inst48
  161. // CHECK:STDOUT: 10: inst50
  162. // CHECK:STDOUT: 11: inst51
  163. // CHECK:STDOUT: inst_block13:
  164. // CHECK:STDOUT: 0: inst38
  165. // CHECK:STDOUT: 1: inst39
  166. // CHECK:STDOUT: inst_block14: {}
  167. // CHECK:STDOUT: inst_block15:
  168. // CHECK:STDOUT: 0: inst44
  169. // CHECK:STDOUT: 1: inst47
  170. // CHECK:STDOUT: inst_block16:
  171. // CHECK:STDOUT: 0: inst43
  172. // CHECK:STDOUT: 1: inst43
  173. // CHECK:STDOUT: inst_block17:
  174. // CHECK:STDOUT: 0: inst14
  175. // CHECK:STDOUT: 1: inst34
  176. // CHECK:STDOUT: ...
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: --- raw_and_textual_ir.carbon
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: constants {
  181. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  182. // CHECK:STDOUT: %tuple.type: type = tuple_type (%empty_tuple.type, %empty_tuple.type) [concrete]
  183. // CHECK:STDOUT: %Foo.type: type = fn_type @Foo [concrete]
  184. // CHECK:STDOUT: %Foo: %Foo.type = struct_value () [concrete]
  185. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  186. // CHECK:STDOUT: %tuple: %tuple.type = tuple_value (%empty_tuple, %empty_tuple) [concrete]
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: file {
  190. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  191. // CHECK:STDOUT: .Foo = %Foo.decl
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [concrete = constants.%Foo] {
  194. // CHECK:STDOUT: %n.patt: %empty_tuple.type = binding_pattern n
  195. // CHECK:STDOUT: %n.param_patt: %empty_tuple.type = value_param_pattern %n.patt, call_param0
  196. // CHECK:STDOUT: %return.patt: %tuple.type = return_slot_pattern
  197. // CHECK:STDOUT: %return.param_patt: %tuple.type = out_param_pattern %return.patt, call_param1
  198. // CHECK:STDOUT: } {
  199. // CHECK:STDOUT: %.loc15_20: %empty_tuple.type = tuple_literal ()
  200. // CHECK:STDOUT: %.loc15_24: %empty_tuple.type = tuple_literal ()
  201. // CHECK:STDOUT: %.loc15_25.1: %tuple.type = tuple_literal (%.loc15_20, %.loc15_24)
  202. // CHECK:STDOUT: %.loc15_25.2: type = converted %.loc15_20, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  203. // CHECK:STDOUT: %.loc15_25.3: type = converted %.loc15_24, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  204. // CHECK:STDOUT: %.loc15_25.4: type = converted %.loc15_25.1, constants.%tuple.type [concrete = constants.%tuple.type]
  205. // CHECK:STDOUT: %n.param: %empty_tuple.type = value_param call_param0
  206. // CHECK:STDOUT: %.loc15_12.1: type = splice_block %.loc15_12.3 [concrete = constants.%empty_tuple.type] {
  207. // CHECK:STDOUT: %.loc15_12.2: %empty_tuple.type = tuple_literal ()
  208. // CHECK:STDOUT: %.loc15_12.3: type = converted %.loc15_12.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
  211. // CHECK:STDOUT: %return.param: ref %tuple.type = out_param call_param1
  212. // CHECK:STDOUT: %return: ref %tuple.type = return_slot %return.param
  213. // CHECK:STDOUT: }
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: fn @Foo(%n.param: %empty_tuple.type) -> %return.param: %tuple.type {
  217. // CHECK:STDOUT: !entry:
  218. // CHECK:STDOUT: %n.ref: %empty_tuple.type = name_ref n, %n
  219. // CHECK:STDOUT: %.loc16_15.1: %empty_tuple.type = tuple_literal ()
  220. // CHECK:STDOUT: %.loc16_16.1: %tuple.type = tuple_literal (%n.ref, %.loc16_15.1)
  221. // CHECK:STDOUT: %tuple.elem0: ref %empty_tuple.type = tuple_access %return, element0
  222. // CHECK:STDOUT: %.loc16_11: init %empty_tuple.type = tuple_init () to %tuple.elem0 [concrete = constants.%empty_tuple]
  223. // CHECK:STDOUT: %.loc16_16.2: init %empty_tuple.type = converted %n.ref, %.loc16_11 [concrete = constants.%empty_tuple]
  224. // CHECK:STDOUT: %tuple.elem1: ref %empty_tuple.type = tuple_access %return, element1
  225. // CHECK:STDOUT: %.loc16_15.2: init %empty_tuple.type = tuple_init () to %tuple.elem1 [concrete = constants.%empty_tuple]
  226. // CHECK:STDOUT: %.loc16_16.3: init %empty_tuple.type = converted %.loc16_15.1, %.loc16_15.2 [concrete = constants.%empty_tuple]
  227. // CHECK:STDOUT: %.loc16_16.4: init %tuple.type = tuple_init (%.loc16_16.2, %.loc16_16.3) to %return [concrete = constants.%tuple]
  228. // CHECK:STDOUT: %.loc16_17: init %tuple.type = converted %.loc16_16.1, %.loc16_16.4 [concrete = constants.%tuple]
  229. // CHECK:STDOUT: return %.loc16_17 to %return
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT: