import.carbon 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/struct/import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/import.carbon
  10. // --- implicit.carbon
  11. package Implicit;
  12. var a_ref: {.a: i32} = {.a = 0};
  13. var b_ref: {.a: {.b: i32, .c: (i32,)}, .d: i32} =
  14. {.a = {.b = 0, .c = (0,)}, .d = 0};
  15. class C(S:! {.a: i32, .b: i32}) {}
  16. fn F() -> C({.a = 1, .b = 2});
  17. // --- implicit.impl.carbon
  18. impl package Implicit;
  19. var a: {.a: i32} = a_ref;
  20. var b: {.a: {.b: i32, .c: (i32,)}, .d: i32} = b_ref;
  21. var c: C({.a = 1, .b = 2}) = F();
  22. // --- fail_bad_type.impl.carbon
  23. impl package Implicit;
  24. // CHECK:STDERR: fail_bad_type.impl.carbon:[[@LINE+10]]:14: ERROR: Missing value for field `a` in struct initialization.
  25. // CHECK:STDERR: var c_bad: C({.c = 1, .d = 2}) = F();
  26. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  27. // CHECK:STDERR: fail_bad_type.impl.carbon:[[@LINE-4]]:6: In import.
  28. // CHECK:STDERR: impl package Implicit;
  29. // CHECK:STDERR: ^~~~~~~
  30. // CHECK:STDERR: implicit.carbon:8:1: Initializing parameter 1 of function declared here.
  31. // CHECK:STDERR: class C(S:! {.a: i32, .b: i32}) {}
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. // CHECK:STDERR:
  34. var c_bad: C({.c = 1, .d = 2}) = F();
  35. // --- fail_bad_value.impl.carbon
  36. impl package Implicit;
  37. // CHECK:STDERR: fail_bad_value.impl.carbon:[[@LINE+3]]:1: ERROR: Cannot implicitly convert from `C` to `C`.
  38. // CHECK:STDERR: var c_bad: C({.a = 3, .b = 4}) = F();
  39. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. var c_bad: C({.a = 3, .b = 4}) = F();
  41. // CHECK:STDOUT: --- implicit.carbon
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: constants {
  44. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  45. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  46. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  47. // CHECK:STDOUT: %.2: type = struct_type {.a: i32} [template]
  48. // CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
  49. // CHECK:STDOUT: %struct.1: %.2 = struct_value (%.3) [template]
  50. // CHECK:STDOUT: %.4: type = tuple_type (type) [template]
  51. // CHECK:STDOUT: %.5: type = tuple_type (i32) [template]
  52. // CHECK:STDOUT: %.6: type = struct_type {.b: i32, .c: %.5} [template]
  53. // CHECK:STDOUT: %.7: type = struct_type {.a: %.6, .d: i32} [template]
  54. // CHECK:STDOUT: %.8: type = ptr_type %.6 [template]
  55. // CHECK:STDOUT: %.9: type = struct_type {.a: %.8, .d: i32} [template]
  56. // CHECK:STDOUT: %.10: type = ptr_type %.9 [template]
  57. // CHECK:STDOUT: %tuple: %.5 = tuple_value (%.3) [template]
  58. // CHECK:STDOUT: %struct.2: %.6 = struct_value (%.3, %tuple) [template]
  59. // CHECK:STDOUT: %struct.3: %.7 = struct_value (%struct.2, %.3) [template]
  60. // CHECK:STDOUT: %.11: type = struct_type {.a: i32, .b: i32} [template]
  61. // CHECK:STDOUT: %S: %.11 = bind_symbolic_name S 0 [symbolic]
  62. // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
  63. // CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
  64. // CHECK:STDOUT: %C.2: type = class_type @C, @C(%S) [symbolic]
  65. // CHECK:STDOUT: %.12: type = struct_type {} [template]
  66. // CHECK:STDOUT: %.13: i32 = int_literal 1 [template]
  67. // CHECK:STDOUT: %.14: i32 = int_literal 2 [template]
  68. // CHECK:STDOUT: %.15: type = ptr_type %.11 [template]
  69. // CHECK:STDOUT: %struct.4: %.11 = struct_value (%.13, %.14) [template]
  70. // CHECK:STDOUT: %C.3: type = class_type @C, @C(%struct.4) [template]
  71. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  72. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: imports {
  76. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  77. // CHECK:STDOUT: .Int32 = %import_ref
  78. // CHECK:STDOUT: import Core//prelude
  79. // CHECK:STDOUT: import Core//prelude/operators
  80. // CHECK:STDOUT: import Core//prelude/types
  81. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  82. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  83. // CHECK:STDOUT: import Core//prelude/operators/comparison
  84. // CHECK:STDOUT: import Core//prelude/types/bool
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: file {
  90. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  91. // CHECK:STDOUT: .Core = imports.%Core
  92. // CHECK:STDOUT: .a_ref = %a_ref
  93. // CHECK:STDOUT: .b_ref = %b_ref
  94. // CHECK:STDOUT: .C = %C.decl
  95. // CHECK:STDOUT: .F = %F.decl
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %Core.import = import Core
  98. // CHECK:STDOUT: %int.make_type_32.loc4: init type = call constants.%Int32() [template = i32]
  99. // CHECK:STDOUT: %.loc4_17.1: type = value_of_initializer %int.make_type_32.loc4 [template = i32]
  100. // CHECK:STDOUT: %.loc4_17.2: type = converted %int.make_type_32.loc4, %.loc4_17.1 [template = i32]
  101. // CHECK:STDOUT: %.loc4_20: type = struct_type {.a: i32} [template = constants.%.2]
  102. // CHECK:STDOUT: %a_ref.var: ref %.2 = var a_ref
  103. // CHECK:STDOUT: %a_ref: ref %.2 = bind_name a_ref, %a_ref.var
  104. // CHECK:STDOUT: %int.make_type_32.loc5_22: init type = call constants.%Int32() [template = i32]
  105. // CHECK:STDOUT: %.loc5_22.1: type = value_of_initializer %int.make_type_32.loc5_22 [template = i32]
  106. // CHECK:STDOUT: %.loc5_22.2: type = converted %int.make_type_32.loc5_22, %.loc5_22.1 [template = i32]
  107. // CHECK:STDOUT: %int.make_type_32.loc5_32: init type = call constants.%Int32() [template = i32]
  108. // CHECK:STDOUT: %.loc5_36.1: %.4 = tuple_literal (%int.make_type_32.loc5_32)
  109. // CHECK:STDOUT: %.loc5_36.2: type = value_of_initializer %int.make_type_32.loc5_32 [template = i32]
  110. // CHECK:STDOUT: %.loc5_36.3: type = converted %int.make_type_32.loc5_32, %.loc5_36.2 [template = i32]
  111. // CHECK:STDOUT: %.loc5_36.4: type = converted %.loc5_36.1, constants.%.5 [template = constants.%.5]
  112. // CHECK:STDOUT: %.loc5_37: type = struct_type {.b: i32, .c: %.5} [template = constants.%.6]
  113. // CHECK:STDOUT: %int.make_type_32.loc5_44: init type = call constants.%Int32() [template = i32]
  114. // CHECK:STDOUT: %.loc5_44.1: type = value_of_initializer %int.make_type_32.loc5_44 [template = i32]
  115. // CHECK:STDOUT: %.loc5_44.2: type = converted %int.make_type_32.loc5_44, %.loc5_44.1 [template = i32]
  116. // CHECK:STDOUT: %.loc5_47: type = struct_type {.a: %.6, .d: i32} [template = constants.%.7]
  117. // CHECK:STDOUT: %b_ref.var: ref %.7 = var b_ref
  118. // CHECK:STDOUT: %b_ref: ref %.7 = bind_name b_ref, %b_ref.var
  119. // CHECK:STDOUT: %C.decl: %C.type = class_decl @C [template = constants.%C.1] {
  120. // CHECK:STDOUT: %int.make_type_32.loc8_18: init type = call constants.%Int32() [template = i32]
  121. // CHECK:STDOUT: %.loc8_18.1: type = value_of_initializer %int.make_type_32.loc8_18 [template = i32]
  122. // CHECK:STDOUT: %.loc8_18.2: type = converted %int.make_type_32.loc8_18, %.loc8_18.1 [template = i32]
  123. // CHECK:STDOUT: %int.make_type_32.loc8_27: init type = call constants.%Int32() [template = i32]
  124. // CHECK:STDOUT: %.loc8_27.1: type = value_of_initializer %int.make_type_32.loc8_27 [template = i32]
  125. // CHECK:STDOUT: %.loc8_27.2: type = converted %int.make_type_32.loc8_27, %.loc8_27.1 [template = i32]
  126. // CHECK:STDOUT: %.loc8_30: type = struct_type {.a: i32, .b: i32} [template = constants.%.11]
  127. // CHECK:STDOUT: %S.loc8_9.1: %.11 = param S
  128. // CHECK:STDOUT: %S.loc8_9.2: %.11 = bind_symbolic_name S 0, %S.loc8_9.1 [symbolic = @C.%S (constants.%S)]
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  131. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, %C.decl [template = constants.%C.1]
  132. // CHECK:STDOUT: %.loc9_19: i32 = int_literal 1 [template = constants.%.13]
  133. // CHECK:STDOUT: %.loc9_27: i32 = int_literal 2 [template = constants.%.14]
  134. // CHECK:STDOUT: %.loc9_28: %.11 = struct_literal (%.loc9_19, %.loc9_27)
  135. // CHECK:STDOUT: %struct: %.11 = struct_value (%.loc9_19, %.loc9_27) [template = constants.%struct.4]
  136. // CHECK:STDOUT: %.loc9_12.1: %.11 = converted %.loc9_28, %struct [template = constants.%struct.4]
  137. // CHECK:STDOUT: %.loc9_12.2: init type = call %C.ref(%.loc9_12.1) [template = constants.%C.3]
  138. // CHECK:STDOUT: %.loc9_29.1: type = value_of_initializer %.loc9_12.2 [template = constants.%C.3]
  139. // CHECK:STDOUT: %.loc9_29.2: type = converted %.loc9_12.2, %.loc9_29.1 [template = constants.%C.3]
  140. // CHECK:STDOUT: @F.%return: ref %C.3 = var <return slot>
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: generic class @C(file.%S.loc8_9.2: %.11) {
  145. // CHECK:STDOUT: %S: %.11 = bind_symbolic_name S 0 [symbolic = %S (constants.%S)]
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: !definition:
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: class {
  150. // CHECK:STDOUT: !members:
  151. // CHECK:STDOUT: .Self = constants.%C.2
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: fn @F() -> %C.3;
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: fn @__global_init() {
  160. // CHECK:STDOUT: !entry:
  161. // CHECK:STDOUT: %.loc4_30: i32 = int_literal 0 [template = constants.%.3]
  162. // CHECK:STDOUT: %.loc4_31.1: %.2 = struct_literal (%.loc4_30)
  163. // CHECK:STDOUT: %.loc4_31.2: init %.2 = struct_init (%.loc4_30) to file.%a_ref.var [template = constants.%struct.1]
  164. // CHECK:STDOUT: %.loc4_32: init %.2 = converted %.loc4_31.1, %.loc4_31.2 [template = constants.%struct.1]
  165. // CHECK:STDOUT: assign file.%a_ref.var, %.loc4_32
  166. // CHECK:STDOUT: %.loc6_17: i32 = int_literal 0 [template = constants.%.3]
  167. // CHECK:STDOUT: %.loc6_26: i32 = int_literal 0 [template = constants.%.3]
  168. // CHECK:STDOUT: %.loc6_28.1: %.5 = tuple_literal (%.loc6_26)
  169. // CHECK:STDOUT: %.loc6_29.1: %.6 = struct_literal (%.loc6_17, %.loc6_28.1)
  170. // CHECK:STDOUT: %.loc6_37: i32 = int_literal 0 [template = constants.%.3]
  171. // CHECK:STDOUT: %.loc6_38.1: %.7 = struct_literal (%.loc6_29.1, %.loc6_37)
  172. // CHECK:STDOUT: %.loc6_38.2: ref %.6 = struct_access file.%b_ref.var, element0
  173. // CHECK:STDOUT: %.loc6_29.2: ref i32 = struct_access %.loc6_38.2, element0
  174. // CHECK:STDOUT: %.loc6_29.3: init i32 = initialize_from %.loc6_17 to %.loc6_29.2 [template = constants.%.3]
  175. // CHECK:STDOUT: %.loc6_29.4: ref %.5 = struct_access %.loc6_38.2, element1
  176. // CHECK:STDOUT: %.loc6_28.2: init %.5 = tuple_init (%.loc6_26) to %.loc6_29.4 [template = constants.%tuple]
  177. // CHECK:STDOUT: %.loc6_29.5: init %.5 = converted %.loc6_28.1, %.loc6_28.2 [template = constants.%tuple]
  178. // CHECK:STDOUT: %.loc6_29.6: init %.5 = initialize_from %.loc6_29.5 to %.loc6_29.4 [template = constants.%tuple]
  179. // CHECK:STDOUT: %.loc6_29.7: init %.6 = struct_init (%.loc6_29.3, %.loc6_29.6) to %.loc6_38.2 [template = constants.%struct.2]
  180. // CHECK:STDOUT: %.loc6_38.3: init %.6 = converted %.loc6_29.1, %.loc6_29.7 [template = constants.%struct.2]
  181. // CHECK:STDOUT: %.loc6_38.4: ref i32 = struct_access file.%b_ref.var, element1
  182. // CHECK:STDOUT: %.loc6_38.5: init i32 = initialize_from %.loc6_37 to %.loc6_38.4 [template = constants.%.3]
  183. // CHECK:STDOUT: %.loc6_38.6: init %.7 = struct_init (%.loc6_38.3, %.loc6_38.5) to file.%b_ref.var [template = constants.%struct.3]
  184. // CHECK:STDOUT: %.loc6_39: init %.7 = converted %.loc6_38.1, %.loc6_38.6 [template = constants.%struct.3]
  185. // CHECK:STDOUT: assign file.%b_ref.var, %.loc6_39
  186. // CHECK:STDOUT: return
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: specific @C(constants.%S) {
  190. // CHECK:STDOUT: %S => constants.%S
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: specific @C(constants.%struct.4) {
  194. // CHECK:STDOUT: %S => constants.%struct.4
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: --- implicit.impl.carbon
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: constants {
  200. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  201. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  202. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  203. // CHECK:STDOUT: %.2: type = struct_type {.a: i32} [template]
  204. // CHECK:STDOUT: %.3: type = tuple_type (type) [template]
  205. // CHECK:STDOUT: %.4: type = tuple_type (i32) [template]
  206. // CHECK:STDOUT: %.5: type = struct_type {.b: i32, .c: %.4} [template]
  207. // CHECK:STDOUT: %.6: type = struct_type {.a: %.5, .d: i32} [template]
  208. // CHECK:STDOUT: %.7: type = ptr_type %.5 [template]
  209. // CHECK:STDOUT: %.8: type = struct_type {.a: %.7, .d: i32} [template]
  210. // CHECK:STDOUT: %.9: type = ptr_type %.8 [template]
  211. // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
  212. // CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
  213. // CHECK:STDOUT: %.10: type = struct_type {} [template]
  214. // CHECK:STDOUT: %.11: type = struct_type {.a: i32, .b: i32} [template]
  215. // CHECK:STDOUT: %S: %.11 = bind_symbolic_name S 0 [symbolic]
  216. // CHECK:STDOUT: %C.2: type = class_type @C, @C(%S) [symbolic]
  217. // CHECK:STDOUT: %.12: i32 = int_literal 1 [template]
  218. // CHECK:STDOUT: %.13: i32 = int_literal 2 [template]
  219. // CHECK:STDOUT: %.14: type = ptr_type %.11 [template]
  220. // CHECK:STDOUT: %struct: %.11 = struct_value (%.12, %.13) [template]
  221. // CHECK:STDOUT: %C.3: type = class_type @C, @C(%struct) [template]
  222. // CHECK:STDOUT: %.15: type = ptr_type %.10 [template]
  223. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  224. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: imports {
  228. // CHECK:STDOUT: %import_ref.1: ref %.2 = import_ref Implicit//default, inst+17, loaded
  229. // CHECK:STDOUT: %import_ref.2: ref %.6 = import_ref Implicit//default, inst+57, loaded
  230. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Implicit//default, inst+99, loaded [template = constants.%C.1]
  231. // CHECK:STDOUT: %import_ref.4: %F.type = import_ref Implicit//default, inst+122, loaded [template = constants.%F]
  232. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  233. // CHECK:STDOUT: .Int32 = %import_ref.5
  234. // CHECK:STDOUT: import Core//prelude
  235. // CHECK:STDOUT: import Core//prelude/operators
  236. // CHECK:STDOUT: import Core//prelude/types
  237. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  238. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  239. // CHECK:STDOUT: import Core//prelude/operators/comparison
  240. // CHECK:STDOUT: import Core//prelude/types/bool
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  243. // CHECK:STDOUT: %import_ref.6 = import_ref Implicit//default, inst+103, unloaded
  244. // CHECK:STDOUT: }
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: file {
  247. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  248. // CHECK:STDOUT: .a_ref = imports.%import_ref.1
  249. // CHECK:STDOUT: .b_ref = imports.%import_ref.2
  250. // CHECK:STDOUT: .C = imports.%import_ref.3
  251. // CHECK:STDOUT: .F = imports.%import_ref.4
  252. // CHECK:STDOUT: .Core = imports.%Core
  253. // CHECK:STDOUT: .a = %a
  254. // CHECK:STDOUT: .b = %b
  255. // CHECK:STDOUT: .c = %c
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT: %Implicit.import = import Implicit
  258. // CHECK:STDOUT: %default.import = import <invalid>
  259. // CHECK:STDOUT: %Core.import = import Core
  260. // CHECK:STDOUT: %int.make_type_32.loc4: init type = call constants.%Int32() [template = i32]
  261. // CHECK:STDOUT: %.loc4_13.1: type = value_of_initializer %int.make_type_32.loc4 [template = i32]
  262. // CHECK:STDOUT: %.loc4_13.2: type = converted %int.make_type_32.loc4, %.loc4_13.1 [template = i32]
  263. // CHECK:STDOUT: %.loc4_16: type = struct_type {.a: i32} [template = constants.%.2]
  264. // CHECK:STDOUT: %a.var: ref %.2 = var a
  265. // CHECK:STDOUT: %a: ref %.2 = bind_name a, %a.var
  266. // CHECK:STDOUT: %int.make_type_32.loc5_18: init type = call constants.%Int32() [template = i32]
  267. // CHECK:STDOUT: %.loc5_18.1: type = value_of_initializer %int.make_type_32.loc5_18 [template = i32]
  268. // CHECK:STDOUT: %.loc5_18.2: type = converted %int.make_type_32.loc5_18, %.loc5_18.1 [template = i32]
  269. // CHECK:STDOUT: %int.make_type_32.loc5_28: init type = call constants.%Int32() [template = i32]
  270. // CHECK:STDOUT: %.loc5_32.1: %.3 = tuple_literal (%int.make_type_32.loc5_28)
  271. // CHECK:STDOUT: %.loc5_32.2: type = value_of_initializer %int.make_type_32.loc5_28 [template = i32]
  272. // CHECK:STDOUT: %.loc5_32.3: type = converted %int.make_type_32.loc5_28, %.loc5_32.2 [template = i32]
  273. // CHECK:STDOUT: %.loc5_32.4: type = converted %.loc5_32.1, constants.%.4 [template = constants.%.4]
  274. // CHECK:STDOUT: %.loc5_33: type = struct_type {.b: i32, .c: %.4} [template = constants.%.5]
  275. // CHECK:STDOUT: %int.make_type_32.loc5_40: init type = call constants.%Int32() [template = i32]
  276. // CHECK:STDOUT: %.loc5_40.1: type = value_of_initializer %int.make_type_32.loc5_40 [template = i32]
  277. // CHECK:STDOUT: %.loc5_40.2: type = converted %int.make_type_32.loc5_40, %.loc5_40.1 [template = i32]
  278. // CHECK:STDOUT: %.loc5_43: type = struct_type {.a: %.5, .d: i32} [template = constants.%.6]
  279. // CHECK:STDOUT: %b.var: ref %.6 = var b
  280. // CHECK:STDOUT: %b: ref %.6 = bind_name b, %b.var
  281. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C.1]
  282. // CHECK:STDOUT: %.loc6_16: i32 = int_literal 1 [template = constants.%.12]
  283. // CHECK:STDOUT: %.loc6_24: i32 = int_literal 2 [template = constants.%.13]
  284. // CHECK:STDOUT: %.loc6_25: %.11 = struct_literal (%.loc6_16, %.loc6_24)
  285. // CHECK:STDOUT: %struct: %.11 = struct_value (%.loc6_16, %.loc6_24) [template = constants.%struct]
  286. // CHECK:STDOUT: %.loc6_9.1: %.11 = converted %.loc6_25, %struct [template = constants.%struct]
  287. // CHECK:STDOUT: %.loc6_9.2: init type = call %C.ref(%.loc6_9.1) [template = constants.%C.3]
  288. // CHECK:STDOUT: %.loc6_26.1: type = value_of_initializer %.loc6_9.2 [template = constants.%C.3]
  289. // CHECK:STDOUT: %.loc6_26.2: type = converted %.loc6_9.2, %.loc6_26.1 [template = constants.%C.3]
  290. // CHECK:STDOUT: %c.var: ref %C.3 = var c
  291. // CHECK:STDOUT: %c: ref %C.3 = bind_name c, %c.var
  292. // CHECK:STDOUT: }
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: generic class @C(constants.%S: %.11) {
  295. // CHECK:STDOUT: %S: %.11 = bind_symbolic_name S 0 [symbolic = %S (constants.%S)]
  296. // CHECK:STDOUT:
  297. // CHECK:STDOUT: !definition:
  298. // CHECK:STDOUT:
  299. // CHECK:STDOUT: class {
  300. // CHECK:STDOUT: !members:
  301. // CHECK:STDOUT: .Self = imports.%import_ref.6
  302. // CHECK:STDOUT: }
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  306. // CHECK:STDOUT:
  307. // CHECK:STDOUT: fn @F() -> %C.3;
  308. // CHECK:STDOUT:
  309. // CHECK:STDOUT: fn @__global_init() {
  310. // CHECK:STDOUT: !entry:
  311. // CHECK:STDOUT: %a_ref.ref: ref %.2 = name_ref a_ref, imports.%import_ref.1
  312. // CHECK:STDOUT: %.loc4_20.1: ref i32 = struct_access %a_ref.ref, element0
  313. // CHECK:STDOUT: %.loc4_20.2: i32 = bind_value %.loc4_20.1
  314. // CHECK:STDOUT: %.loc4_20.3: init %.2 = struct_init (%.loc4_20.2) to file.%a.var
  315. // CHECK:STDOUT: %.loc4_25: init %.2 = converted %a_ref.ref, %.loc4_20.3
  316. // CHECK:STDOUT: assign file.%a.var, %.loc4_25
  317. // CHECK:STDOUT: %b_ref.ref: ref %.6 = name_ref b_ref, imports.%import_ref.2
  318. // CHECK:STDOUT: %.loc5_47.1: ref %.5 = struct_access %b_ref.ref, element0
  319. // CHECK:STDOUT: %.loc5_47.2: ref i32 = struct_access %.loc5_47.1, element0
  320. // CHECK:STDOUT: %.loc5_47.3: i32 = bind_value %.loc5_47.2
  321. // CHECK:STDOUT: %.loc5_47.4: ref %.5 = struct_access file.%b.var, element0
  322. // CHECK:STDOUT: %.loc5_47.5: ref i32 = struct_access %.loc5_47.4, element0
  323. // CHECK:STDOUT: %.loc5_47.6: init i32 = initialize_from %.loc5_47.3 to %.loc5_47.5
  324. // CHECK:STDOUT: %.loc5_47.7: ref %.4 = struct_access %.loc5_47.1, element1
  325. // CHECK:STDOUT: %.loc5_47.8: ref i32 = tuple_access %.loc5_47.7, element0
  326. // CHECK:STDOUT: %.loc5_47.9: i32 = bind_value %.loc5_47.8
  327. // CHECK:STDOUT: %.loc5_47.10: ref %.4 = struct_access %.loc5_47.4, element1
  328. // CHECK:STDOUT: %.loc5_47.11: init %.4 = tuple_init (%.loc5_47.9) to %.loc5_47.10
  329. // CHECK:STDOUT: %.loc5_47.12: init %.4 = converted %.loc5_47.7, %.loc5_47.11
  330. // CHECK:STDOUT: %.loc5_47.13: init %.4 = initialize_from %.loc5_47.12 to %.loc5_47.10
  331. // CHECK:STDOUT: %.loc5_47.14: init %.5 = struct_init (%.loc5_47.6, %.loc5_47.13) to %.loc5_47.4
  332. // CHECK:STDOUT: %.loc5_47.15: init %.5 = converted %.loc5_47.1, %.loc5_47.14
  333. // CHECK:STDOUT: %.loc5_47.16: ref i32 = struct_access %b_ref.ref, element1
  334. // CHECK:STDOUT: %.loc5_47.17: i32 = bind_value %.loc5_47.16
  335. // CHECK:STDOUT: %.loc5_47.18: ref i32 = struct_access file.%b.var, element1
  336. // CHECK:STDOUT: %.loc5_47.19: init i32 = initialize_from %.loc5_47.17 to %.loc5_47.18
  337. // CHECK:STDOUT: %.loc5_47.20: init %.6 = struct_init (%.loc5_47.15, %.loc5_47.19) to file.%b.var
  338. // CHECK:STDOUT: %.loc5_52: init %.6 = converted %b_ref.ref, %.loc5_47.20
  339. // CHECK:STDOUT: assign file.%b.var, %.loc5_52
  340. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%import_ref.4 [template = constants.%F]
  341. // CHECK:STDOUT: %.loc6: ref %C.3 = splice_block file.%c.var {}
  342. // CHECK:STDOUT: %F.call: init %C.3 = call %F.ref() to %.loc6
  343. // CHECK:STDOUT: assign file.%c.var, %F.call
  344. // CHECK:STDOUT: return
  345. // CHECK:STDOUT: }
  346. // CHECK:STDOUT:
  347. // CHECK:STDOUT: specific @C(constants.%S) {
  348. // CHECK:STDOUT: %S => constants.%S
  349. // CHECK:STDOUT: }
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: specific @C(constants.%struct) {
  352. // CHECK:STDOUT: %S => constants.%struct
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: !definition:
  355. // CHECK:STDOUT: }
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: --- fail_bad_type.impl.carbon
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: constants {
  360. // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
  361. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  362. // CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
  363. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  364. // CHECK:STDOUT: %.3: type = struct_type {.a: i32, .b: i32} [template]
  365. // CHECK:STDOUT: %S: %.3 = bind_symbolic_name S 0 [symbolic]
  366. // CHECK:STDOUT: %C.2: type = class_type @C, @C(%S) [symbolic]
  367. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  368. // CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
  369. // CHECK:STDOUT: %.6: type = struct_type {.c: i32, .d: i32} [template]
  370. // CHECK:STDOUT: %.7: type = ptr_type %.3 [template]
  371. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  372. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  373. // CHECK:STDOUT: %struct: %.3 = struct_value (%.4, %.5) [template]
  374. // CHECK:STDOUT: %C.3: type = class_type @C, @C(%struct) [template]
  375. // CHECK:STDOUT: %.8: type = ptr_type %.2 [template]
  376. // CHECK:STDOUT: }
  377. // CHECK:STDOUT:
  378. // CHECK:STDOUT: imports {
  379. // CHECK:STDOUT: %import_ref.1 = import_ref Implicit//default, inst+17, unloaded
  380. // CHECK:STDOUT: %import_ref.2 = import_ref Implicit//default, inst+57, unloaded
  381. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Implicit//default, inst+99, loaded [template = constants.%C.1]
  382. // CHECK:STDOUT: %import_ref.4: %F.type = import_ref Implicit//default, inst+122, loaded [template = constants.%F]
  383. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  384. // CHECK:STDOUT: import Core//prelude
  385. // CHECK:STDOUT: import Core//prelude/operators
  386. // CHECK:STDOUT: import Core//prelude/types
  387. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  388. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  389. // CHECK:STDOUT: import Core//prelude/operators/comparison
  390. // CHECK:STDOUT: import Core//prelude/types/bool
  391. // CHECK:STDOUT: }
  392. // CHECK:STDOUT: %import_ref.5 = import_ref Implicit//default, inst+103, unloaded
  393. // CHECK:STDOUT: }
  394. // CHECK:STDOUT:
  395. // CHECK:STDOUT: file {
  396. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  397. // CHECK:STDOUT: .a_ref = imports.%import_ref.1
  398. // CHECK:STDOUT: .b_ref = imports.%import_ref.2
  399. // CHECK:STDOUT: .C = imports.%import_ref.3
  400. // CHECK:STDOUT: .F = imports.%import_ref.4
  401. // CHECK:STDOUT: .Core = imports.%Core
  402. // CHECK:STDOUT: .c_bad = %c_bad
  403. // CHECK:STDOUT: }
  404. // CHECK:STDOUT: %Implicit.import = import Implicit
  405. // CHECK:STDOUT: %default.import = import <invalid>
  406. // CHECK:STDOUT: %Core.import = import Core
  407. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C.1]
  408. // CHECK:STDOUT: %.loc13_20: i32 = int_literal 1 [template = constants.%.4]
  409. // CHECK:STDOUT: %.loc13_28: i32 = int_literal 2 [template = constants.%.5]
  410. // CHECK:STDOUT: %.loc13_29: %.6 = struct_literal (%.loc13_20, %.loc13_28)
  411. // CHECK:STDOUT: %.loc13_13: init type = call %C.ref(<invalid>) [template = <error>]
  412. // CHECK:STDOUT: %.loc13_30.1: type = value_of_initializer %.loc13_13 [template = <error>]
  413. // CHECK:STDOUT: %.loc13_30.2: type = converted %.loc13_13, %.loc13_30.1 [template = <error>]
  414. // CHECK:STDOUT: %c_bad.var: ref <error> = var c_bad
  415. // CHECK:STDOUT: %c_bad: ref <error> = bind_name c_bad, %c_bad.var
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT:
  418. // CHECK:STDOUT: generic class @C(constants.%S: %.3) {
  419. // CHECK:STDOUT: %S: %.3 = bind_symbolic_name S 0 [symbolic = %S (constants.%S)]
  420. // CHECK:STDOUT:
  421. // CHECK:STDOUT: !definition:
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: class {
  424. // CHECK:STDOUT: !members:
  425. // CHECK:STDOUT: .Self = imports.%import_ref.5
  426. // CHECK:STDOUT: }
  427. // CHECK:STDOUT: }
  428. // CHECK:STDOUT:
  429. // CHECK:STDOUT: fn @F() -> %C.3;
  430. // CHECK:STDOUT:
  431. // CHECK:STDOUT: fn @__global_init() {
  432. // CHECK:STDOUT: !entry:
  433. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%import_ref.4 [template = constants.%F]
  434. // CHECK:STDOUT: %.loc13: ref %C.3 = temporary_storage
  435. // CHECK:STDOUT: %F.call: init %C.3 = call %F.ref() to %.loc13
  436. // CHECK:STDOUT: assign file.%c_bad.var, <error>
  437. // CHECK:STDOUT: return
  438. // CHECK:STDOUT: }
  439. // CHECK:STDOUT:
  440. // CHECK:STDOUT: specific @C(constants.%S) {
  441. // CHECK:STDOUT: %S => constants.%S
  442. // CHECK:STDOUT: }
  443. // CHECK:STDOUT:
  444. // CHECK:STDOUT: specific @C(constants.%struct) {
  445. // CHECK:STDOUT: %S => constants.%struct
  446. // CHECK:STDOUT:
  447. // CHECK:STDOUT: !definition:
  448. // CHECK:STDOUT: }
  449. // CHECK:STDOUT:
  450. // CHECK:STDOUT: --- fail_bad_value.impl.carbon
  451. // CHECK:STDOUT:
  452. // CHECK:STDOUT: constants {
  453. // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
  454. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  455. // CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
  456. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  457. // CHECK:STDOUT: %.3: type = struct_type {.a: i32, .b: i32} [template]
  458. // CHECK:STDOUT: %S: %.3 = bind_symbolic_name S 0 [symbolic]
  459. // CHECK:STDOUT: %C.2: type = class_type @C, @C(%S) [symbolic]
  460. // CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
  461. // CHECK:STDOUT: %.5: i32 = int_literal 4 [template]
  462. // CHECK:STDOUT: %.6: type = ptr_type %.3 [template]
  463. // CHECK:STDOUT: %struct.1: %.3 = struct_value (%.4, %.5) [template]
  464. // CHECK:STDOUT: %C.3: type = class_type @C, @C(%struct.1) [template]
  465. // CHECK:STDOUT: %.7: type = ptr_type %.2 [template]
  466. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  467. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  468. // CHECK:STDOUT: %.8: i32 = int_literal 2 [template]
  469. // CHECK:STDOUT: %.9: i32 = int_literal 1 [template]
  470. // CHECK:STDOUT: %struct.2: %.3 = struct_value (%.9, %.8) [template]
  471. // CHECK:STDOUT: %C.4: type = class_type @C, @C(%struct.2) [template]
  472. // CHECK:STDOUT: }
  473. // CHECK:STDOUT:
  474. // CHECK:STDOUT: imports {
  475. // CHECK:STDOUT: %import_ref.1 = import_ref Implicit//default, inst+17, unloaded
  476. // CHECK:STDOUT: %import_ref.2 = import_ref Implicit//default, inst+57, unloaded
  477. // CHECK:STDOUT: %import_ref.3: %C.type = import_ref Implicit//default, inst+99, loaded [template = constants.%C.1]
  478. // CHECK:STDOUT: %import_ref.4: %F.type = import_ref Implicit//default, inst+122, loaded [template = constants.%F]
  479. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  480. // CHECK:STDOUT: import Core//prelude
  481. // CHECK:STDOUT: import Core//prelude/operators
  482. // CHECK:STDOUT: import Core//prelude/types
  483. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  484. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  485. // CHECK:STDOUT: import Core//prelude/operators/comparison
  486. // CHECK:STDOUT: import Core//prelude/types/bool
  487. // CHECK:STDOUT: }
  488. // CHECK:STDOUT: %import_ref.5 = import_ref Implicit//default, inst+103, unloaded
  489. // CHECK:STDOUT: }
  490. // CHECK:STDOUT:
  491. // CHECK:STDOUT: file {
  492. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  493. // CHECK:STDOUT: .a_ref = imports.%import_ref.1
  494. // CHECK:STDOUT: .b_ref = imports.%import_ref.2
  495. // CHECK:STDOUT: .C = imports.%import_ref.3
  496. // CHECK:STDOUT: .F = imports.%import_ref.4
  497. // CHECK:STDOUT: .Core = imports.%Core
  498. // CHECK:STDOUT: .c_bad = %c_bad
  499. // CHECK:STDOUT: }
  500. // CHECK:STDOUT: %Implicit.import = import Implicit
  501. // CHECK:STDOUT: %default.import = import <invalid>
  502. // CHECK:STDOUT: %Core.import = import Core
  503. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, imports.%import_ref.3 [template = constants.%C.1]
  504. // CHECK:STDOUT: %.loc6_20: i32 = int_literal 3 [template = constants.%.4]
  505. // CHECK:STDOUT: %.loc6_28: i32 = int_literal 4 [template = constants.%.5]
  506. // CHECK:STDOUT: %.loc6_29: %.3 = struct_literal (%.loc6_20, %.loc6_28)
  507. // CHECK:STDOUT: %struct: %.3 = struct_value (%.loc6_20, %.loc6_28) [template = constants.%struct.1]
  508. // CHECK:STDOUT: %.loc6_13.1: %.3 = converted %.loc6_29, %struct [template = constants.%struct.1]
  509. // CHECK:STDOUT: %.loc6_13.2: init type = call %C.ref(%.loc6_13.1) [template = constants.%C.3]
  510. // CHECK:STDOUT: %.loc6_30.1: type = value_of_initializer %.loc6_13.2 [template = constants.%C.3]
  511. // CHECK:STDOUT: %.loc6_30.2: type = converted %.loc6_13.2, %.loc6_30.1 [template = constants.%C.3]
  512. // CHECK:STDOUT: %c_bad.var: ref %C.3 = var c_bad
  513. // CHECK:STDOUT: %c_bad: ref %C.3 = bind_name c_bad, %c_bad.var
  514. // CHECK:STDOUT: }
  515. // CHECK:STDOUT:
  516. // CHECK:STDOUT: generic class @C(constants.%S: %.3) {
  517. // CHECK:STDOUT: %S: %.3 = bind_symbolic_name S 0 [symbolic = %S (constants.%S)]
  518. // CHECK:STDOUT:
  519. // CHECK:STDOUT: !definition:
  520. // CHECK:STDOUT:
  521. // CHECK:STDOUT: class {
  522. // CHECK:STDOUT: !members:
  523. // CHECK:STDOUT: .Self = imports.%import_ref.5
  524. // CHECK:STDOUT: }
  525. // CHECK:STDOUT: }
  526. // CHECK:STDOUT:
  527. // CHECK:STDOUT: fn @F() -> %C.4;
  528. // CHECK:STDOUT:
  529. // CHECK:STDOUT: fn @__global_init() {
  530. // CHECK:STDOUT: !entry:
  531. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%import_ref.4 [template = constants.%F]
  532. // CHECK:STDOUT: %.loc6: ref %C.4 = temporary_storage
  533. // CHECK:STDOUT: %F.call: init %C.4 = call %F.ref() to %.loc6
  534. // CHECK:STDOUT: assign file.%c_bad.var, <error>
  535. // CHECK:STDOUT: return
  536. // CHECK:STDOUT: }
  537. // CHECK:STDOUT:
  538. // CHECK:STDOUT: specific @C(constants.%S) {
  539. // CHECK:STDOUT: %S => constants.%S
  540. // CHECK:STDOUT: }
  541. // CHECK:STDOUT:
  542. // CHECK:STDOUT: specific @C(constants.%struct.1) {
  543. // CHECK:STDOUT: %S => constants.%struct.1
  544. // CHECK:STDOUT:
  545. // CHECK:STDOUT: !definition:
  546. // CHECK:STDOUT: }
  547. // CHECK:STDOUT:
  548. // CHECK:STDOUT: specific @C(constants.%struct.2) {
  549. // CHECK:STDOUT: %S => constants.%struct.2
  550. // CHECK:STDOUT:
  551. // CHECK:STDOUT: !definition:
  552. // CHECK:STDOUT: }
  553. // CHECK:STDOUT: