raw_ir.carbon 15 KB

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