raw_and_textual_ir.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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: inst12, parent_scope: name_scope<none>, has_error: false, extended_scopes: [], names: {name0: inst32}}
  25. // CHECK:STDOUT: entity_names:
  26. // CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope<none>, index: comp_time_bind<none>}
  27. // CHECK:STDOUT: functions:
  28. // CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, return_slot_pattern: inst27, body: [inst_block10]}
  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)': {kind: copy, type: type(TypeType)}
  36. // CHECK:STDOUT: 'type(Error)': {kind: copy, type: type(Error)}
  37. // CHECK:STDOUT: 'type(inst(NamespaceType))': {kind: copy, type: type(inst(NamespaceType))}
  38. // CHECK:STDOUT: 'type(inst33)': {kind: none, type: type(inst13)}
  39. // CHECK:STDOUT: 'type(inst13)': {kind: none, type: type(inst13)}
  40. // CHECK:STDOUT: 'type(inst21)': {kind: pointer, type: type(inst35)}
  41. // CHECK:STDOUT: 'type(inst35)': {kind: copy, type: type(inst35)}
  42. // CHECK:STDOUT: type_blocks:
  43. // CHECK:STDOUT: type_block0: {}
  44. // CHECK:STDOUT: type_block1:
  45. // CHECK:STDOUT: 0: type(inst13)
  46. // CHECK:STDOUT: 1: type(inst13)
  47. // CHECK:STDOUT: insts:
  48. // CHECK:STDOUT: inst12: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
  49. // CHECK:STDOUT: inst13: {kind: TupleType, arg0: type_block0, type: type(TypeType)}
  50. // CHECK:STDOUT: inst14: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst13)}
  51. // CHECK:STDOUT: inst15: {kind: Converted, arg0: inst14, arg1: inst13, type: type(TypeType)}
  52. // CHECK:STDOUT: inst16: {kind: BindName, arg0: entity_name0, arg1: inst28, type: type(inst13)}
  53. // CHECK:STDOUT: inst17: {kind: BindingPattern, arg0: entity_name0, type: type(inst13)}
  54. // CHECK:STDOUT: inst18: {kind: ValueParamPattern, arg0: inst17, arg1: runtime_param0, type: type(inst13)}
  55. // CHECK:STDOUT: inst19: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst13)}
  56. // CHECK:STDOUT: inst20: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst13)}
  57. // CHECK:STDOUT: inst21: {kind: TupleType, arg0: type_block1, type: type(TypeType)}
  58. // CHECK:STDOUT: inst22: {kind: TupleLiteral, arg0: inst_block6, type: type(inst21)}
  59. // CHECK:STDOUT: inst23: {kind: Converted, arg0: inst19, arg1: inst13, type: type(TypeType)}
  60. // CHECK:STDOUT: inst24: {kind: Converted, arg0: inst20, arg1: inst13, type: type(TypeType)}
  61. // CHECK:STDOUT: inst25: {kind: Converted, arg0: inst22, arg1: inst21, type: type(TypeType)}
  62. // CHECK:STDOUT: inst26: {kind: ReturnSlotPattern, arg0: inst22, type: type(inst21)}
  63. // CHECK:STDOUT: inst27: {kind: OutParamPattern, arg0: inst26, arg1: runtime_param1, type: type(inst21)}
  64. // CHECK:STDOUT: inst28: {kind: ValueParam, arg0: runtime_param0, arg1: name1, type: type(inst13)}
  65. // CHECK:STDOUT: inst29: {kind: SpliceBlock, arg0: inst_block4, arg1: inst15, type: type(TypeType)}
  66. // CHECK:STDOUT: inst30: {kind: OutParam, arg0: runtime_param1, arg1: name(ReturnSlot), type: type(inst21)}
  67. // CHECK:STDOUT: inst31: {kind: ReturnSlot, arg0: inst22, arg1: inst30, type: type(inst21)}
  68. // CHECK:STDOUT: inst32: {kind: FunctionDecl, arg0: function0, arg1: inst_block9, type: type(inst33)}
  69. // CHECK:STDOUT: inst33: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
  70. // CHECK:STDOUT: inst34: {kind: StructValue, arg0: inst_block_empty, type: type(inst33)}
  71. // CHECK:STDOUT: inst35: {kind: PointerType, arg0: type(inst21), type: type(TypeType)}
  72. // CHECK:STDOUT: inst36: {kind: NameRef, arg0: name1, arg1: inst16, type: type(inst13)}
  73. // CHECK:STDOUT: inst37: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst13)}
  74. // CHECK:STDOUT: inst38: {kind: TupleLiteral, arg0: inst_block11, type: type(inst21)}
  75. // CHECK:STDOUT: inst39: {kind: TupleAccess, arg0: inst31, arg1: element0, type: type(inst13)}
  76. // CHECK:STDOUT: inst40: {kind: TupleInit, arg0: inst_block12, arg1: inst39, type: type(inst13)}
  77. // CHECK:STDOUT: inst41: {kind: TupleValue, arg0: inst_block_empty, type: type(inst13)}
  78. // CHECK:STDOUT: inst42: {kind: Converted, arg0: inst36, arg1: inst40, type: type(inst13)}
  79. // CHECK:STDOUT: inst43: {kind: TupleAccess, arg0: inst31, arg1: element1, type: type(inst13)}
  80. // CHECK:STDOUT: inst44: {kind: TupleInit, arg0: inst_block_empty, arg1: inst43, type: type(inst13)}
  81. // CHECK:STDOUT: inst45: {kind: Converted, arg0: inst37, arg1: inst44, type: type(inst13)}
  82. // CHECK:STDOUT: inst46: {kind: TupleInit, arg0: inst_block13, arg1: inst31, type: type(inst21)}
  83. // CHECK:STDOUT: inst47: {kind: TupleValue, arg0: inst_block14, type: type(inst21)}
  84. // CHECK:STDOUT: inst48: {kind: Converted, arg0: inst38, arg1: inst46, type: type(inst21)}
  85. // CHECK:STDOUT: inst49: {kind: ReturnExpr, arg0: inst48, arg1: inst31}
  86. // CHECK:STDOUT: constant_values:
  87. // CHECK:STDOUT: inst12: template_constant(inst12)
  88. // CHECK:STDOUT: inst13: template_constant(inst13)
  89. // CHECK:STDOUT: inst15: template_constant(inst13)
  90. // CHECK:STDOUT: inst21: template_constant(inst21)
  91. // CHECK:STDOUT: inst23: template_constant(inst13)
  92. // CHECK:STDOUT: inst24: template_constant(inst13)
  93. // CHECK:STDOUT: inst25: template_constant(inst21)
  94. // CHECK:STDOUT: inst29: template_constant(inst13)
  95. // CHECK:STDOUT: inst32: template_constant(inst34)
  96. // CHECK:STDOUT: inst33: template_constant(inst33)
  97. // CHECK:STDOUT: inst34: template_constant(inst34)
  98. // CHECK:STDOUT: inst35: template_constant(inst35)
  99. // CHECK:STDOUT: inst40: template_constant(inst41)
  100. // CHECK:STDOUT: inst41: template_constant(inst41)
  101. // CHECK:STDOUT: inst42: template_constant(inst41)
  102. // CHECK:STDOUT: inst44: template_constant(inst41)
  103. // CHECK:STDOUT: inst45: template_constant(inst41)
  104. // CHECK:STDOUT: inst46: template_constant(inst47)
  105. // CHECK:STDOUT: inst47: template_constant(inst47)
  106. // CHECK:STDOUT: inst48: template_constant(inst47)
  107. // CHECK:STDOUT: symbolic_constants: {}
  108. // CHECK:STDOUT: inst_blocks:
  109. // CHECK:STDOUT: inst_block_empty: {}
  110. // CHECK:STDOUT: exports:
  111. // CHECK:STDOUT: 0: inst32
  112. // CHECK:STDOUT: import_refs: {}
  113. // CHECK:STDOUT: global_init: {}
  114. // CHECK:STDOUT: inst_block4:
  115. // CHECK:STDOUT: 0: inst14
  116. // CHECK:STDOUT: 1: inst15
  117. // CHECK:STDOUT: inst_block5:
  118. // CHECK:STDOUT: 0: inst18
  119. // CHECK:STDOUT: inst_block6:
  120. // CHECK:STDOUT: 0: inst19
  121. // CHECK:STDOUT: 1: inst20
  122. // CHECK:STDOUT: inst_block7:
  123. // CHECK:STDOUT: 0: inst28
  124. // CHECK:STDOUT: 1: inst30
  125. // CHECK:STDOUT: inst_block8:
  126. // CHECK:STDOUT: 0: inst17
  127. // CHECK:STDOUT: 1: inst18
  128. // CHECK:STDOUT: 2: inst26
  129. // CHECK:STDOUT: 3: inst27
  130. // CHECK:STDOUT: inst_block9:
  131. // CHECK:STDOUT: 0: inst19
  132. // CHECK:STDOUT: 1: inst20
  133. // CHECK:STDOUT: 2: inst22
  134. // CHECK:STDOUT: 3: inst23
  135. // CHECK:STDOUT: 4: inst24
  136. // CHECK:STDOUT: 5: inst25
  137. // CHECK:STDOUT: 6: inst28
  138. // CHECK:STDOUT: 7: inst29
  139. // CHECK:STDOUT: 8: inst16
  140. // CHECK:STDOUT: 9: inst30
  141. // CHECK:STDOUT: 10: inst31
  142. // CHECK:STDOUT: inst_block10:
  143. // CHECK:STDOUT: 0: inst36
  144. // CHECK:STDOUT: 1: inst37
  145. // CHECK:STDOUT: 2: inst38
  146. // CHECK:STDOUT: 3: inst39
  147. // CHECK:STDOUT: 4: inst40
  148. // CHECK:STDOUT: 5: inst42
  149. // CHECK:STDOUT: 6: inst43
  150. // CHECK:STDOUT: 7: inst44
  151. // CHECK:STDOUT: 8: inst45
  152. // CHECK:STDOUT: 9: inst46
  153. // CHECK:STDOUT: 10: inst48
  154. // CHECK:STDOUT: 11: inst49
  155. // CHECK:STDOUT: inst_block11:
  156. // CHECK:STDOUT: 0: inst36
  157. // CHECK:STDOUT: 1: inst37
  158. // CHECK:STDOUT: inst_block12: {}
  159. // CHECK:STDOUT: inst_block13:
  160. // CHECK:STDOUT: 0: inst42
  161. // CHECK:STDOUT: 1: inst45
  162. // CHECK:STDOUT: inst_block14:
  163. // CHECK:STDOUT: 0: inst41
  164. // CHECK:STDOUT: 1: inst41
  165. // CHECK:STDOUT: inst_block15:
  166. // CHECK:STDOUT: 0: inst12
  167. // CHECK:STDOUT: 1: inst32
  168. // CHECK:STDOUT: ...
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: --- raw_and_textual_ir.carbon
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: constants {
  173. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  174. // CHECK:STDOUT: %tuple.type: type = tuple_type (%empty_tuple.type, %empty_tuple.type) [template]
  175. // CHECK:STDOUT: %Foo.type: type = fn_type @Foo [template]
  176. // CHECK:STDOUT: %Foo: %Foo.type = struct_value () [template]
  177. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template]
  178. // CHECK:STDOUT: %tuple: %tuple.type = tuple_value (%empty_tuple, %empty_tuple) [template]
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: file {
  182. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  183. // CHECK:STDOUT: .Foo = %Foo.decl
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [template = constants.%Foo] {
  186. // CHECK:STDOUT: %n.patt: %empty_tuple.type = binding_pattern n
  187. // CHECK:STDOUT: %n.param_patt: %empty_tuple.type = value_param_pattern %n.patt, runtime_param0
  188. // CHECK:STDOUT: %return.patt: %tuple.type = return_slot_pattern
  189. // CHECK:STDOUT: %return.param_patt: %tuple.type = out_param_pattern %return.patt, runtime_param1
  190. // CHECK:STDOUT: } {
  191. // CHECK:STDOUT: %.loc15_20: %empty_tuple.type = tuple_literal ()
  192. // CHECK:STDOUT: %.loc15_24: %empty_tuple.type = tuple_literal ()
  193. // CHECK:STDOUT: %.loc15_25.1: %tuple.type = tuple_literal (%.loc15_20, %.loc15_24)
  194. // CHECK:STDOUT: %.loc15_25.2: type = converted %.loc15_20, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  195. // CHECK:STDOUT: %.loc15_25.3: type = converted %.loc15_24, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  196. // CHECK:STDOUT: %.loc15_25.4: type = converted %.loc15_25.1, constants.%tuple.type [template = constants.%tuple.type]
  197. // CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
  198. // CHECK:STDOUT: %.loc15_12.1: type = splice_block %.loc15_12.3 [template = constants.%empty_tuple.type] {
  199. // CHECK:STDOUT: %.loc15_12.2: %empty_tuple.type = tuple_literal ()
  200. // CHECK:STDOUT: %.loc15_12.3: type = converted %.loc15_12.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
  203. // CHECK:STDOUT: %return.param: ref %tuple.type = out_param runtime_param1
  204. // CHECK:STDOUT: %return: ref %tuple.type = return_slot %return.param
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: fn @Foo(%n.param_patt: %empty_tuple.type) -> %return.param_patt: %tuple.type {
  209. // CHECK:STDOUT: !entry:
  210. // CHECK:STDOUT: %n.ref: %empty_tuple.type = name_ref n, %n
  211. // CHECK:STDOUT: %.loc16_15.1: %empty_tuple.type = tuple_literal ()
  212. // CHECK:STDOUT: %.loc16_16.1: %tuple.type = tuple_literal (%n.ref, %.loc16_15.1)
  213. // CHECK:STDOUT: %tuple.elem0: ref %empty_tuple.type = tuple_access %return, element0
  214. // CHECK:STDOUT: %.loc16_11: init %empty_tuple.type = tuple_init () to %tuple.elem0 [template = constants.%empty_tuple]
  215. // CHECK:STDOUT: %.loc16_16.2: init %empty_tuple.type = converted %n.ref, %.loc16_11 [template = constants.%empty_tuple]
  216. // CHECK:STDOUT: %tuple.elem1: ref %empty_tuple.type = tuple_access %return, element1
  217. // CHECK:STDOUT: %.loc16_15.2: init %empty_tuple.type = tuple_init () to %tuple.elem1 [template = constants.%empty_tuple]
  218. // CHECK:STDOUT: %.loc16_16.3: init %empty_tuple.type = converted %.loc16_15.1, %.loc16_15.2 [template = constants.%empty_tuple]
  219. // CHECK:STDOUT: %.loc16_16.4: init %tuple.type = tuple_init (%.loc16_16.2, %.loc16_16.3) to %return [template = constants.%tuple]
  220. // CHECK:STDOUT: %.loc16_17: init %tuple.type = converted %.loc16_16.1, %.loc16_16.4 [template = constants.%tuple]
  221. // CHECK:STDOUT: return %.loc16_17 to %return
  222. // CHECK:STDOUT: }
  223. // CHECK:STDOUT: