raw_ir.carbon 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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: 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/check/testdata/basics/no_prelude/raw_ir.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/basics/no_prelude/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<invalid>, is_export: false}
  22. // CHECK:STDOUT: import_ir_insts: {}
  23. // CHECK:STDOUT: name_scopes:
  24. // CHECK:STDOUT: name_scope0: {inst: inst+0, parent_scope: name_scope<invalid>, has_error: false, extended_scopes: [], names: {name0: inst+16}}
  25. // CHECK:STDOUT: bind_names:
  26. // CHECK:STDOUT: bind_name0: {name: name1, parent_scope: name_scope<invalid>, index: comp_time_bind0}
  27. // CHECK:STDOUT: bind_name1: {name: name2, parent_scope: name_scope<invalid>, index: comp_time_bind<invalid>}
  28. // CHECK:STDOUT: functions:
  29. // CHECK:STDOUT: function0: {name: name0, parent_scope: name_scope0, param_refs: block5, return_storage: inst+15, return_slot: present, body: [block11]}
  30. // CHECK:STDOUT: classes: {}
  31. // CHECK:STDOUT: generics:
  32. // CHECK:STDOUT: generic0: {decl: inst+16, bindings: block8}
  33. // CHECK:STDOUT: generic_instances:
  34. // CHECK:STDOUT: genericInstance0: {generic: generic0, args: block10}
  35. // CHECK:STDOUT: types:
  36. // CHECK:STDOUT: type0: {constant: template instNamespaceType, value_rep: {kind: copy, type: type0}}
  37. // CHECK:STDOUT: type1: {constant: symbolic 0, value_rep: {kind: copy, type: type1}}
  38. // CHECK:STDOUT: type2: {constant: template inst+8, value_rep: {kind: none, type: type2}}
  39. // CHECK:STDOUT: type3: {constant: template inst+10, value_rep: {kind: unknown, type: type<invalid>}}
  40. // CHECK:STDOUT: type4: {constant: symbolic 1, value_rep: {kind: pointer, type: type8}}
  41. // CHECK:STDOUT: type5: {constant: symbolic 2, value_rep: {kind: copy, type: type5}}
  42. // CHECK:STDOUT: type6: {constant: symbolic 3, value_rep: {kind: unknown, type: type<invalid>}}
  43. // CHECK:STDOUT: type7: {constant: template inst+17, value_rep: {kind: none, type: type2}}
  44. // CHECK:STDOUT: type8: {constant: symbolic 4, value_rep: {kind: copy, type: type8}}
  45. // CHECK:STDOUT: type_blocks:
  46. // CHECK:STDOUT: type_block0: {}
  47. // CHECK:STDOUT: type_block1:
  48. // CHECK:STDOUT: 0: typeTypeType
  49. // CHECK:STDOUT: 1: type2
  50. // CHECK:STDOUT: type_block2:
  51. // CHECK:STDOUT: 0: type1
  52. // CHECK:STDOUT: 1: type2
  53. // CHECK:STDOUT: insts:
  54. // CHECK:STDOUT: 'inst+0': {kind: Namespace, arg0: name_scope0, arg1: inst<invalid>, type: type0}
  55. // CHECK:STDOUT: 'inst+1': {kind: Param, arg0: name1, type: typeTypeType}
  56. // CHECK:STDOUT: 'inst+2': {kind: BindSymbolicName, arg0: bind_name0, arg1: inst+1, type: typeTypeType}
  57. // CHECK:STDOUT: 'inst+3': {kind: BindSymbolicName, arg0: bind_name0, arg1: inst<invalid>, type: typeTypeType}
  58. // CHECK:STDOUT: 'inst+4': {kind: NameRef, arg0: name1, arg1: inst+2, type: typeTypeType}
  59. // CHECK:STDOUT: 'inst+5': {kind: Param, arg0: name2, type: type5}
  60. // CHECK:STDOUT: 'inst+6': {kind: BindName, arg0: bind_name1, arg1: inst+5, type: type5}
  61. // CHECK:STDOUT: 'inst+7': {kind: NameRef, arg0: name1, arg1: inst+2, type: typeTypeType}
  62. // CHECK:STDOUT: 'inst+8': {kind: TupleType, arg0: type_block0, type: typeTypeType}
  63. // CHECK:STDOUT: 'inst+9': {kind: TupleLiteral, arg0: empty, type: type2}
  64. // CHECK:STDOUT: 'inst+10': {kind: TupleType, arg0: type_block1, type: typeTypeType}
  65. // CHECK:STDOUT: 'inst+11': {kind: TupleLiteral, arg0: block6, type: type3}
  66. // CHECK:STDOUT: 'inst+12': {kind: Converted, arg0: inst+9, arg1: inst+8, type: typeTypeType}
  67. // CHECK:STDOUT: 'inst+13': {kind: TupleType, arg0: type_block2, type: typeTypeType}
  68. // CHECK:STDOUT: 'inst+14': {kind: Converted, arg0: inst+11, arg1: inst+13, type: typeTypeType}
  69. // CHECK:STDOUT: 'inst+15': {kind: VarStorage, arg0: nameReturnSlot, type: type4}
  70. // CHECK:STDOUT: 'inst+16': {kind: FunctionDecl, arg0: function0, arg1: block7, type: type7}
  71. // CHECK:STDOUT: 'inst+17': {kind: FunctionType, arg0: function0, type: typeTypeType}
  72. // CHECK:STDOUT: 'inst+18': {kind: StructValue, arg0: empty, type: type7}
  73. // CHECK:STDOUT: 'inst+19': {kind: PointerType, arg0: type4, type: typeTypeType}
  74. // CHECK:STDOUT: 'inst+20': {kind: NameRef, arg0: name2, arg1: inst+6, type: type1}
  75. // CHECK:STDOUT: 'inst+21': {kind: TupleLiteral, arg0: empty, type: type2}
  76. // CHECK:STDOUT: 'inst+22': {kind: TupleLiteral, arg0: block12, type: type4}
  77. // CHECK:STDOUT: 'inst+23': {kind: TupleAccess, arg0: inst+15, arg1: element0, type: type1}
  78. // CHECK:STDOUT: 'inst+24': {kind: InitializeFrom, arg0: inst+20, arg1: inst+23, type: type1}
  79. // CHECK:STDOUT: 'inst+25': {kind: TupleAccess, arg0: inst+15, arg1: element1, type: type2}
  80. // CHECK:STDOUT: 'inst+26': {kind: TupleInit, arg0: empty, arg1: inst+25, type: type2}
  81. // CHECK:STDOUT: 'inst+27': {kind: TupleValue, arg0: block14, type: type2}
  82. // CHECK:STDOUT: 'inst+28': {kind: Converted, arg0: inst+21, arg1: inst+26, type: type2}
  83. // CHECK:STDOUT: 'inst+29': {kind: TupleInit, arg0: block13, arg1: inst+15, type: type4}
  84. // CHECK:STDOUT: 'inst+30': {kind: Converted, arg0: inst+22, arg1: inst+29, type: type4}
  85. // CHECK:STDOUT: 'inst+31': {kind: ReturnExpr, arg0: inst+30, arg1: inst+15}
  86. // CHECK:STDOUT: constant_values:
  87. // CHECK:STDOUT: 'inst+0': template inst+0
  88. // CHECK:STDOUT: 'inst+2': symbolic 2
  89. // CHECK:STDOUT: 'inst+3': symbolic 0
  90. // CHECK:STDOUT: 'inst+4': symbolic 2
  91. // CHECK:STDOUT: 'inst+7': symbolic 2
  92. // CHECK:STDOUT: 'inst+8': template inst+8
  93. // CHECK:STDOUT: 'inst+10': template inst+10
  94. // CHECK:STDOUT: 'inst+12': template inst+8
  95. // CHECK:STDOUT: 'inst+13': symbolic 1
  96. // CHECK:STDOUT: 'inst+14': symbolic 3
  97. // CHECK:STDOUT: 'inst+16': template inst+18
  98. // CHECK:STDOUT: 'inst+17': template inst+17
  99. // CHECK:STDOUT: 'inst+18': template inst+18
  100. // CHECK:STDOUT: 'inst+19': symbolic 4
  101. // CHECK:STDOUT: 'inst+26': template inst+27
  102. // CHECK:STDOUT: 'inst+27': template inst+27
  103. // CHECK:STDOUT: 'inst+28': template inst+27
  104. // CHECK:STDOUT: inst_blocks:
  105. // CHECK:STDOUT: empty: {}
  106. // CHECK:STDOUT: exports:
  107. // CHECK:STDOUT: 0: inst+16
  108. // CHECK:STDOUT: import_refs: {}
  109. // CHECK:STDOUT: global_init: {}
  110. // CHECK:STDOUT: block4:
  111. // CHECK:STDOUT: 0: inst+2
  112. // CHECK:STDOUT: block5:
  113. // CHECK:STDOUT: 0: inst+6
  114. // CHECK:STDOUT: block6:
  115. // CHECK:STDOUT: 0: inst+7
  116. // CHECK:STDOUT: 1: inst+9
  117. // CHECK:STDOUT: block7:
  118. // CHECK:STDOUT: 0: inst+1
  119. // CHECK:STDOUT: 1: inst+2
  120. // CHECK:STDOUT: 2: inst+4
  121. // CHECK:STDOUT: 3: inst+5
  122. // CHECK:STDOUT: 4: inst+6
  123. // CHECK:STDOUT: 5: inst+7
  124. // CHECK:STDOUT: 6: inst+9
  125. // CHECK:STDOUT: 7: inst+11
  126. // CHECK:STDOUT: 8: inst+12
  127. // CHECK:STDOUT: 9: inst+14
  128. // CHECK:STDOUT: 10: inst+15
  129. // CHECK:STDOUT: block8:
  130. // CHECK:STDOUT: 0: inst+2
  131. // CHECK:STDOUT: block9:
  132. // CHECK:STDOUT: 0: inst+2
  133. // CHECK:STDOUT: 1: inst+14
  134. // CHECK:STDOUT: block10:
  135. // CHECK:STDOUT: 0: inst+3
  136. // CHECK:STDOUT: block11:
  137. // CHECK:STDOUT: 0: inst+20
  138. // CHECK:STDOUT: 1: inst+21
  139. // CHECK:STDOUT: 2: inst+22
  140. // CHECK:STDOUT: 3: inst+23
  141. // CHECK:STDOUT: 4: inst+24
  142. // CHECK:STDOUT: 5: inst+25
  143. // CHECK:STDOUT: 6: inst+26
  144. // CHECK:STDOUT: 7: inst+28
  145. // CHECK:STDOUT: 8: inst+29
  146. // CHECK:STDOUT: 9: inst+30
  147. // CHECK:STDOUT: 10: inst+31
  148. // CHECK:STDOUT: block12:
  149. // CHECK:STDOUT: 0: inst+20
  150. // CHECK:STDOUT: 1: inst+21
  151. // CHECK:STDOUT: block13:
  152. // CHECK:STDOUT: 0: inst+24
  153. // CHECK:STDOUT: 1: inst+28
  154. // CHECK:STDOUT: block14: {}
  155. // CHECK:STDOUT: block15:
  156. // CHECK:STDOUT: 0: inst+0
  157. // CHECK:STDOUT: 1: inst+16
  158. // CHECK:STDOUT: ...