import.carbon 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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/class/generic/import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/import.carbon
  10. // --- foo.carbon
  11. library "[[@TEST_NAME]]";
  12. class Class(T:! type);
  13. class CompleteClass(T:! type) {
  14. var n: i32;
  15. fn F() -> i32 { return 0; }
  16. }
  17. fn F() -> CompleteClass(i32);
  18. // --- foo.impl.carbon
  19. impl library "[[@TEST_NAME]]";
  20. class Class(T:! type) {
  21. var x: T;
  22. }
  23. fn F() -> CompleteClass(i32) {
  24. return {.n = 1};
  25. }
  26. // --- use_foo.carbon
  27. library "[[@TEST_NAME]]";
  28. import library "foo";
  29. fn UseMethod() -> i32 {
  30. var v: CompleteClass(i32) = F();
  31. return v.F();
  32. }
  33. fn UseField() -> i32 {
  34. var v: CompleteClass(i32) = F();
  35. return v.n;
  36. }
  37. // --- fail_generic_arg_mismatch.carbon
  38. library "[[@TEST_NAME]]";
  39. import library "foo";
  40. fn Use() {
  41. // TODO: Include the generic arguments in the formatted type name.
  42. // CHECK:STDERR: fail_generic_arg_mismatch.carbon:[[@LINE+7]]:3: ERROR: Cannot implicitly convert from `CompleteClass` to `CompleteClass`.
  43. // CHECK:STDERR: var v: CompleteClass(i32*) = F();
  44. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. // CHECK:STDERR: fail_generic_arg_mismatch.carbon:[[@LINE+4]]:3: Type `CompleteClass` does not implement interface `ImplicitAs`.
  46. // CHECK:STDERR: var v: CompleteClass(i32*) = F();
  47. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  48. // CHECK:STDERR:
  49. var v: CompleteClass(i32*) = F();
  50. }
  51. // --- fail_foo.impl.carbon
  52. impl library "[[@TEST_NAME]]";
  53. // CHECK:STDERR: fail_foo.impl.carbon:[[@LINE+10]]:13: ERROR: Redeclaration differs at parameter 1.
  54. // CHECK:STDERR: class Class(U:! type) {
  55. // CHECK:STDERR: ^
  56. // CHECK:STDERR: fail_foo.impl.carbon:[[@LINE-5]]:6: In import.
  57. // CHECK:STDERR: impl library "foo";
  58. // CHECK:STDERR: ^~~~~~~
  59. // CHECK:STDERR: foo.carbon:4:13: Previous declaration's corresponding parameter here.
  60. // CHECK:STDERR: class Class(T:! type);
  61. // CHECK:STDERR: ^
  62. // CHECK:STDERR:
  63. class Class(U:! type) {
  64. // CHECK:STDERR: fail_foo.impl.carbon:[[@LINE+3]]:10: ERROR: Name `T` not found.
  65. // CHECK:STDERR: var x: T;
  66. // CHECK:STDERR: ^
  67. var x: T;
  68. }
  69. // CHECK:STDOUT: --- foo.carbon
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: constants {
  72. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  73. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  74. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  75. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  76. // CHECK:STDOUT: %Class.2: type = class_type @Class, @Class(%T) [symbolic]
  77. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  78. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  79. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
  80. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  81. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  82. // CHECK:STDOUT: %.2: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
  83. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
  84. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  85. // CHECK:STDOUT: %.3: type = struct_type {.n: i32} [template]
  86. // CHECK:STDOUT: %.4: i32 = int_literal 0 [template]
  87. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  88. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  89. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: imports {
  93. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  94. // CHECK:STDOUT: .Int32 = %import_ref
  95. // CHECK:STDOUT: import Core//prelude
  96. // CHECK:STDOUT: import Core//prelude/operators
  97. // CHECK:STDOUT: import Core//prelude/types
  98. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  99. // CHECK:STDOUT: import Core//prelude/operators/as
  100. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  101. // CHECK:STDOUT: import Core//prelude/operators/comparison
  102. // CHECK:STDOUT: import Core//prelude/types/bool
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: file {
  108. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  109. // CHECK:STDOUT: .Core = imports.%Core
  110. // CHECK:STDOUT: .Class = %Class.decl
  111. // CHECK:STDOUT: .CompleteClass = %CompleteClass.decl
  112. // CHECK:STDOUT: .F = %F.decl
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %Core.import = import Core
  115. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  116. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  117. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = @Class.%T (constants.%T)]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %CompleteClass.decl: %CompleteClass.type = class_decl @CompleteClass [template = constants.%CompleteClass.1] {
  120. // CHECK:STDOUT: %T.loc6_21.1: type = param T
  121. // CHECK:STDOUT: %T.loc6_21.2: type = bind_symbolic_name T 0, %T.loc6_21.1 [symbolic = @CompleteClass.%T (constants.%T)]
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  124. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, %CompleteClass.decl [template = constants.%CompleteClass.1]
  125. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  126. // CHECK:STDOUT: %.loc11_24.1: type = value_of_initializer %int.make_type_32 [template = i32]
  127. // CHECK:STDOUT: %.loc11_24.2: type = converted %int.make_type_32, %.loc11_24.1 [template = i32]
  128. // CHECK:STDOUT: %.loc11_24.3: init type = call %CompleteClass.ref(%.loc11_24.2) [template = constants.%CompleteClass.3]
  129. // CHECK:STDOUT: %.loc11_28.1: type = value_of_initializer %.loc11_24.3 [template = constants.%CompleteClass.3]
  130. // CHECK:STDOUT: %.loc11_28.2: type = converted %.loc11_24.3, %.loc11_28.1 [template = constants.%CompleteClass.3]
  131. // CHECK:STDOUT: @F.2.%return: ref %CompleteClass.3 = var <return slot>
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: generic class @Class(file.%T.loc4_13.2: type) {
  136. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: class;
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: generic class @CompleteClass(file.%T.loc6_21.2: type) {
  142. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: !definition:
  145. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  146. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.2)]
  147. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  148. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: class {
  151. // CHECK:STDOUT: %int.make_type_32.loc7: init type = call constants.%Int32() [template = i32]
  152. // CHECK:STDOUT: %.loc7_10.1: type = value_of_initializer %int.make_type_32.loc7 [template = i32]
  153. // CHECK:STDOUT: %.loc7_10.2: type = converted %int.make_type_32.loc7, %.loc7_10.1 [template = i32]
  154. // CHECK:STDOUT: %.loc7_8: @CompleteClass.%.1 (%.2) = field_decl n, element0 [template]
  155. // CHECK:STDOUT: %F.decl: @CompleteClass.%F.type (%F.type.1) = fn_decl @F.1 [symbolic = %F (constants.%F.1)] {
  156. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%Int32() [template = i32]
  157. // CHECK:STDOUT: %.loc8_13.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  158. // CHECK:STDOUT: %.loc8_13.2: type = converted %int.make_type_32.loc8, %.loc8_13.1 [template = i32]
  159. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: !members:
  163. // CHECK:STDOUT: .Self = constants.%CompleteClass.2
  164. // CHECK:STDOUT: .n = %.loc7_8
  165. // CHECK:STDOUT: .F = %F.decl
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: generic fn @F.1(file.%T.loc6_21.2: type) {
  172. // CHECK:STDOUT: !definition:
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: fn() -> i32 {
  175. // CHECK:STDOUT: !entry:
  176. // CHECK:STDOUT: %.loc8: i32 = int_literal 0 [template = constants.%.4]
  177. // CHECK:STDOUT: return %.loc8
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: fn @F.2() -> %CompleteClass.3;
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: specific @Class(constants.%T) {
  184. // CHECK:STDOUT: %T => constants.%T
  185. // CHECK:STDOUT: }
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: specific @CompleteClass(constants.%T) {
  188. // CHECK:STDOUT: %T => constants.%T
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: !definition:
  191. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.2
  192. // CHECK:STDOUT: %.1 => constants.%.2
  193. // CHECK:STDOUT: %F.type => constants.%F.type.1
  194. // CHECK:STDOUT: %F => constants.%F.1
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: specific @F.1(constants.%T) {}
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: specific @CompleteClass(@CompleteClass.%T) {
  200. // CHECK:STDOUT: %T => constants.%T
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: specific @CompleteClass(i32) {
  204. // CHECK:STDOUT: %T => i32
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: --- foo.impl.carbon
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: constants {
  210. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  211. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  212. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  213. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  214. // CHECK:STDOUT: %Class.2: type = class_type @Class, @Class(%T) [symbolic]
  215. // CHECK:STDOUT: %.2: type = unbound_element_type %Class.2, %T [symbolic]
  216. // CHECK:STDOUT: %.3: type = struct_type {.x: %T} [symbolic]
  217. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  218. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  219. // CHECK:STDOUT: %.4: type = struct_type {.n: i32} [template]
  220. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
  221. // CHECK:STDOUT: %.5: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
  222. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
  223. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  224. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  225. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  226. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  227. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  228. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  229. // CHECK:STDOUT: %.6: type = unbound_element_type %CompleteClass.3, i32 [template]
  230. // CHECK:STDOUT: %F.type.3: type = fn_type @F.1, @CompleteClass(i32) [template]
  231. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  232. // CHECK:STDOUT: %.7: type = ptr_type %.4 [template]
  233. // CHECK:STDOUT: %.8: i32 = int_literal 1 [template]
  234. // CHECK:STDOUT: %struct: %CompleteClass.3 = struct_value (%.8) [template]
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: imports {
  238. // CHECK:STDOUT: %import_ref.1: %Class.type = import_ref Main//foo, inst+6, loaded [template = constants.%Class.1]
  239. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
  240. // CHECK:STDOUT: %import_ref.3: %F.type.2 = import_ref Main//foo, inst+55, loaded [template = constants.%F.2]
  241. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  242. // CHECK:STDOUT: .Int32 = %import_ref.7
  243. // CHECK:STDOUT: import Core//prelude
  244. // CHECK:STDOUT: import Core//prelude/operators
  245. // CHECK:STDOUT: import Core//prelude/types
  246. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  247. // CHECK:STDOUT: import Core//prelude/operators/as
  248. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  249. // CHECK:STDOUT: import Core//prelude/operators/comparison
  250. // CHECK:STDOUT: import Core//prelude/types/bool
  251. // CHECK:STDOUT: }
  252. // CHECK:STDOUT: %import_ref.4 = import_ref Main//foo, inst+18, unloaded
  253. // CHECK:STDOUT: %import_ref.5 = import_ref Main//foo, inst+28, unloaded
  254. // CHECK:STDOUT: %import_ref.6 = import_ref Main//foo, inst+35, unloaded
  255. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: file {
  259. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  260. // CHECK:STDOUT: .Class = %Class.decl
  261. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  262. // CHECK:STDOUT: .F = %F.decl
  263. // CHECK:STDOUT: .Core = imports.%Core
  264. // CHECK:STDOUT: }
  265. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  266. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  267. // CHECK:STDOUT: %Core.import = import Core
  268. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  269. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  270. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  273. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  274. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  275. // CHECK:STDOUT: %.loc8_24.1: type = value_of_initializer %int.make_type_32 [template = i32]
  276. // CHECK:STDOUT: %.loc8_24.2: type = converted %int.make_type_32, %.loc8_24.1 [template = i32]
  277. // CHECK:STDOUT: %.loc8_24.3: init type = call %CompleteClass.ref(%.loc8_24.2) [template = constants.%CompleteClass.3]
  278. // CHECK:STDOUT: %.loc8_28.1: type = value_of_initializer %.loc8_24.3 [template = constants.%CompleteClass.3]
  279. // CHECK:STDOUT: %.loc8_28.2: type = converted %.loc8_24.3, %.loc8_28.1 [template = constants.%CompleteClass.3]
  280. // CHECK:STDOUT: @F.2.%return: ref %CompleteClass.3 = var <return slot>
  281. // CHECK:STDOUT: }
  282. // CHECK:STDOUT: }
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: generic class @Class(constants.%T: type) {
  285. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: !definition:
  288. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic = %Class (constants.%Class.2)]
  289. // CHECK:STDOUT: %.1: type = unbound_element_type @Class.%Class (%Class.2), @Class.%T (%T) [symbolic = %.1 (constants.%.2)]
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: class {
  292. // CHECK:STDOUT: %T.ref: type = name_ref T, file.%T.loc4_13.2 [symbolic = %T (constants.%T)]
  293. // CHECK:STDOUT: %.loc5: @Class.%.1 (%.2) = field_decl x, element0 [template]
  294. // CHECK:STDOUT:
  295. // CHECK:STDOUT: !members:
  296. // CHECK:STDOUT: .Self = constants.%Class.2
  297. // CHECK:STDOUT: .x = %.loc5
  298. // CHECK:STDOUT: }
  299. // CHECK:STDOUT: }
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: generic class @CompleteClass(constants.%T: type) {
  302. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  303. // CHECK:STDOUT:
  304. // CHECK:STDOUT: !definition:
  305. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  306. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.5)]
  307. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  308. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  309. // CHECK:STDOUT:
  310. // CHECK:STDOUT: class {
  311. // CHECK:STDOUT: !members:
  312. // CHECK:STDOUT: .Self = imports.%import_ref.4
  313. // CHECK:STDOUT: .n = imports.%import_ref.5
  314. // CHECK:STDOUT: .F = imports.%import_ref.6
  315. // CHECK:STDOUT: }
  316. // CHECK:STDOUT: }
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: generic fn @F.1(constants.%T: type) {
  319. // CHECK:STDOUT: !definition:
  320. // CHECK:STDOUT:
  321. // CHECK:STDOUT: fn() -> i32;
  322. // CHECK:STDOUT: }
  323. // CHECK:STDOUT:
  324. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  325. // CHECK:STDOUT:
  326. // CHECK:STDOUT: fn @F.2() -> %return: %CompleteClass.3 {
  327. // CHECK:STDOUT: !entry:
  328. // CHECK:STDOUT: %.loc9_16: i32 = int_literal 1 [template = constants.%.8]
  329. // CHECK:STDOUT: %.loc9_17.1: %.4 = struct_literal (%.loc9_16)
  330. // CHECK:STDOUT: %.loc9_17.2: ref i32 = class_element_access %return, element0
  331. // CHECK:STDOUT: %.loc9_17.3: init i32 = initialize_from %.loc9_16 to %.loc9_17.2 [template = constants.%.8]
  332. // CHECK:STDOUT: %.loc9_17.4: init %CompleteClass.3 = class_init (%.loc9_17.3), %return [template = constants.%struct]
  333. // CHECK:STDOUT: %.loc9_18: init %CompleteClass.3 = converted %.loc9_17.1, %.loc9_17.4 [template = constants.%struct]
  334. // CHECK:STDOUT: return %.loc9_18 to %return
  335. // CHECK:STDOUT: }
  336. // CHECK:STDOUT:
  337. // CHECK:STDOUT: specific @Class(constants.%T) {
  338. // CHECK:STDOUT: %T => constants.%T
  339. // CHECK:STDOUT: }
  340. // CHECK:STDOUT:
  341. // CHECK:STDOUT: specific @Class(@Class.%T) {
  342. // CHECK:STDOUT: %T => constants.%T
  343. // CHECK:STDOUT: }
  344. // CHECK:STDOUT:
  345. // CHECK:STDOUT: specific @CompleteClass(constants.%T) {
  346. // CHECK:STDOUT: %T => constants.%T
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: !definition:
  349. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.2
  350. // CHECK:STDOUT: %.1 => constants.%.5
  351. // CHECK:STDOUT: %F.type => constants.%F.type.1
  352. // CHECK:STDOUT: %F => constants.%F.1
  353. // CHECK:STDOUT: }
  354. // CHECK:STDOUT:
  355. // CHECK:STDOUT: specific @CompleteClass(@CompleteClass.%T) {
  356. // CHECK:STDOUT: %T => constants.%T
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: specific @F.1(constants.%T) {}
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: specific @CompleteClass(i32) {
  362. // CHECK:STDOUT: %T => i32
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: !definition:
  365. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.3
  366. // CHECK:STDOUT: %.1 => constants.%.6
  367. // CHECK:STDOUT: %F.type => constants.%F.type.3
  368. // CHECK:STDOUT: %F => constants.%F.3
  369. // CHECK:STDOUT: }
  370. // CHECK:STDOUT:
  371. // CHECK:STDOUT: --- use_foo.carbon
  372. // CHECK:STDOUT:
  373. // CHECK:STDOUT: constants {
  374. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  375. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  376. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  377. // CHECK:STDOUT: %UseMethod.type: type = fn_type @UseMethod [template]
  378. // CHECK:STDOUT: %UseMethod: %UseMethod.type = struct_value () [template]
  379. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  380. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  381. // CHECK:STDOUT: %.2: type = struct_type {.n: i32} [template]
  382. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  383. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
  384. // CHECK:STDOUT: %.3: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
  385. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
  386. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  387. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  388. // CHECK:STDOUT: %.4: type = unbound_element_type %CompleteClass.3, i32 [template]
  389. // CHECK:STDOUT: %F.type.2: type = fn_type @F.1, @CompleteClass(i32) [template]
  390. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  391. // CHECK:STDOUT: %.5: type = ptr_type %.2 [template]
  392. // CHECK:STDOUT: %F.type.3: type = fn_type @F.2 [template]
  393. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  394. // CHECK:STDOUT: %UseField.type: type = fn_type @UseField [template]
  395. // CHECK:STDOUT: %UseField: %UseField.type = struct_value () [template]
  396. // CHECK:STDOUT: }
  397. // CHECK:STDOUT:
  398. // CHECK:STDOUT: imports {
  399. // CHECK:STDOUT: %import_ref.1 = import_ref Main//foo, inst+6, unloaded
  400. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
  401. // CHECK:STDOUT: %import_ref.3: %F.type.3 = import_ref Main//foo, inst+55, loaded [template = constants.%F.3]
  402. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  403. // CHECK:STDOUT: .Int32 = %import_ref.4
  404. // CHECK:STDOUT: import Core//prelude
  405. // CHECK:STDOUT: import Core//prelude/operators
  406. // CHECK:STDOUT: import Core//prelude/types
  407. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  408. // CHECK:STDOUT: import Core//prelude/operators/as
  409. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  410. // CHECK:STDOUT: import Core//prelude/operators/comparison
  411. // CHECK:STDOUT: import Core//prelude/types/bool
  412. // CHECK:STDOUT: }
  413. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  414. // CHECK:STDOUT: %import_ref.5 = import_ref Main//foo, inst+18, unloaded
  415. // CHECK:STDOUT: %import_ref.6: @CompleteClass.%.1 (%.3) = import_ref Main//foo, inst+28, loaded [template = %.1]
  416. // CHECK:STDOUT: %import_ref.7: @CompleteClass.%F.type (%F.type.1) = import_ref Main//foo, inst+35, loaded [symbolic = @CompleteClass.%F (constants.%F.1)]
  417. // CHECK:STDOUT: }
  418. // CHECK:STDOUT:
  419. // CHECK:STDOUT: file {
  420. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  421. // CHECK:STDOUT: .Class = imports.%import_ref.1
  422. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  423. // CHECK:STDOUT: .F = imports.%import_ref.3
  424. // CHECK:STDOUT: .Core = imports.%Core
  425. // CHECK:STDOUT: .UseMethod = %UseMethod.decl
  426. // CHECK:STDOUT: .UseField = %UseField.decl
  427. // CHECK:STDOUT: }
  428. // CHECK:STDOUT: %Core.import = import Core
  429. // CHECK:STDOUT: %default.import = import <invalid>
  430. // CHECK:STDOUT: %UseMethod.decl: %UseMethod.type = fn_decl @UseMethod [template = constants.%UseMethod] {
  431. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  432. // CHECK:STDOUT: %.loc5_19.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  433. // CHECK:STDOUT: %.loc5_19.2: type = converted %int.make_type_32.loc5, %.loc5_19.1 [template = i32]
  434. // CHECK:STDOUT: @UseMethod.%return: ref i32 = var <return slot>
  435. // CHECK:STDOUT: }
  436. // CHECK:STDOUT: %UseField.decl: %UseField.type = fn_decl @UseField [template = constants.%UseField] {
  437. // CHECK:STDOUT: %int.make_type_32.loc10: init type = call constants.%Int32() [template = i32]
  438. // CHECK:STDOUT: %.loc10_18.1: type = value_of_initializer %int.make_type_32.loc10 [template = i32]
  439. // CHECK:STDOUT: %.loc10_18.2: type = converted %int.make_type_32.loc10, %.loc10_18.1 [template = i32]
  440. // CHECK:STDOUT: @UseField.%return: ref i32 = var <return slot>
  441. // CHECK:STDOUT: }
  442. // CHECK:STDOUT: }
  443. // CHECK:STDOUT:
  444. // CHECK:STDOUT: generic class @CompleteClass(constants.%T: type) {
  445. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  446. // CHECK:STDOUT:
  447. // CHECK:STDOUT: !definition:
  448. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  449. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.3)]
  450. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  451. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  452. // CHECK:STDOUT:
  453. // CHECK:STDOUT: class {
  454. // CHECK:STDOUT: !members:
  455. // CHECK:STDOUT: .Self = imports.%import_ref.5
  456. // CHECK:STDOUT: .n = imports.%import_ref.6
  457. // CHECK:STDOUT: .F = imports.%import_ref.7
  458. // CHECK:STDOUT: }
  459. // CHECK:STDOUT: }
  460. // CHECK:STDOUT:
  461. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  462. // CHECK:STDOUT:
  463. // CHECK:STDOUT: fn @UseMethod() -> i32 {
  464. // CHECK:STDOUT: !entry:
  465. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  466. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  467. // CHECK:STDOUT: %.loc6_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
  468. // CHECK:STDOUT: %.loc6_23.2: type = converted %int.make_type_32, %.loc6_23.1 [template = i32]
  469. // CHECK:STDOUT: %.loc6_23.3: init type = call %CompleteClass.ref(%.loc6_23.2) [template = constants.%CompleteClass.3]
  470. // CHECK:STDOUT: %.loc6_27.1: type = value_of_initializer %.loc6_23.3 [template = constants.%CompleteClass.3]
  471. // CHECK:STDOUT: %.loc6_27.2: type = converted %.loc6_23.3, %.loc6_27.1 [template = constants.%CompleteClass.3]
  472. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  473. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  474. // CHECK:STDOUT: %F.ref.loc6: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
  475. // CHECK:STDOUT: %.loc6_7: ref %CompleteClass.3 = splice_block %v.var {}
  476. // CHECK:STDOUT: %F.call.loc6: init %CompleteClass.3 = call %F.ref.loc6() to %.loc6_7
  477. // CHECK:STDOUT: assign %v.var, %F.call.loc6
  478. // CHECK:STDOUT: %v.ref: ref %CompleteClass.3 = name_ref v, %v
  479. // CHECK:STDOUT: %.loc7_11: %F.type.2 = specific_constant imports.%import_ref.7, @CompleteClass(i32) [template = constants.%F.2]
  480. // CHECK:STDOUT: %F.ref.loc7: %F.type.2 = name_ref F, %.loc7_11 [template = constants.%F.2]
  481. // CHECK:STDOUT: %F.call.loc7: init i32 = call %F.ref.loc7()
  482. // CHECK:STDOUT: %.loc7_15.1: i32 = value_of_initializer %F.call.loc7
  483. // CHECK:STDOUT: %.loc7_15.2: i32 = converted %F.call.loc7, %.loc7_15.1
  484. // CHECK:STDOUT: return %.loc7_15.2
  485. // CHECK:STDOUT: }
  486. // CHECK:STDOUT:
  487. // CHECK:STDOUT: generic fn @F.1(constants.%T: type) {
  488. // CHECK:STDOUT: !definition:
  489. // CHECK:STDOUT:
  490. // CHECK:STDOUT: fn() -> i32;
  491. // CHECK:STDOUT: }
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: fn @F.2() -> %CompleteClass.3;
  494. // CHECK:STDOUT:
  495. // CHECK:STDOUT: fn @UseField() -> i32 {
  496. // CHECK:STDOUT: !entry:
  497. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  498. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  499. // CHECK:STDOUT: %.loc11_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
  500. // CHECK:STDOUT: %.loc11_23.2: type = converted %int.make_type_32, %.loc11_23.1 [template = i32]
  501. // CHECK:STDOUT: %.loc11_23.3: init type = call %CompleteClass.ref(%.loc11_23.2) [template = constants.%CompleteClass.3]
  502. // CHECK:STDOUT: %.loc11_27.1: type = value_of_initializer %.loc11_23.3 [template = constants.%CompleteClass.3]
  503. // CHECK:STDOUT: %.loc11_27.2: type = converted %.loc11_23.3, %.loc11_27.1 [template = constants.%CompleteClass.3]
  504. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  505. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  506. // CHECK:STDOUT: %F.ref: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
  507. // CHECK:STDOUT: %.loc11_7: ref %CompleteClass.3 = splice_block %v.var {}
  508. // CHECK:STDOUT: %F.call: init %CompleteClass.3 = call %F.ref() to %.loc11_7
  509. // CHECK:STDOUT: assign %v.var, %F.call
  510. // CHECK:STDOUT: %v.ref: ref %CompleteClass.3 = name_ref v, %v
  511. // CHECK:STDOUT: %n.ref: %.4 = name_ref n, imports.%import_ref.6 [template = imports.%.1]
  512. // CHECK:STDOUT: %.loc12_11.1: ref i32 = class_element_access %v.ref, element0
  513. // CHECK:STDOUT: %.loc12_11.2: i32 = bind_value %.loc12_11.1
  514. // CHECK:STDOUT: return %.loc12_11.2
  515. // CHECK:STDOUT: }
  516. // CHECK:STDOUT:
  517. // CHECK:STDOUT: specific @CompleteClass(constants.%T) {
  518. // CHECK:STDOUT: %T => constants.%T
  519. // CHECK:STDOUT:
  520. // CHECK:STDOUT: !definition:
  521. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.2
  522. // CHECK:STDOUT: %.1 => constants.%.3
  523. // CHECK:STDOUT: %F.type => constants.%F.type.1
  524. // CHECK:STDOUT: %F => constants.%F.1
  525. // CHECK:STDOUT: }
  526. // CHECK:STDOUT:
  527. // CHECK:STDOUT: specific @CompleteClass(@CompleteClass.%T) {
  528. // CHECK:STDOUT: %T => constants.%T
  529. // CHECK:STDOUT: }
  530. // CHECK:STDOUT:
  531. // CHECK:STDOUT: specific @F.1(constants.%T) {}
  532. // CHECK:STDOUT:
  533. // CHECK:STDOUT: specific @CompleteClass(i32) {
  534. // CHECK:STDOUT: %T => i32
  535. // CHECK:STDOUT:
  536. // CHECK:STDOUT: !definition:
  537. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.3
  538. // CHECK:STDOUT: %.1 => constants.%.4
  539. // CHECK:STDOUT: %F.type => constants.%F.type.2
  540. // CHECK:STDOUT: %F => constants.%F.2
  541. // CHECK:STDOUT: }
  542. // CHECK:STDOUT:
  543. // CHECK:STDOUT: specific @F.1(i32) {}
  544. // CHECK:STDOUT:
  545. // CHECK:STDOUT: --- fail_generic_arg_mismatch.carbon
  546. // CHECK:STDOUT:
  547. // CHECK:STDOUT: constants {
  548. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  549. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  550. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  551. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  552. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  553. // CHECK:STDOUT: %.2: type = struct_type {.n: i32} [template]
  554. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  555. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
  556. // CHECK:STDOUT: %.3: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
  557. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
  558. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  559. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  560. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  561. // CHECK:STDOUT: %.4: type = ptr_type i32 [template]
  562. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(%.4) [template]
  563. // CHECK:STDOUT: %.5: type = unbound_element_type %CompleteClass.3, i32 [template]
  564. // CHECK:STDOUT: %F.type.2: type = fn_type @F.1, @CompleteClass(%.4) [template]
  565. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  566. // CHECK:STDOUT: %.6: type = ptr_type %.2 [template]
  567. // CHECK:STDOUT: %F.type.3: type = fn_type @F.2 [template]
  568. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  569. // CHECK:STDOUT: %CompleteClass.4: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  570. // CHECK:STDOUT: %.7: type = unbound_element_type %CompleteClass.4, i32 [template]
  571. // CHECK:STDOUT: %F.type.4: type = fn_type @F.1, @CompleteClass(i32) [template]
  572. // CHECK:STDOUT: %F.4: %F.type.4 = struct_value () [template]
  573. // CHECK:STDOUT: %ImplicitAs.type: type = generic_interface_type @ImplicitAs [template]
  574. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type = struct_value () [template]
  575. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic]
  576. // CHECK:STDOUT: %.8: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  577. // CHECK:STDOUT: %Self.1: @ImplicitAs.%.1 (%.8) = bind_symbolic_name Self 1 [symbolic]
  578. // CHECK:STDOUT: %Self.2: %.8 = bind_symbolic_name Self 1 [symbolic]
  579. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  580. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  581. // CHECK:STDOUT: %.9: type = assoc_entity_type %.8, %Convert.type.1 [symbolic]
  582. // CHECK:STDOUT: %.10: %.9 = assoc_entity element0, imports.%import_ref.12 [symbolic]
  583. // CHECK:STDOUT: %.11: type = interface_type @ImplicitAs, @ImplicitAs(%CompleteClass.3) [template]
  584. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(%CompleteClass.3) [template]
  585. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  586. // CHECK:STDOUT: %.12: type = assoc_entity_type %.11, %Convert.type.2 [template]
  587. // CHECK:STDOUT: %.13: %.12 = assoc_entity element0, imports.%import_ref.12 [template]
  588. // CHECK:STDOUT: %.14: %.9 = assoc_entity element0, imports.%import_ref.13 [symbolic]
  589. // CHECK:STDOUT: }
  590. // CHECK:STDOUT:
  591. // CHECK:STDOUT: imports {
  592. // CHECK:STDOUT: %import_ref.1 = import_ref Main//foo, inst+6, unloaded
  593. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
  594. // CHECK:STDOUT: %import_ref.3: %F.type.3 = import_ref Main//foo, inst+55, loaded [template = constants.%F.3]
  595. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  596. // CHECK:STDOUT: .Int32 = %import_ref.7
  597. // CHECK:STDOUT: .ImplicitAs = %import_ref.8
  598. // CHECK:STDOUT: import Core//prelude
  599. // CHECK:STDOUT: import Core//prelude/operators
  600. // CHECK:STDOUT: import Core//prelude/types
  601. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  602. // CHECK:STDOUT: import Core//prelude/operators/as
  603. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  604. // CHECK:STDOUT: import Core//prelude/operators/comparison
  605. // CHECK:STDOUT: import Core//prelude/types/bool
  606. // CHECK:STDOUT: }
  607. // CHECK:STDOUT: %import_ref.4 = import_ref Main//foo, inst+18, unloaded
  608. // CHECK:STDOUT: %import_ref.5 = import_ref Main//foo, inst+28, unloaded
  609. // CHECK:STDOUT: %import_ref.6 = import_ref Main//foo, inst+35, unloaded
  610. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  611. // CHECK:STDOUT: %import_ref.8: %ImplicitAs.type = import_ref Core//prelude/operators/as, inst+37, loaded [template = constants.%ImplicitAs]
  612. // CHECK:STDOUT: %import_ref.9 = import_ref Core//prelude/operators/as, inst+42, unloaded
  613. // CHECK:STDOUT: %import_ref.10: @ImplicitAs.%.2 (%.9) = import_ref Core//prelude/operators/as, inst+59, loaded [symbolic = @ImplicitAs.%.3 (constants.%.14)]
  614. // CHECK:STDOUT: %import_ref.11 = import_ref Core//prelude/operators/as, inst+52, unloaded
  615. // CHECK:STDOUT: %import_ref.12 = import_ref Core//prelude/operators/as, inst+52, unloaded
  616. // CHECK:STDOUT: %import_ref.13 = import_ref Core//prelude/operators/as, inst+52, unloaded
  617. // CHECK:STDOUT: }
  618. // CHECK:STDOUT:
  619. // CHECK:STDOUT: file {
  620. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  621. // CHECK:STDOUT: .Class = imports.%import_ref.1
  622. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  623. // CHECK:STDOUT: .F = imports.%import_ref.3
  624. // CHECK:STDOUT: .Core = imports.%Core
  625. // CHECK:STDOUT: .Use = %Use.decl
  626. // CHECK:STDOUT: }
  627. // CHECK:STDOUT: %Core.import = import Core
  628. // CHECK:STDOUT: %default.import = import <invalid>
  629. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {}
  630. // CHECK:STDOUT: }
  631. // CHECK:STDOUT:
  632. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  633. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  634. // CHECK:STDOUT:
  635. // CHECK:STDOUT: !definition:
  636. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.8)]
  637. // CHECK:STDOUT: %Self: %.8 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  638. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  639. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  640. // CHECK:STDOUT: %.2: type = assoc_entity_type @ImplicitAs.%.1 (%.8), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.2 (constants.%.9)]
  641. // CHECK:STDOUT: %.3: @ImplicitAs.%.2 (%.9) = assoc_entity element0, imports.%import_ref.12 [symbolic = %.3 (constants.%.10)]
  642. // CHECK:STDOUT:
  643. // CHECK:STDOUT: interface {
  644. // CHECK:STDOUT: !members:
  645. // CHECK:STDOUT: .Self = imports.%import_ref.9
  646. // CHECK:STDOUT: .Convert = imports.%import_ref.10
  647. // CHECK:STDOUT: witness = (imports.%import_ref.11)
  648. // CHECK:STDOUT: }
  649. // CHECK:STDOUT: }
  650. // CHECK:STDOUT:
  651. // CHECK:STDOUT: generic class @CompleteClass(constants.%T: type) {
  652. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  653. // CHECK:STDOUT:
  654. // CHECK:STDOUT: !definition:
  655. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  656. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.3)]
  657. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  658. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  659. // CHECK:STDOUT:
  660. // CHECK:STDOUT: class {
  661. // CHECK:STDOUT: !members:
  662. // CHECK:STDOUT: .Self = imports.%import_ref.4
  663. // CHECK:STDOUT: .n = imports.%import_ref.5
  664. // CHECK:STDOUT: .F = imports.%import_ref.6
  665. // CHECK:STDOUT: }
  666. // CHECK:STDOUT: }
  667. // CHECK:STDOUT:
  668. // CHECK:STDOUT: fn @Use() {
  669. // CHECK:STDOUT: !entry:
  670. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  671. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  672. // CHECK:STDOUT: %.loc14_27.1: type = value_of_initializer %int.make_type_32 [template = i32]
  673. // CHECK:STDOUT: %.loc14_27.2: type = converted %int.make_type_32, %.loc14_27.1 [template = i32]
  674. // CHECK:STDOUT: %.loc14_27.3: type = ptr_type i32 [template = constants.%.4]
  675. // CHECK:STDOUT: %.loc14_23: init type = call %CompleteClass.ref(%.loc14_27.3) [template = constants.%CompleteClass.3]
  676. // CHECK:STDOUT: %.loc14_28.1: type = value_of_initializer %.loc14_23 [template = constants.%CompleteClass.3]
  677. // CHECK:STDOUT: %.loc14_28.2: type = converted %.loc14_23, %.loc14_28.1 [template = constants.%CompleteClass.3]
  678. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  679. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  680. // CHECK:STDOUT: %F.ref: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
  681. // CHECK:STDOUT: %.loc14_33.1: ref %CompleteClass.4 = temporary_storage
  682. // CHECK:STDOUT: %F.call: init %CompleteClass.4 = call %F.ref() to %.loc14_33.1
  683. // CHECK:STDOUT: %.loc14_35.1: init type = call constants.%ImplicitAs(constants.%CompleteClass.3) [template = constants.%.11]
  684. // CHECK:STDOUT: %.loc14_35.2: %.12 = specific_constant imports.%import_ref.10, @ImplicitAs(constants.%CompleteClass.3) [template = constants.%.13]
  685. // CHECK:STDOUT: %Convert.ref: %.12 = name_ref Convert, %.loc14_35.2 [template = constants.%.13]
  686. // CHECK:STDOUT: %.loc14_33.2: ref %CompleteClass.4 = temporary %.loc14_33.1, %F.call
  687. // CHECK:STDOUT: %.loc14_35.3: %CompleteClass.3 = converted %F.call, <error> [template = <error>]
  688. // CHECK:STDOUT: assign %v.var, <error>
  689. // CHECK:STDOUT: return
  690. // CHECK:STDOUT: }
  691. // CHECK:STDOUT:
  692. // CHECK:STDOUT: generic fn @F.1(constants.%T: type) {
  693. // CHECK:STDOUT: !definition:
  694. // CHECK:STDOUT:
  695. // CHECK:STDOUT: fn() -> i32;
  696. // CHECK:STDOUT: }
  697. // CHECK:STDOUT:
  698. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  699. // CHECK:STDOUT:
  700. // CHECK:STDOUT: fn @F.2() -> %CompleteClass.4;
  701. // CHECK:STDOUT:
  702. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%.1 (%.8)) {
  703. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  704. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.8)]
  705. // CHECK:STDOUT: %Self: %.8 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  706. // CHECK:STDOUT:
  707. // CHECK:STDOUT: fn[%self: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  708. // CHECK:STDOUT: }
  709. // CHECK:STDOUT:
  710. // CHECK:STDOUT: specific @CompleteClass(constants.%T) {
  711. // CHECK:STDOUT: %T => constants.%T
  712. // CHECK:STDOUT:
  713. // CHECK:STDOUT: !definition:
  714. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.2
  715. // CHECK:STDOUT: %.1 => constants.%.3
  716. // CHECK:STDOUT: %F.type => constants.%F.type.1
  717. // CHECK:STDOUT: %F => constants.%F.1
  718. // CHECK:STDOUT: }
  719. // CHECK:STDOUT:
  720. // CHECK:STDOUT: specific @CompleteClass(@CompleteClass.%T) {
  721. // CHECK:STDOUT: %T => constants.%T
  722. // CHECK:STDOUT: }
  723. // CHECK:STDOUT:
  724. // CHECK:STDOUT: specific @F.1(constants.%T) {}
  725. // CHECK:STDOUT:
  726. // CHECK:STDOUT: specific @CompleteClass(constants.%.4) {
  727. // CHECK:STDOUT: %T => constants.%.4
  728. // CHECK:STDOUT:
  729. // CHECK:STDOUT: !definition:
  730. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.3
  731. // CHECK:STDOUT: %.1 => constants.%.5
  732. // CHECK:STDOUT: %F.type => constants.%F.type.2
  733. // CHECK:STDOUT: %F => constants.%F.2
  734. // CHECK:STDOUT: }
  735. // CHECK:STDOUT:
  736. // CHECK:STDOUT: specific @CompleteClass(i32) {
  737. // CHECK:STDOUT: %T => i32
  738. // CHECK:STDOUT:
  739. // CHECK:STDOUT: !definition:
  740. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.4
  741. // CHECK:STDOUT: %.1 => constants.%.7
  742. // CHECK:STDOUT: %F.type => constants.%F.type.4
  743. // CHECK:STDOUT: %F => constants.%F.4
  744. // CHECK:STDOUT: }
  745. // CHECK:STDOUT:
  746. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  747. // CHECK:STDOUT: %Dest => constants.%Dest
  748. // CHECK:STDOUT: }
  749. // CHECK:STDOUT:
  750. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  751. // CHECK:STDOUT: %Dest => constants.%Dest
  752. // CHECK:STDOUT: }
  753. // CHECK:STDOUT:
  754. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  755. // CHECK:STDOUT: %Dest => constants.%Dest
  756. // CHECK:STDOUT: }
  757. // CHECK:STDOUT:
  758. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  759. // CHECK:STDOUT: %Dest => constants.%Dest
  760. // CHECK:STDOUT: %.1 => constants.%.8
  761. // CHECK:STDOUT: %Self => constants.%Self.1
  762. // CHECK:STDOUT: }
  763. // CHECK:STDOUT:
  764. // CHECK:STDOUT: specific @ImplicitAs(constants.%CompleteClass.3) {
  765. // CHECK:STDOUT: %Dest => constants.%CompleteClass.3
  766. // CHECK:STDOUT:
  767. // CHECK:STDOUT: !definition:
  768. // CHECK:STDOUT: %.1 => constants.%.11
  769. // CHECK:STDOUT: %Self => constants.%Self.2
  770. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  771. // CHECK:STDOUT: %Convert => constants.%Convert.2
  772. // CHECK:STDOUT: %.2 => constants.%.12
  773. // CHECK:STDOUT: %.3 => constants.%.13
  774. // CHECK:STDOUT: }
  775. // CHECK:STDOUT:
  776. // CHECK:STDOUT: --- fail_foo.impl.carbon
  777. // CHECK:STDOUT:
  778. // CHECK:STDOUT: constants {
  779. // CHECK:STDOUT: %U: type = bind_symbolic_name U 0 [symbolic]
  780. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  781. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  782. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  783. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  784. // CHECK:STDOUT: %Class.2: type = class_type @Class, @Class(%T) [symbolic]
  785. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  786. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  787. // CHECK:STDOUT: %.3: type = class_type @.1, @.1(%U) [symbolic]
  788. // CHECK:STDOUT: }
  789. // CHECK:STDOUT:
  790. // CHECK:STDOUT: imports {
  791. // CHECK:STDOUT: %import_ref.1: %Class.type = import_ref Main//foo, inst+6, loaded [template = constants.%Class.1]
  792. // CHECK:STDOUT: %import_ref.2 = import_ref Main//foo, inst+14, unloaded
  793. // CHECK:STDOUT: %import_ref.3 = import_ref Main//foo, inst+55, unloaded
  794. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  795. // CHECK:STDOUT: import Core//prelude
  796. // CHECK:STDOUT: import Core//prelude/operators
  797. // CHECK:STDOUT: import Core//prelude/types
  798. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  799. // CHECK:STDOUT: import Core//prelude/operators/as
  800. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  801. // CHECK:STDOUT: import Core//prelude/operators/comparison
  802. // CHECK:STDOUT: import Core//prelude/types/bool
  803. // CHECK:STDOUT: }
  804. // CHECK:STDOUT: }
  805. // CHECK:STDOUT:
  806. // CHECK:STDOUT: file {
  807. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  808. // CHECK:STDOUT: .Class = imports.%import_ref.1
  809. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  810. // CHECK:STDOUT: .F = imports.%import_ref.3
  811. // CHECK:STDOUT: .Core = imports.%Core
  812. // CHECK:STDOUT: }
  813. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  814. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  815. // CHECK:STDOUT: %Core.import = import Core
  816. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  817. // CHECK:STDOUT: %U.loc14_13.1: type = param U
  818. // CHECK:STDOUT: %U.loc14_13.2: type = bind_symbolic_name U 0, %U.loc14_13.1 [symbolic = @.1.%U (constants.%U)]
  819. // CHECK:STDOUT: }
  820. // CHECK:STDOUT: }
  821. // CHECK:STDOUT:
  822. // CHECK:STDOUT: generic class @Class(constants.%T: type) {
  823. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  824. // CHECK:STDOUT:
  825. // CHECK:STDOUT: class;
  826. // CHECK:STDOUT: }
  827. // CHECK:STDOUT:
  828. // CHECK:STDOUT: generic class @.1(file.%U.loc14_13.2: type) {
  829. // CHECK:STDOUT: %U: type = bind_symbolic_name U 0 [symbolic = %U (constants.%U)]
  830. // CHECK:STDOUT:
  831. // CHECK:STDOUT: !definition:
  832. // CHECK:STDOUT:
  833. // CHECK:STDOUT: class {
  834. // CHECK:STDOUT: %T.ref: <error> = name_ref T, <error> [template = <error>]
  835. // CHECK:STDOUT: %.loc18: <error> = field_decl x, element0 [template]
  836. // CHECK:STDOUT:
  837. // CHECK:STDOUT: !members:
  838. // CHECK:STDOUT: .Self = constants.%.3
  839. // CHECK:STDOUT: .x = %.loc18
  840. // CHECK:STDOUT: }
  841. // CHECK:STDOUT: }
  842. // CHECK:STDOUT:
  843. // CHECK:STDOUT: specific @Class(constants.%T) {
  844. // CHECK:STDOUT: %T => constants.%T
  845. // CHECK:STDOUT: }
  846. // CHECK:STDOUT:
  847. // CHECK:STDOUT: specific @.1(constants.%U) {
  848. // CHECK:STDOUT: %U => constants.%U
  849. // CHECK:STDOUT: }
  850. // CHECK:STDOUT: