import.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // AUTOUPDATE
  6. // --- implicit.carbon
  7. package Implicit api;
  8. var a_ref: (i32,) = (0,);
  9. var b_ref: (((i32,), i32), (i32, i32)) = (((0,), 1), (2, 3));
  10. // --- implicit.impl.carbon
  11. package Implicit impl;
  12. var a: (i32,) = a_ref;
  13. var b: (((i32,), i32), (i32, i32)) = b_ref;
  14. // CHECK:STDOUT: --- implicit.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %.1: type = tuple_type (type) [template]
  18. // CHECK:STDOUT: %.2: type = tuple_type (i32) [template]
  19. // CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
  20. // CHECK:STDOUT: %.4: (i32,) = tuple_value (%.3) [template]
  21. // CHECK:STDOUT: %.5: type = tuple_type ((type,), type) [template]
  22. // CHECK:STDOUT: %.6: type = tuple_type (type, type) [template]
  23. // CHECK:STDOUT: %.7: type = tuple_type (((type,), type), (type, type)) [template]
  24. // CHECK:STDOUT: %.8: type = tuple_type ((i32,), i32) [template]
  25. // CHECK:STDOUT: %.9: type = tuple_type (i32, i32) [template]
  26. // CHECK:STDOUT: %.10: type = tuple_type (((i32,), i32), (i32, i32)) [template]
  27. // CHECK:STDOUT: %.11: type = ptr_type (i32, i32) [template]
  28. // CHECK:STDOUT: %.12: type = ptr_type ((i32,), i32) [template]
  29. // CHECK:STDOUT: %.13: type = tuple_type (((i32,), i32)*, (i32, i32)*) [template]
  30. // CHECK:STDOUT: %.14: type = ptr_type (((i32,), i32)*, (i32, i32)*) [template]
  31. // CHECK:STDOUT: %.15: i32 = int_literal 1 [template]
  32. // CHECK:STDOUT: %.16: i32 = int_literal 2 [template]
  33. // CHECK:STDOUT: %.17: i32 = int_literal 3 [template]
  34. // CHECK:STDOUT: %.18: ((i32,), i32) = tuple_value (%.4, %.15) [template]
  35. // CHECK:STDOUT: %.19: (i32, i32) = tuple_value (%.16, %.17) [template]
  36. // CHECK:STDOUT: %.20: (((i32,), i32), (i32, i32)) = tuple_value (%.18, %.19) [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .a_ref = %a_ref
  42. // CHECK:STDOUT: .b_ref = %b_ref
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %.loc4_17.1: (type,) = tuple_literal (i32)
  45. // CHECK:STDOUT: %.loc4_17.2: type = converted %.loc4_17.1, constants.%.2 [template = constants.%.2]
  46. // CHECK:STDOUT: %a_ref.var: ref (i32,) = var a_ref
  47. // CHECK:STDOUT: %a_ref: ref (i32,) = bind_name a_ref, %a_ref.var
  48. // CHECK:STDOUT: %.loc5_19.1: (type,) = tuple_literal (i32)
  49. // CHECK:STDOUT: %.loc5_25.1: ((type,), type) = tuple_literal (%.loc5_19.1, i32)
  50. // CHECK:STDOUT: %.loc5_37.1: (type, type) = tuple_literal (i32, i32)
  51. // CHECK:STDOUT: %.loc5_38.1: (((type,), type), (type, type)) = tuple_literal (%.loc5_25.1, %.loc5_37.1)
  52. // CHECK:STDOUT: %.loc5_19.2: type = converted %.loc5_19.1, constants.%.2 [template = constants.%.2]
  53. // CHECK:STDOUT: %.loc5_25.2: type = converted %.loc5_25.1, constants.%.8 [template = constants.%.8]
  54. // CHECK:STDOUT: %.loc5_37.2: type = converted %.loc5_37.1, constants.%.9 [template = constants.%.9]
  55. // CHECK:STDOUT: %.loc5_38.2: type = converted %.loc5_38.1, constants.%.10 [template = constants.%.10]
  56. // CHECK:STDOUT: %b_ref.var: ref (((i32,), i32), (i32, i32)) = var b_ref
  57. // CHECK:STDOUT: %b_ref: ref (((i32,), i32), (i32, i32)) = bind_name b_ref, %b_ref.var
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @__global_init() {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: %.loc4_22: i32 = int_literal 0 [template = constants.%.3]
  63. // CHECK:STDOUT: %.loc4_24.1: (i32,) = tuple_literal (%.loc4_22)
  64. // CHECK:STDOUT: %.loc4_24.2: init (i32,) = tuple_init (%.loc4_22) to file.%a_ref.var [template = constants.%.4]
  65. // CHECK:STDOUT: %.loc4_24.3: init (i32,) = converted %.loc4_24.1, %.loc4_24.2 [template = constants.%.4]
  66. // CHECK:STDOUT: assign file.%a_ref.var, %.loc4_24.3
  67. // CHECK:STDOUT: %.loc5_45: i32 = int_literal 0 [template = constants.%.3]
  68. // CHECK:STDOUT: %.loc5_47.1: (i32,) = tuple_literal (%.loc5_45)
  69. // CHECK:STDOUT: %.loc5_50: i32 = int_literal 1 [template = constants.%.15]
  70. // CHECK:STDOUT: %.loc5_51.1: ((i32,), i32) = tuple_literal (%.loc5_47.1, %.loc5_50)
  71. // CHECK:STDOUT: %.loc5_55: i32 = int_literal 2 [template = constants.%.16]
  72. // CHECK:STDOUT: %.loc5_58: i32 = int_literal 3 [template = constants.%.17]
  73. // CHECK:STDOUT: %.loc5_59.1: (i32, i32) = tuple_literal (%.loc5_55, %.loc5_58)
  74. // CHECK:STDOUT: %.loc5_60.1: (((i32,), i32), (i32, i32)) = tuple_literal (%.loc5_51.1, %.loc5_59.1)
  75. // CHECK:STDOUT: %.loc5_60.2: ref ((i32,), i32) = tuple_access file.%b_ref.var, element0
  76. // CHECK:STDOUT: %.loc5_51.2: ref (i32,) = tuple_access %.loc5_60.2, element0
  77. // CHECK:STDOUT: %.loc5_47.2: init (i32,) = tuple_init (%.loc5_45) to %.loc5_51.2 [template = constants.%.4]
  78. // CHECK:STDOUT: %.loc5_47.3: init (i32,) = converted %.loc5_47.1, %.loc5_47.2 [template = constants.%.4]
  79. // CHECK:STDOUT: %.loc5_51.3: init (i32,) = initialize_from %.loc5_47.3 to %.loc5_51.2 [template = constants.%.4]
  80. // CHECK:STDOUT: %.loc5_51.4: ref i32 = tuple_access %.loc5_60.2, element1
  81. // CHECK:STDOUT: %.loc5_51.5: init i32 = initialize_from %.loc5_50 to %.loc5_51.4 [template = constants.%.15]
  82. // CHECK:STDOUT: %.loc5_51.6: init ((i32,), i32) = tuple_init (%.loc5_51.3, %.loc5_51.5) to %.loc5_60.2 [template = constants.%.18]
  83. // CHECK:STDOUT: %.loc5_51.7: init ((i32,), i32) = converted %.loc5_51.1, %.loc5_51.6 [template = constants.%.18]
  84. // CHECK:STDOUT: %.loc5_60.3: ref (i32, i32) = tuple_access file.%b_ref.var, element1
  85. // CHECK:STDOUT: %.loc5_59.2: ref i32 = tuple_access %.loc5_60.3, element0
  86. // CHECK:STDOUT: %.loc5_59.3: init i32 = initialize_from %.loc5_55 to %.loc5_59.2 [template = constants.%.16]
  87. // CHECK:STDOUT: %.loc5_59.4: ref i32 = tuple_access %.loc5_60.3, element1
  88. // CHECK:STDOUT: %.loc5_59.5: init i32 = initialize_from %.loc5_58 to %.loc5_59.4 [template = constants.%.17]
  89. // CHECK:STDOUT: %.loc5_59.6: init (i32, i32) = tuple_init (%.loc5_59.3, %.loc5_59.5) to %.loc5_60.3 [template = constants.%.19]
  90. // CHECK:STDOUT: %.loc5_59.7: init (i32, i32) = converted %.loc5_59.1, %.loc5_59.6 [template = constants.%.19]
  91. // CHECK:STDOUT: %.loc5_60.4: init (((i32,), i32), (i32, i32)) = tuple_init (%.loc5_51.7, %.loc5_59.7) to file.%b_ref.var [template = constants.%.20]
  92. // CHECK:STDOUT: %.loc5_60.5: init (((i32,), i32), (i32, i32)) = converted %.loc5_60.1, %.loc5_60.4 [template = constants.%.20]
  93. // CHECK:STDOUT: assign file.%b_ref.var, %.loc5_60.5
  94. // CHECK:STDOUT: return
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: --- implicit.impl.carbon
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: constants {
  100. // CHECK:STDOUT: %.1: type = tuple_type (type) [template]
  101. // CHECK:STDOUT: %.2: type = tuple_type (i32) [template]
  102. // CHECK:STDOUT: %.3: type = tuple_type ((type,), type) [template]
  103. // CHECK:STDOUT: %.4: type = tuple_type (type, type) [template]
  104. // CHECK:STDOUT: %.5: type = tuple_type (((type,), type), (type, type)) [template]
  105. // CHECK:STDOUT: %.6: type = tuple_type ((i32,), i32) [template]
  106. // CHECK:STDOUT: %.7: type = tuple_type (i32, i32) [template]
  107. // CHECK:STDOUT: %.8: type = tuple_type (((i32,), i32), (i32, i32)) [template]
  108. // CHECK:STDOUT: %.9: type = ptr_type (i32, i32) [template]
  109. // CHECK:STDOUT: %.10: type = ptr_type ((i32,), i32) [template]
  110. // CHECK:STDOUT: %.11: type = tuple_type (((i32,), i32)*, (i32, i32)*) [template]
  111. // CHECK:STDOUT: %.12: type = ptr_type (((i32,), i32)*, (i32, i32)*) [template]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: file {
  115. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  116. // CHECK:STDOUT: .a_ref = %import_ref.1
  117. // CHECK:STDOUT: .b_ref = %import_ref.2
  118. // CHECK:STDOUT: .a = %a
  119. // CHECK:STDOUT: .b = %b
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %import_ref.1: ref (i32,) = import_ref ir1, inst+6, used
  122. // CHECK:STDOUT: %import_ref.2: ref (((i32,), i32), (i32, i32)) = import_ref ir1, inst+34, used
  123. // CHECK:STDOUT: %.loc4_13.1: (type,) = tuple_literal (i32)
  124. // CHECK:STDOUT: %.loc4_13.2: type = converted %.loc4_13.1, constants.%.2 [template = constants.%.2]
  125. // CHECK:STDOUT: %a.var: ref (i32,) = var a
  126. // CHECK:STDOUT: %a: ref (i32,) = bind_name a, %a.var
  127. // CHECK:STDOUT: %.loc5_15.1: (type,) = tuple_literal (i32)
  128. // CHECK:STDOUT: %.loc5_21.1: ((type,), type) = tuple_literal (%.loc5_15.1, i32)
  129. // CHECK:STDOUT: %.loc5_33.1: (type, type) = tuple_literal (i32, i32)
  130. // CHECK:STDOUT: %.loc5_34.1: (((type,), type), (type, type)) = tuple_literal (%.loc5_21.1, %.loc5_33.1)
  131. // CHECK:STDOUT: %.loc5_15.2: type = converted %.loc5_15.1, constants.%.2 [template = constants.%.2]
  132. // CHECK:STDOUT: %.loc5_21.2: type = converted %.loc5_21.1, constants.%.6 [template = constants.%.6]
  133. // CHECK:STDOUT: %.loc5_33.2: type = converted %.loc5_33.1, constants.%.7 [template = constants.%.7]
  134. // CHECK:STDOUT: %.loc5_34.2: type = converted %.loc5_34.1, constants.%.8 [template = constants.%.8]
  135. // CHECK:STDOUT: %b.var: ref (((i32,), i32), (i32, i32)) = var b
  136. // CHECK:STDOUT: %b: ref (((i32,), i32), (i32, i32)) = bind_name b, %b.var
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: fn @__global_init() {
  140. // CHECK:STDOUT: !entry:
  141. // CHECK:STDOUT: %a_ref.ref: ref (i32,) = name_ref a_ref, file.%import_ref.1
  142. // CHECK:STDOUT: %.loc4_17.1: ref i32 = tuple_access %a_ref.ref, element0
  143. // CHECK:STDOUT: %.loc4_17.2: i32 = bind_value %.loc4_17.1
  144. // CHECK:STDOUT: %.loc4_17.3: init (i32,) = tuple_init (%.loc4_17.2) to file.%a.var
  145. // CHECK:STDOUT: %.loc4_17.4: init (i32,) = converted %a_ref.ref, %.loc4_17.3
  146. // CHECK:STDOUT: assign file.%a.var, %.loc4_17.4
  147. // CHECK:STDOUT: %b_ref.ref: ref (((i32,), i32), (i32, i32)) = name_ref b_ref, file.%import_ref.2
  148. // CHECK:STDOUT: %.loc5_38.1: ref ((i32,), i32) = tuple_access %b_ref.ref, element0
  149. // CHECK:STDOUT: %.loc5_38.2: ref (i32,) = tuple_access %.loc5_38.1, element0
  150. // CHECK:STDOUT: %.loc5_38.3: ref i32 = tuple_access %.loc5_38.2, element0
  151. // CHECK:STDOUT: %.loc5_38.4: i32 = bind_value %.loc5_38.3
  152. // CHECK:STDOUT: %.loc5_38.5: ref ((i32,), i32) = tuple_access file.%b.var, element0
  153. // CHECK:STDOUT: %.loc5_38.6: ref (i32,) = tuple_access %.loc5_38.5, element0
  154. // CHECK:STDOUT: %.loc5_38.7: init (i32,) = tuple_init (%.loc5_38.4) to %.loc5_38.6
  155. // CHECK:STDOUT: %.loc5_38.8: init (i32,) = converted %.loc5_38.2, %.loc5_38.7
  156. // CHECK:STDOUT: %.loc5_38.9: init (i32,) = initialize_from %.loc5_38.8 to %.loc5_38.6
  157. // CHECK:STDOUT: %.loc5_38.10: ref i32 = tuple_access %.loc5_38.1, element1
  158. // CHECK:STDOUT: %.loc5_38.11: i32 = bind_value %.loc5_38.10
  159. // CHECK:STDOUT: %.loc5_38.12: ref i32 = tuple_access %.loc5_38.5, element1
  160. // CHECK:STDOUT: %.loc5_38.13: init i32 = initialize_from %.loc5_38.11 to %.loc5_38.12
  161. // CHECK:STDOUT: %.loc5_38.14: init ((i32,), i32) = tuple_init (%.loc5_38.9, %.loc5_38.13) to %.loc5_38.5
  162. // CHECK:STDOUT: %.loc5_38.15: init ((i32,), i32) = converted %.loc5_38.1, %.loc5_38.14
  163. // CHECK:STDOUT: %.loc5_38.16: ref (i32, i32) = tuple_access %b_ref.ref, element1
  164. // CHECK:STDOUT: %.loc5_38.17: ref i32 = tuple_access %.loc5_38.16, element0
  165. // CHECK:STDOUT: %.loc5_38.18: i32 = bind_value %.loc5_38.17
  166. // CHECK:STDOUT: %.loc5_38.19: ref (i32, i32) = tuple_access file.%b.var, element1
  167. // CHECK:STDOUT: %.loc5_38.20: ref i32 = tuple_access %.loc5_38.19, element0
  168. // CHECK:STDOUT: %.loc5_38.21: init i32 = initialize_from %.loc5_38.18 to %.loc5_38.20
  169. // CHECK:STDOUT: %.loc5_38.22: ref i32 = tuple_access %.loc5_38.16, element1
  170. // CHECK:STDOUT: %.loc5_38.23: i32 = bind_value %.loc5_38.22
  171. // CHECK:STDOUT: %.loc5_38.24: ref i32 = tuple_access %.loc5_38.19, element1
  172. // CHECK:STDOUT: %.loc5_38.25: init i32 = initialize_from %.loc5_38.23 to %.loc5_38.24
  173. // CHECK:STDOUT: %.loc5_38.26: init (i32, i32) = tuple_init (%.loc5_38.21, %.loc5_38.25) to %.loc5_38.19
  174. // CHECK:STDOUT: %.loc5_38.27: init (i32, i32) = converted %.loc5_38.16, %.loc5_38.26
  175. // CHECK:STDOUT: %.loc5_38.28: init (((i32,), i32), (i32, i32)) = tuple_init (%.loc5_38.15, %.loc5_38.27) to file.%b.var
  176. // CHECK:STDOUT: %.loc5_38.29: init (((i32,), i32), (i32, i32)) = converted %b_ref.ref, %.loc5_38.28
  177. // CHECK:STDOUT: assign file.%b.var, %.loc5_38.29
  178. // CHECK:STDOUT: return
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT: