raw_ir.carbon 15 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-raw-sem-ir %s
  6. //
  7. // Check that raw IR dumping works as expected.
  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_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_ir.carbon
  14. fn Foo[T:! type](n: T) -> (T, ()) {
  15. return (n, ());
  16. }
  17. // CHECK:STDOUT: ---
  18. // CHECK:STDOUT: filename: raw_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: inst36}}
  25. // CHECK:STDOUT: entity_names:
  26. // CHECK:STDOUT: entity_name0: {name: name1, parent_scope: name_scope<none>, index: comp_time_bind0}
  27. // CHECK:STDOUT: entity_name1: {name: name2, parent_scope: name_scope<none>, index: comp_time_bind<none>}
  28. // CHECK:STDOUT: functions:
  29. // CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, return_slot_pattern: inst31, body: [inst_block16]}
  30. // CHECK:STDOUT: classes: {}
  31. // CHECK:STDOUT: generics:
  32. // CHECK:STDOUT: generic0: {decl: inst36, bindings: inst_block12}
  33. // CHECK:STDOUT: specifics:
  34. // CHECK:STDOUT: specific0: {generic: generic0, args: inst_block13}
  35. // CHECK:STDOUT: struct_type_fields:
  36. // CHECK:STDOUT: struct_type_fields0: {}
  37. // CHECK:STDOUT: types:
  38. // CHECK:STDOUT: 'type(TypeType)': {kind: copy, type: type(TypeType)}
  39. // CHECK:STDOUT: 'type(Error)': {kind: copy, type: type(Error)}
  40. // CHECK:STDOUT: 'type(inst(NamespaceType))': {kind: copy, type: type(inst(NamespaceType))}
  41. // CHECK:STDOUT: 'type(inst40)': {kind: none, type: type(inst23)}
  42. // CHECK:STDOUT: 'type(inst23)': {kind: none, type: type(inst23)}
  43. // CHECK:STDOUT: 'type(symbolic_constant0)': {kind: copy, type: type(symbolic_constant0)}
  44. // CHECK:STDOUT: 'type(symbolic_constant2)': {kind: pointer, type: type(symbolic_constant6)}
  45. // CHECK:STDOUT: 'type(symbolic_constant6)': {kind: copy, type: type(symbolic_constant6)}
  46. // CHECK:STDOUT: 'type(inst(WitnessType))': {kind: copy, type: type(inst(WitnessType))}
  47. // CHECK:STDOUT: 'type(symbolic_constant3)': {kind: copy, type: type(symbolic_constant3)}
  48. // CHECK:STDOUT: 'type(symbolic_constant5)': {kind: pointer, type: type(symbolic_constant6)}
  49. // CHECK:STDOUT: type_blocks:
  50. // CHECK:STDOUT: type_block0: {}
  51. // CHECK:STDOUT: type_block1:
  52. // CHECK:STDOUT: 0: type(TypeType)
  53. // CHECK:STDOUT: 1: type(inst23)
  54. // CHECK:STDOUT: type_block2:
  55. // CHECK:STDOUT: 0: type(symbolic_constant0)
  56. // CHECK:STDOUT: 1: type(inst23)
  57. // CHECK:STDOUT: type_block3:
  58. // CHECK:STDOUT: 0: type(symbolic_constant3)
  59. // CHECK:STDOUT: 1: type(inst23)
  60. // CHECK:STDOUT: insts:
  61. // CHECK:STDOUT: inst12: {kind: Namespace, arg0: name_scope0, arg1: inst<none>, type: type(inst(NamespaceType))}
  62. // CHECK:STDOUT: inst13: {kind: BindSymbolicName, arg0: entity_name0, arg1: inst32, type: type(TypeType)}
  63. // CHECK:STDOUT: inst14: {kind: BindSymbolicName, arg0: entity_name0, arg1: inst<none>, type: type(TypeType)}
  64. // CHECK:STDOUT: inst15: {kind: SymbolicBindingPattern, arg0: entity_name0, type: type(TypeType)}
  65. // CHECK:STDOUT: inst16: {kind: SymbolicBindingPattern, arg0: entity_name0, type: type(TypeType)}
  66. // CHECK:STDOUT: inst17: {kind: ValueParamPattern, arg0: inst15, arg1: runtime_param<none>, type: type(TypeType)}
  67. // CHECK:STDOUT: inst18: {kind: NameRef, arg0: name1, arg1: inst13, type: type(TypeType)}
  68. // CHECK:STDOUT: inst19: {kind: BindName, arg0: entity_name1, arg1: inst33, type: type(symbolic_constant3)}
  69. // CHECK:STDOUT: inst20: {kind: BindingPattern, arg0: entity_name1, type: type(symbolic_constant3)}
  70. // CHECK:STDOUT: inst21: {kind: ValueParamPattern, arg0: inst20, arg1: runtime_param0, type: type(symbolic_constant3)}
  71. // CHECK:STDOUT: inst22: {kind: NameRef, arg0: name1, arg1: inst13, type: type(TypeType)}
  72. // CHECK:STDOUT: inst23: {kind: TupleType, arg0: type_block0, type: type(TypeType)}
  73. // CHECK:STDOUT: inst24: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst23)}
  74. // CHECK:STDOUT: inst25: {kind: TupleType, arg0: type_block1, type: type(TypeType)}
  75. // CHECK:STDOUT: inst26: {kind: TupleLiteral, arg0: inst_block8, type: type(inst25)}
  76. // CHECK:STDOUT: inst27: {kind: Converted, arg0: inst24, arg1: inst23, type: type(TypeType)}
  77. // CHECK:STDOUT: inst28: {kind: TupleType, arg0: type_block2, type: type(TypeType)}
  78. // CHECK:STDOUT: inst29: {kind: Converted, arg0: inst26, arg1: inst28, type: type(TypeType)}
  79. // CHECK:STDOUT: inst30: {kind: ReturnSlotPattern, arg0: inst26, type: type(symbolic_constant5)}
  80. // CHECK:STDOUT: inst31: {kind: OutParamPattern, arg0: inst30, arg1: runtime_param1, type: type(symbolic_constant5)}
  81. // CHECK:STDOUT: inst32: {kind: ValueParam, arg0: runtime_param<none>, arg1: name1, type: type(TypeType)}
  82. // CHECK:STDOUT: inst33: {kind: ValueParam, arg0: runtime_param0, arg1: name2, type: type(symbolic_constant3)}
  83. // CHECK:STDOUT: inst34: {kind: OutParam, arg0: runtime_param1, arg1: name(ReturnSlot), type: type(symbolic_constant5)}
  84. // CHECK:STDOUT: inst35: {kind: ReturnSlot, arg0: inst26, arg1: inst34, type: type(symbolic_constant5)}
  85. // CHECK:STDOUT: inst36: {kind: FunctionDecl, arg0: function0, arg1: inst_block11, type: type(inst40)}
  86. // CHECK:STDOUT: inst37: {kind: BindSymbolicName, arg0: entity_name0, arg1: inst<none>, type: type(TypeType)}
  87. // CHECK:STDOUT: inst38: {kind: SymbolicBindingPattern, arg0: entity_name0, type: type(TypeType)}
  88. // CHECK:STDOUT: inst39: {kind: TupleType, arg0: type_block3, type: type(TypeType)}
  89. // CHECK:STDOUT: inst40: {kind: FunctionType, arg0: function0, arg1: specific<none>, type: type(TypeType)}
  90. // CHECK:STDOUT: inst41: {kind: StructValue, arg0: inst_block_empty, type: type(inst40)}
  91. // CHECK:STDOUT: inst42: {kind: PointerType, arg0: type(symbolic_constant2), type: type(TypeType)}
  92. // CHECK:STDOUT: inst43: {kind: RequireCompleteType, arg0: type(symbolic_constant2), type: type(inst(WitnessType))}
  93. // CHECK:STDOUT: inst44: {kind: RequireCompleteType, arg0: type(symbolic_constant2), type: type(inst(WitnessType))}
  94. // CHECK:STDOUT: inst45: {kind: RequireCompleteType, arg0: type(symbolic_constant3), type: type(inst(WitnessType))}
  95. // CHECK:STDOUT: inst46: {kind: RequireCompleteType, arg0: type(symbolic_constant0), type: type(inst(WitnessType))}
  96. // CHECK:STDOUT: inst47: {kind: NameRef, arg0: name2, arg1: inst19, type: type(symbolic_constant3)}
  97. // CHECK:STDOUT: inst48: {kind: TupleLiteral, arg0: inst_block_empty, type: type(inst23)}
  98. // CHECK:STDOUT: inst49: {kind: TupleLiteral, arg0: inst_block17, type: type(symbolic_constant5)}
  99. // CHECK:STDOUT: inst50: {kind: RequireCompleteType, arg0: type(symbolic_constant5), type: type(inst(WitnessType))}
  100. // CHECK:STDOUT: inst51: {kind: TupleAccess, arg0: inst35, arg1: element0, type: type(symbolic_constant3)}
  101. // CHECK:STDOUT: inst52: {kind: RequireCompleteType, arg0: type(symbolic_constant0), type: type(inst(WitnessType))}
  102. // CHECK:STDOUT: inst53: {kind: InitializeFrom, arg0: inst47, arg1: inst51, type: type(symbolic_constant3)}
  103. // CHECK:STDOUT: inst54: {kind: TupleAccess, arg0: inst35, arg1: element1, type: type(inst23)}
  104. // CHECK:STDOUT: inst55: {kind: TupleInit, arg0: inst_block_empty, arg1: inst54, type: type(inst23)}
  105. // CHECK:STDOUT: inst56: {kind: TupleValue, arg0: inst_block_empty, type: type(inst23)}
  106. // CHECK:STDOUT: inst57: {kind: Converted, arg0: inst48, arg1: inst55, type: type(inst23)}
  107. // CHECK:STDOUT: inst58: {kind: TupleInit, arg0: inst_block18, arg1: inst35, type: type(symbolic_constant5)}
  108. // CHECK:STDOUT: inst59: {kind: Converted, arg0: inst49, arg1: inst58, type: type(symbolic_constant5)}
  109. // CHECK:STDOUT: inst60: {kind: ReturnExpr, arg0: inst59, arg1: inst35}
  110. // CHECK:STDOUT: inst61: {kind: RequireCompleteType, arg0: type(symbolic_constant5), type: type(inst(WitnessType))}
  111. // CHECK:STDOUT: inst62: {kind: RequireCompleteType, arg0: type(symbolic_constant3), type: type(inst(WitnessType))}
  112. // CHECK:STDOUT: constant_values:
  113. // CHECK:STDOUT: inst12: template_constant(inst12)
  114. // CHECK:STDOUT: inst13: symbolic_constant3
  115. // CHECK:STDOUT: inst14: symbolic_constant0
  116. // CHECK:STDOUT: inst15: symbolic_constant4
  117. // CHECK:STDOUT: inst16: symbolic_constant1
  118. // CHECK:STDOUT: inst17: symbolic_constant4
  119. // CHECK:STDOUT: inst18: symbolic_constant3
  120. // CHECK:STDOUT: inst22: symbolic_constant3
  121. // CHECK:STDOUT: inst23: template_constant(inst23)
  122. // CHECK:STDOUT: inst25: template_constant(inst25)
  123. // CHECK:STDOUT: inst27: template_constant(inst23)
  124. // CHECK:STDOUT: inst28: symbolic_constant2
  125. // CHECK:STDOUT: inst29: symbolic_constant5
  126. // CHECK:STDOUT: inst36: template_constant(inst41)
  127. // CHECK:STDOUT: inst37: symbolic_constant3
  128. // CHECK:STDOUT: inst38: symbolic_constant4
  129. // CHECK:STDOUT: inst39: symbolic_constant5
  130. // CHECK:STDOUT: inst40: template_constant(inst40)
  131. // CHECK:STDOUT: inst41: template_constant(inst41)
  132. // CHECK:STDOUT: inst42: symbolic_constant6
  133. // CHECK:STDOUT: inst43: symbolic_constant9
  134. // CHECK:STDOUT: inst44: symbolic_constant7
  135. // CHECK:STDOUT: inst45: symbolic_constant10
  136. // CHECK:STDOUT: inst46: symbolic_constant8
  137. // CHECK:STDOUT: inst50: symbolic_constant9
  138. // CHECK:STDOUT: inst52: symbolic_constant10
  139. // CHECK:STDOUT: inst55: template_constant(inst56)
  140. // CHECK:STDOUT: inst56: template_constant(inst56)
  141. // CHECK:STDOUT: inst57: template_constant(inst56)
  142. // CHECK:STDOUT: inst61: symbolic_constant9
  143. // CHECK:STDOUT: inst62: symbolic_constant10
  144. // CHECK:STDOUT: symbolic_constants:
  145. // CHECK:STDOUT: symbolic_constant0: {inst: inst14, generic: generic<none>, index: generic_inst<none>, .Self: false}
  146. // CHECK:STDOUT: symbolic_constant1: {inst: inst16, generic: generic<none>, index: generic_inst<none>, .Self: false}
  147. // CHECK:STDOUT: symbolic_constant2: {inst: inst28, generic: generic<none>, index: generic_inst<none>, .Self: false}
  148. // CHECK:STDOUT: symbolic_constant3: {inst: inst14, generic: generic0, index: generic_inst_in_decl0, .Self: false}
  149. // CHECK:STDOUT: symbolic_constant4: {inst: inst16, generic: generic0, index: generic_inst_in_decl1, .Self: false}
  150. // CHECK:STDOUT: symbolic_constant5: {inst: inst28, generic: generic0, index: generic_inst_in_decl2, .Self: false}
  151. // CHECK:STDOUT: symbolic_constant6: {inst: inst42, generic: generic<none>, index: generic_inst<none>, .Self: false}
  152. // CHECK:STDOUT: symbolic_constant7: {inst: inst44, generic: generic<none>, index: generic_inst<none>, .Self: false}
  153. // CHECK:STDOUT: symbolic_constant8: {inst: inst46, generic: generic<none>, index: generic_inst<none>, .Self: false}
  154. // CHECK:STDOUT: symbolic_constant9: {inst: inst44, generic: generic0, index: generic_inst_in_def0, .Self: false}
  155. // CHECK:STDOUT: symbolic_constant10: {inst: inst46, generic: generic0, index: generic_inst_in_def1, .Self: false}
  156. // CHECK:STDOUT: inst_blocks:
  157. // CHECK:STDOUT: inst_block_empty: {}
  158. // CHECK:STDOUT: exports:
  159. // CHECK:STDOUT: 0: inst36
  160. // CHECK:STDOUT: import_refs: {}
  161. // CHECK:STDOUT: global_init: {}
  162. // CHECK:STDOUT: inst_block4: {}
  163. // CHECK:STDOUT: inst_block5:
  164. // CHECK:STDOUT: 0: inst17
  165. // CHECK:STDOUT: inst_block6:
  166. // CHECK:STDOUT: 0: inst18
  167. // CHECK:STDOUT: inst_block7:
  168. // CHECK:STDOUT: 0: inst21
  169. // CHECK:STDOUT: inst_block8:
  170. // CHECK:STDOUT: 0: inst22
  171. // CHECK:STDOUT: 1: inst24
  172. // CHECK:STDOUT: inst_block9:
  173. // CHECK:STDOUT: 0: inst33
  174. // CHECK:STDOUT: 1: inst34
  175. // CHECK:STDOUT: inst_block10:
  176. // CHECK:STDOUT: 0: inst15
  177. // CHECK:STDOUT: 1: inst17
  178. // CHECK:STDOUT: 2: inst20
  179. // CHECK:STDOUT: 3: inst21
  180. // CHECK:STDOUT: 4: inst30
  181. // CHECK:STDOUT: 5: inst31
  182. // CHECK:STDOUT: inst_block11:
  183. // CHECK:STDOUT: 0: inst22
  184. // CHECK:STDOUT: 1: inst24
  185. // CHECK:STDOUT: 2: inst26
  186. // CHECK:STDOUT: 3: inst27
  187. // CHECK:STDOUT: 4: inst29
  188. // CHECK:STDOUT: 5: inst32
  189. // CHECK:STDOUT: 6: inst13
  190. // CHECK:STDOUT: 7: inst33
  191. // CHECK:STDOUT: 8: inst18
  192. // CHECK:STDOUT: 9: inst19
  193. // CHECK:STDOUT: 10: inst34
  194. // CHECK:STDOUT: 11: inst35
  195. // CHECK:STDOUT: inst_block12:
  196. // CHECK:STDOUT: 0: inst13
  197. // CHECK:STDOUT: inst_block13:
  198. // CHECK:STDOUT: 0: inst14
  199. // CHECK:STDOUT: inst_block14:
  200. // CHECK:STDOUT: 0: inst37
  201. // CHECK:STDOUT: 1: inst38
  202. // CHECK:STDOUT: 2: inst39
  203. // CHECK:STDOUT: inst_block15:
  204. // CHECK:STDOUT: 0: inst14
  205. // CHECK:STDOUT: 1: inst14
  206. // CHECK:STDOUT: 2: inst28
  207. // CHECK:STDOUT: inst_block16:
  208. // CHECK:STDOUT: 0: inst47
  209. // CHECK:STDOUT: 1: inst48
  210. // CHECK:STDOUT: 2: inst49
  211. // CHECK:STDOUT: 3: inst51
  212. // CHECK:STDOUT: 4: inst53
  213. // CHECK:STDOUT: 5: inst54
  214. // CHECK:STDOUT: 6: inst55
  215. // CHECK:STDOUT: 7: inst57
  216. // CHECK:STDOUT: 8: inst58
  217. // CHECK:STDOUT: 9: inst59
  218. // CHECK:STDOUT: 10: inst60
  219. // CHECK:STDOUT: inst_block17:
  220. // CHECK:STDOUT: 0: inst47
  221. // CHECK:STDOUT: 1: inst48
  222. // CHECK:STDOUT: inst_block18:
  223. // CHECK:STDOUT: 0: inst53
  224. // CHECK:STDOUT: 1: inst57
  225. // CHECK:STDOUT: inst_block19:
  226. // CHECK:STDOUT: 0: inst61
  227. // CHECK:STDOUT: 1: inst62
  228. // CHECK:STDOUT: inst_block20:
  229. // CHECK:STDOUT: 0: inst12
  230. // CHECK:STDOUT: 1: inst36
  231. // CHECK:STDOUT: ...