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: <witness> = complete_type_witness %.3 [template]
  87. // CHECK:STDOUT: %.5: i32 = int_literal 0 [template]
  88. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  89. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  90. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: imports {
  94. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  95. // CHECK:STDOUT: .Int32 = %import_ref
  96. // CHECK:STDOUT: import Core//prelude
  97. // CHECK:STDOUT: import Core//prelude/operators
  98. // CHECK:STDOUT: import Core//prelude/types
  99. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  100. // CHECK:STDOUT: import Core//prelude/operators/as
  101. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  102. // CHECK:STDOUT: import Core//prelude/operators/comparison
  103. // CHECK:STDOUT: import Core//prelude/types/bool
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: file {
  109. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  110. // CHECK:STDOUT: .Core = imports.%Core
  111. // CHECK:STDOUT: .Class = %Class.decl
  112. // CHECK:STDOUT: .CompleteClass = %CompleteClass.decl
  113. // CHECK:STDOUT: .F = %F.decl
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %Core.import = import Core
  116. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  117. // CHECK:STDOUT: %T.loc4_13.1: type = param T, runtime_param<invalid>
  118. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = @Class.%T (constants.%T)]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %CompleteClass.decl: %CompleteClass.type = class_decl @CompleteClass [template = constants.%CompleteClass.1] {
  121. // CHECK:STDOUT: %T.loc6_21.1: type = param T, runtime_param<invalid>
  122. // CHECK:STDOUT: %T.loc6_21.2: type = bind_symbolic_name T 0, %T.loc6_21.1 [symbolic = @CompleteClass.%T (constants.%T)]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  125. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, %CompleteClass.decl [template = constants.%CompleteClass.1]
  126. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  127. // CHECK:STDOUT: %.loc11_24.1: type = value_of_initializer %int.make_type_32 [template = i32]
  128. // CHECK:STDOUT: %.loc11_24.2: type = converted %int.make_type_32, %.loc11_24.1 [template = i32]
  129. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(i32) [template = constants.%CompleteClass.3]
  130. // CHECK:STDOUT: @F.2.%return: ref %CompleteClass.3 = var <return slot>
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: generic class @Class(file.%T.loc4_13.2: type) {
  135. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: class;
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: generic class @CompleteClass(file.%T.loc6_21.2: type) {
  141. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: !definition:
  144. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  145. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.2)]
  146. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  147. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: class {
  150. // CHECK:STDOUT: %int.make_type_32.loc7: init type = call constants.%Int32() [template = i32]
  151. // CHECK:STDOUT: %.loc7_10.1: type = value_of_initializer %int.make_type_32.loc7 [template = i32]
  152. // CHECK:STDOUT: %.loc7_10.2: type = converted %int.make_type_32.loc7, %.loc7_10.1 [template = i32]
  153. // CHECK:STDOUT: %.loc7_8: @CompleteClass.%.1 (%.2) = field_decl n, element0 [template]
  154. // CHECK:STDOUT: %F.decl: @CompleteClass.%F.type (%F.type.1) = fn_decl @F.1 [symbolic = %F (constants.%F.1)] {
  155. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%Int32() [template = i32]
  156. // CHECK:STDOUT: %.loc8_13.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  157. // CHECK:STDOUT: %.loc8_13.2: type = converted %int.make_type_32.loc8, %.loc8_13.1 [template = i32]
  158. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.3 [template = constants.%.4]
  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.%.5]
  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: %.4: <witness> = complete_type_witness %.3 [symbolic]
  218. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  219. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  220. // CHECK:STDOUT: %.5: type = struct_type {.n: i32} [template]
  221. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %.5 [template]
  222. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
  223. // CHECK:STDOUT: %.7: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
  224. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
  225. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  226. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  227. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  228. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  229. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  230. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  231. // CHECK:STDOUT: %.8: type = unbound_element_type %CompleteClass.3, i32 [template]
  232. // CHECK:STDOUT: %F.type.3: type = fn_type @F.1, @CompleteClass(i32) [template]
  233. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  234. // CHECK:STDOUT: %.9: type = ptr_type %.5 [template]
  235. // CHECK:STDOUT: %.10: i32 = int_literal 1 [template]
  236. // CHECK:STDOUT: %struct: %CompleteClass.3 = struct_value (%.10) [template]
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: imports {
  240. // CHECK:STDOUT: %import_ref.1: %Class.type = import_ref Main//foo, inst+6, loaded [template = constants.%Class.1]
  241. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
  242. // CHECK:STDOUT: %import_ref.3: %F.type.2 = import_ref Main//foo, inst+55, loaded [template = constants.%F.2]
  243. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  244. // CHECK:STDOUT: .Int32 = %import_ref.7
  245. // CHECK:STDOUT: import Core//prelude
  246. // CHECK:STDOUT: import Core//prelude/operators
  247. // CHECK:STDOUT: import Core//prelude/types
  248. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  249. // CHECK:STDOUT: import Core//prelude/operators/as
  250. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  251. // CHECK:STDOUT: import Core//prelude/operators/comparison
  252. // CHECK:STDOUT: import Core//prelude/types/bool
  253. // CHECK:STDOUT: }
  254. // CHECK:STDOUT: %import_ref.4 = import_ref Main//foo, inst+18, unloaded
  255. // CHECK:STDOUT: %import_ref.5 = import_ref Main//foo, inst+28, unloaded
  256. // CHECK:STDOUT: %import_ref.6 = import_ref Main//foo, inst+35, unloaded
  257. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: file {
  261. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  262. // CHECK:STDOUT: .Class = %Class.decl
  263. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  264. // CHECK:STDOUT: .F = %F.decl
  265. // CHECK:STDOUT: .Core = imports.%Core
  266. // CHECK:STDOUT: }
  267. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  268. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  269. // CHECK:STDOUT: %Core.import = import Core
  270. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  271. // CHECK:STDOUT: %T.loc4_13.1: type = param T, runtime_param<invalid>
  272. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  273. // CHECK:STDOUT: }
  274. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  275. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  276. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  277. // CHECK:STDOUT: %.loc8_24.1: type = value_of_initializer %int.make_type_32 [template = i32]
  278. // CHECK:STDOUT: %.loc8_24.2: type = converted %int.make_type_32, %.loc8_24.1 [template = i32]
  279. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(i32) [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: %.2: type = struct_type {.x: @Class.%T (%T)} [symbolic = %.2 (constants.%.3)]
  291. // CHECK:STDOUT: %.3: <witness> = complete_type_witness @Class.%.2 (%.3) [symbolic = %.3 (constants.%.4)]
  292. // CHECK:STDOUT:
  293. // CHECK:STDOUT: class {
  294. // CHECK:STDOUT: %T.ref: type = name_ref T, file.%T.loc4_13.2 [symbolic = %T (constants.%T)]
  295. // CHECK:STDOUT: %.loc5: @Class.%.1 (%.2) = field_decl x, element0 [template]
  296. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.3 [symbolic = %.3 (constants.%.4)]
  297. // CHECK:STDOUT:
  298. // CHECK:STDOUT: !members:
  299. // CHECK:STDOUT: .Self = constants.%Class.2
  300. // CHECK:STDOUT: .x = %.loc5
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT: }
  303. // CHECK:STDOUT:
  304. // CHECK:STDOUT: generic class @CompleteClass(constants.%T: type) {
  305. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  306. // CHECK:STDOUT:
  307. // CHECK:STDOUT: !definition:
  308. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  309. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.7)]
  310. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  311. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  312. // CHECK:STDOUT:
  313. // CHECK:STDOUT: class {
  314. // CHECK:STDOUT: !members:
  315. // CHECK:STDOUT: .Self = imports.%import_ref.4
  316. // CHECK:STDOUT: .n = imports.%import_ref.5
  317. // CHECK:STDOUT: .F = imports.%import_ref.6
  318. // CHECK:STDOUT: }
  319. // CHECK:STDOUT: }
  320. // CHECK:STDOUT:
  321. // CHECK:STDOUT: generic fn @F.1(constants.%T: type) {
  322. // CHECK:STDOUT: !definition:
  323. // CHECK:STDOUT:
  324. // CHECK:STDOUT: fn() -> i32;
  325. // CHECK:STDOUT: }
  326. // CHECK:STDOUT:
  327. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: fn @F.2() -> %return: %CompleteClass.3 {
  330. // CHECK:STDOUT: !entry:
  331. // CHECK:STDOUT: %.loc9_16: i32 = int_literal 1 [template = constants.%.10]
  332. // CHECK:STDOUT: %.loc9_17.1: %.5 = struct_literal (%.loc9_16)
  333. // CHECK:STDOUT: %.loc9_17.2: ref i32 = class_element_access %return, element0
  334. // CHECK:STDOUT: %.loc9_17.3: init i32 = initialize_from %.loc9_16 to %.loc9_17.2 [template = constants.%.10]
  335. // CHECK:STDOUT: %.loc9_17.4: init %CompleteClass.3 = class_init (%.loc9_17.3), %return [template = constants.%struct]
  336. // CHECK:STDOUT: %.loc9_18: init %CompleteClass.3 = converted %.loc9_17.1, %.loc9_17.4 [template = constants.%struct]
  337. // CHECK:STDOUT: return %.loc9_18 to %return
  338. // CHECK:STDOUT: }
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: specific @Class(constants.%T) {
  341. // CHECK:STDOUT: %T => constants.%T
  342. // CHECK:STDOUT: }
  343. // CHECK:STDOUT:
  344. // CHECK:STDOUT: specific @Class(@Class.%T) {
  345. // CHECK:STDOUT: %T => constants.%T
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: specific @CompleteClass(constants.%T) {
  349. // CHECK:STDOUT: %T => constants.%T
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: !definition:
  352. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.2
  353. // CHECK:STDOUT: %.1 => constants.%.7
  354. // CHECK:STDOUT: %F.type => constants.%F.type.1
  355. // CHECK:STDOUT: %F => constants.%F.1
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT:
  358. // CHECK:STDOUT: specific @CompleteClass(@CompleteClass.%T) {
  359. // CHECK:STDOUT: %T => constants.%T
  360. // CHECK:STDOUT: }
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: specific @F.1(constants.%T) {}
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: specific @CompleteClass(i32) {
  365. // CHECK:STDOUT: %T => i32
  366. // CHECK:STDOUT:
  367. // CHECK:STDOUT: !definition:
  368. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.3
  369. // CHECK:STDOUT: %.1 => constants.%.8
  370. // CHECK:STDOUT: %F.type => constants.%F.type.3
  371. // CHECK:STDOUT: %F => constants.%F.3
  372. // CHECK:STDOUT: }
  373. // CHECK:STDOUT:
  374. // CHECK:STDOUT: --- use_foo.carbon
  375. // CHECK:STDOUT:
  376. // CHECK:STDOUT: constants {
  377. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  378. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  379. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  380. // CHECK:STDOUT: %UseMethod.type: type = fn_type @UseMethod [template]
  381. // CHECK:STDOUT: %UseMethod: %UseMethod.type = struct_value () [template]
  382. // CHECK:STDOUT: %CompleteClass.type: type = generic_class_type @CompleteClass [template]
  383. // CHECK:STDOUT: %CompleteClass.1: %CompleteClass.type = struct_value () [template]
  384. // CHECK:STDOUT: %.2: type = struct_type {.n: i32} [template]
  385. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  386. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  387. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
  388. // CHECK:STDOUT: %.4: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
  389. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
  390. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  391. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  392. // CHECK:STDOUT: %.5: type = unbound_element_type %CompleteClass.3, i32 [template]
  393. // CHECK:STDOUT: %F.type.2: type = fn_type @F.1, @CompleteClass(i32) [template]
  394. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  395. // CHECK:STDOUT: %.6: type = ptr_type %.2 [template]
  396. // CHECK:STDOUT: %F.type.3: type = fn_type @F.2 [template]
  397. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  398. // CHECK:STDOUT: %UseField.type: type = fn_type @UseField [template]
  399. // CHECK:STDOUT: %UseField: %UseField.type = struct_value () [template]
  400. // CHECK:STDOUT: }
  401. // CHECK:STDOUT:
  402. // CHECK:STDOUT: imports {
  403. // CHECK:STDOUT: %import_ref.1 = import_ref Main//foo, inst+6, unloaded
  404. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
  405. // CHECK:STDOUT: %import_ref.3: %F.type.3 = import_ref Main//foo, inst+55, loaded [template = constants.%F.3]
  406. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  407. // CHECK:STDOUT: .Int32 = %import_ref.4
  408. // CHECK:STDOUT: import Core//prelude
  409. // CHECK:STDOUT: import Core//prelude/operators
  410. // CHECK:STDOUT: import Core//prelude/types
  411. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  412. // CHECK:STDOUT: import Core//prelude/operators/as
  413. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  414. // CHECK:STDOUT: import Core//prelude/operators/comparison
  415. // CHECK:STDOUT: import Core//prelude/types/bool
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  418. // CHECK:STDOUT: %import_ref.5 = import_ref Main//foo, inst+18, unloaded
  419. // CHECK:STDOUT: %import_ref.6: @CompleteClass.%.1 (%.4) = import_ref Main//foo, inst+28, loaded [template = %.1]
  420. // CHECK:STDOUT: %import_ref.7: @CompleteClass.%F.type (%F.type.1) = import_ref Main//foo, inst+35, loaded [symbolic = @CompleteClass.%F (constants.%F.1)]
  421. // CHECK:STDOUT: }
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: file {
  424. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  425. // CHECK:STDOUT: .Class = imports.%import_ref.1
  426. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  427. // CHECK:STDOUT: .F = imports.%import_ref.3
  428. // CHECK:STDOUT: .Core = imports.%Core
  429. // CHECK:STDOUT: .UseMethod = %UseMethod.decl
  430. // CHECK:STDOUT: .UseField = %UseField.decl
  431. // CHECK:STDOUT: }
  432. // CHECK:STDOUT: %Core.import = import Core
  433. // CHECK:STDOUT: %default.import = import <invalid>
  434. // CHECK:STDOUT: %UseMethod.decl: %UseMethod.type = fn_decl @UseMethod [template = constants.%UseMethod] {
  435. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  436. // CHECK:STDOUT: %.loc5_19.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  437. // CHECK:STDOUT: %.loc5_19.2: type = converted %int.make_type_32.loc5, %.loc5_19.1 [template = i32]
  438. // CHECK:STDOUT: @UseMethod.%return: ref i32 = var <return slot>
  439. // CHECK:STDOUT: }
  440. // CHECK:STDOUT: %UseField.decl: %UseField.type = fn_decl @UseField [template = constants.%UseField] {
  441. // CHECK:STDOUT: %int.make_type_32.loc10: init type = call constants.%Int32() [template = i32]
  442. // CHECK:STDOUT: %.loc10_18.1: type = value_of_initializer %int.make_type_32.loc10 [template = i32]
  443. // CHECK:STDOUT: %.loc10_18.2: type = converted %int.make_type_32.loc10, %.loc10_18.1 [template = i32]
  444. // CHECK:STDOUT: @UseField.%return: ref i32 = var <return slot>
  445. // CHECK:STDOUT: }
  446. // CHECK:STDOUT: }
  447. // CHECK:STDOUT:
  448. // CHECK:STDOUT: generic class @CompleteClass(constants.%T: type) {
  449. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  450. // CHECK:STDOUT:
  451. // CHECK:STDOUT: !definition:
  452. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  453. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.4)]
  454. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  455. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  456. // CHECK:STDOUT:
  457. // CHECK:STDOUT: class {
  458. // CHECK:STDOUT: !members:
  459. // CHECK:STDOUT: .Self = imports.%import_ref.5
  460. // CHECK:STDOUT: .n = imports.%import_ref.6
  461. // CHECK:STDOUT: .F = imports.%import_ref.7
  462. // CHECK:STDOUT: }
  463. // CHECK:STDOUT: }
  464. // CHECK:STDOUT:
  465. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  466. // CHECK:STDOUT:
  467. // CHECK:STDOUT: fn @UseMethod() -> i32 {
  468. // CHECK:STDOUT: !entry:
  469. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  470. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  471. // CHECK:STDOUT: %.loc6_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
  472. // CHECK:STDOUT: %.loc6_23.2: type = converted %int.make_type_32, %.loc6_23.1 [template = i32]
  473. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(i32) [template = constants.%CompleteClass.3]
  474. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  475. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  476. // CHECK:STDOUT: %F.ref.loc6: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
  477. // CHECK:STDOUT: %.loc6_7: ref %CompleteClass.3 = splice_block %v.var {}
  478. // CHECK:STDOUT: %F.call.loc6: init %CompleteClass.3 = call %F.ref.loc6() to %.loc6_7
  479. // CHECK:STDOUT: assign %v.var, %F.call.loc6
  480. // CHECK:STDOUT: %v.ref: ref %CompleteClass.3 = name_ref v, %v
  481. // CHECK:STDOUT: %.loc7_11: %F.type.2 = specific_constant imports.%import_ref.7, @CompleteClass(i32) [template = constants.%F.2]
  482. // CHECK:STDOUT: %F.ref.loc7: %F.type.2 = name_ref F, %.loc7_11 [template = constants.%F.2]
  483. // CHECK:STDOUT: %F.call.loc7: init i32 = call %F.ref.loc7()
  484. // CHECK:STDOUT: %.loc7_15.1: i32 = value_of_initializer %F.call.loc7
  485. // CHECK:STDOUT: %.loc7_15.2: i32 = converted %F.call.loc7, %.loc7_15.1
  486. // CHECK:STDOUT: return %.loc7_15.2
  487. // CHECK:STDOUT: }
  488. // CHECK:STDOUT:
  489. // CHECK:STDOUT: generic fn @F.1(constants.%T: type) {
  490. // CHECK:STDOUT: !definition:
  491. // CHECK:STDOUT:
  492. // CHECK:STDOUT: fn() -> i32;
  493. // CHECK:STDOUT: }
  494. // CHECK:STDOUT:
  495. // CHECK:STDOUT: fn @F.2() -> %CompleteClass.3;
  496. // CHECK:STDOUT:
  497. // CHECK:STDOUT: fn @UseField() -> i32 {
  498. // CHECK:STDOUT: !entry:
  499. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  500. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  501. // CHECK:STDOUT: %.loc11_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
  502. // CHECK:STDOUT: %.loc11_23.2: type = converted %int.make_type_32, %.loc11_23.1 [template = i32]
  503. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(i32) [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: %.5 = 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.%.4
  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.%.5
  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: %.3: <witness> = complete_type_witness %.2 [template]
  555. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  556. // CHECK:STDOUT: %CompleteClass.2: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic]
  557. // CHECK:STDOUT: %.4: type = unbound_element_type %CompleteClass.2, i32 [symbolic]
  558. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @CompleteClass(%T) [symbolic]
  559. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  560. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  561. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  562. // CHECK:STDOUT: %.5: type = ptr_type i32 [template]
  563. // CHECK:STDOUT: %CompleteClass.3: type = class_type @CompleteClass, @CompleteClass(%.5) [template]
  564. // CHECK:STDOUT: %.6: type = unbound_element_type %CompleteClass.3, i32 [template]
  565. // CHECK:STDOUT: %F.type.2: type = fn_type @F.1, @CompleteClass(%.5) [template]
  566. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  567. // CHECK:STDOUT: %.7: type = ptr_type %.2 [template]
  568. // CHECK:STDOUT: %F.type.3: type = fn_type @F.2 [template]
  569. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  570. // CHECK:STDOUT: %CompleteClass.4: type = class_type @CompleteClass, @CompleteClass(i32) [template]
  571. // CHECK:STDOUT: %.8: type = unbound_element_type %CompleteClass.4, i32 [template]
  572. // CHECK:STDOUT: %F.type.4: type = fn_type @F.1, @CompleteClass(i32) [template]
  573. // CHECK:STDOUT: %F.4: %F.type.4 = struct_value () [template]
  574. // CHECK:STDOUT: %ImplicitAs.type: type = generic_interface_type @ImplicitAs [template]
  575. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type = struct_value () [template]
  576. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic]
  577. // CHECK:STDOUT: %.9: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  578. // CHECK:STDOUT: %Self.1: @ImplicitAs.%.1 (%.9) = bind_symbolic_name Self 1 [symbolic]
  579. // CHECK:STDOUT: %Self.2: %.9 = bind_symbolic_name Self 1 [symbolic]
  580. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  581. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  582. // CHECK:STDOUT: %.10: type = assoc_entity_type %.9, %Convert.type.1 [symbolic]
  583. // CHECK:STDOUT: %.11: %.10 = assoc_entity element0, imports.%import_ref.12 [symbolic]
  584. // CHECK:STDOUT: %.12: type = interface_type @ImplicitAs, @ImplicitAs(%CompleteClass.3) [template]
  585. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(%CompleteClass.3) [template]
  586. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  587. // CHECK:STDOUT: %.13: type = assoc_entity_type %.12, %Convert.type.2 [template]
  588. // CHECK:STDOUT: %.14: %.13 = assoc_entity element0, imports.%import_ref.12 [template]
  589. // CHECK:STDOUT: %.15: %.10 = assoc_entity element0, imports.%import_ref.13 [symbolic]
  590. // CHECK:STDOUT: }
  591. // CHECK:STDOUT:
  592. // CHECK:STDOUT: imports {
  593. // CHECK:STDOUT: %import_ref.1 = import_ref Main//foo, inst+6, unloaded
  594. // CHECK:STDOUT: %import_ref.2: %CompleteClass.type = import_ref Main//foo, inst+14, loaded [template = constants.%CompleteClass.1]
  595. // CHECK:STDOUT: %import_ref.3: %F.type.3 = import_ref Main//foo, inst+55, loaded [template = constants.%F.3]
  596. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  597. // CHECK:STDOUT: .Int32 = %import_ref.7
  598. // CHECK:STDOUT: .ImplicitAs = %import_ref.8
  599. // CHECK:STDOUT: import Core//prelude
  600. // CHECK:STDOUT: import Core//prelude/operators
  601. // CHECK:STDOUT: import Core//prelude/types
  602. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  603. // CHECK:STDOUT: import Core//prelude/operators/as
  604. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  605. // CHECK:STDOUT: import Core//prelude/operators/comparison
  606. // CHECK:STDOUT: import Core//prelude/types/bool
  607. // CHECK:STDOUT: }
  608. // CHECK:STDOUT: %import_ref.4 = import_ref Main//foo, inst+18, unloaded
  609. // CHECK:STDOUT: %import_ref.5 = import_ref Main//foo, inst+28, unloaded
  610. // CHECK:STDOUT: %import_ref.6 = import_ref Main//foo, inst+35, unloaded
  611. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  612. // CHECK:STDOUT: %import_ref.8: %ImplicitAs.type = import_ref Core//prelude/operators/as, inst+37, loaded [template = constants.%ImplicitAs]
  613. // CHECK:STDOUT: %import_ref.9 = import_ref Core//prelude/operators/as, inst+42, unloaded
  614. // CHECK:STDOUT: %import_ref.10: @ImplicitAs.%.2 (%.10) = import_ref Core//prelude/operators/as, inst+59, loaded [symbolic = @ImplicitAs.%.3 (constants.%.15)]
  615. // CHECK:STDOUT: %import_ref.11 = import_ref Core//prelude/operators/as, inst+52, unloaded
  616. // CHECK:STDOUT: %import_ref.12 = import_ref Core//prelude/operators/as, inst+52, unloaded
  617. // CHECK:STDOUT: %import_ref.13 = import_ref Core//prelude/operators/as, inst+52, unloaded
  618. // CHECK:STDOUT: }
  619. // CHECK:STDOUT:
  620. // CHECK:STDOUT: file {
  621. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  622. // CHECK:STDOUT: .Class = imports.%import_ref.1
  623. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  624. // CHECK:STDOUT: .F = imports.%import_ref.3
  625. // CHECK:STDOUT: .Core = imports.%Core
  626. // CHECK:STDOUT: .Use = %Use.decl
  627. // CHECK:STDOUT: }
  628. // CHECK:STDOUT: %Core.import = import Core
  629. // CHECK:STDOUT: %default.import = import <invalid>
  630. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {}
  631. // CHECK:STDOUT: }
  632. // CHECK:STDOUT:
  633. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  634. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  635. // CHECK:STDOUT:
  636. // CHECK:STDOUT: !definition:
  637. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.9)]
  638. // CHECK:STDOUT: %Self: %.9 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  639. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  640. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  641. // CHECK:STDOUT: %.2: type = assoc_entity_type @ImplicitAs.%.1 (%.9), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.2 (constants.%.10)]
  642. // CHECK:STDOUT: %.3: @ImplicitAs.%.2 (%.10) = assoc_entity element0, imports.%import_ref.12 [symbolic = %.3 (constants.%.11)]
  643. // CHECK:STDOUT:
  644. // CHECK:STDOUT: interface {
  645. // CHECK:STDOUT: !members:
  646. // CHECK:STDOUT: .Self = imports.%import_ref.9
  647. // CHECK:STDOUT: .Convert = imports.%import_ref.10
  648. // CHECK:STDOUT: witness = (imports.%import_ref.11)
  649. // CHECK:STDOUT: }
  650. // CHECK:STDOUT: }
  651. // CHECK:STDOUT:
  652. // CHECK:STDOUT: generic class @CompleteClass(constants.%T: type) {
  653. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  654. // CHECK:STDOUT:
  655. // CHECK:STDOUT: !definition:
  656. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(%T) [symbolic = %CompleteClass (constants.%CompleteClass.2)]
  657. // CHECK:STDOUT: %.1: type = unbound_element_type @CompleteClass.%CompleteClass (%CompleteClass.2), i32 [symbolic = %.1 (constants.%.4)]
  658. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @CompleteClass(%T) [symbolic = %F.type (constants.%F.type.1)]
  659. // CHECK:STDOUT: %F: @CompleteClass.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  660. // CHECK:STDOUT:
  661. // CHECK:STDOUT: class {
  662. // CHECK:STDOUT: !members:
  663. // CHECK:STDOUT: .Self = imports.%import_ref.4
  664. // CHECK:STDOUT: .n = imports.%import_ref.5
  665. // CHECK:STDOUT: .F = imports.%import_ref.6
  666. // CHECK:STDOUT: }
  667. // CHECK:STDOUT: }
  668. // CHECK:STDOUT:
  669. // CHECK:STDOUT: fn @Use() {
  670. // CHECK:STDOUT: !entry:
  671. // CHECK:STDOUT: %CompleteClass.ref: %CompleteClass.type = name_ref CompleteClass, imports.%import_ref.2 [template = constants.%CompleteClass.1]
  672. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  673. // CHECK:STDOUT: %.loc14_27.1: type = value_of_initializer %int.make_type_32 [template = i32]
  674. // CHECK:STDOUT: %.loc14_27.2: type = converted %int.make_type_32, %.loc14_27.1 [template = i32]
  675. // CHECK:STDOUT: %.loc14_27.3: type = ptr_type i32 [template = constants.%.5]
  676. // CHECK:STDOUT: %CompleteClass: type = class_type @CompleteClass, @CompleteClass(constants.%.5) [template = constants.%CompleteClass.3]
  677. // CHECK:STDOUT: %v.var: ref %CompleteClass.3 = var v
  678. // CHECK:STDOUT: %v: ref %CompleteClass.3 = bind_name v, %v.var
  679. // CHECK:STDOUT: %F.ref: %F.type.3 = name_ref F, imports.%import_ref.3 [template = constants.%F.3]
  680. // CHECK:STDOUT: %.loc14_33.1: ref %CompleteClass.4 = temporary_storage
  681. // CHECK:STDOUT: %F.call: init %CompleteClass.4 = call %F.ref() to %.loc14_33.1
  682. // CHECK:STDOUT: %.loc14_35.1: type = interface_type @ImplicitAs, @ImplicitAs(constants.%CompleteClass.3) [template = constants.%.12]
  683. // CHECK:STDOUT: %.loc14_35.2: %.13 = specific_constant imports.%import_ref.10, @ImplicitAs(constants.%CompleteClass.3) [template = constants.%.14]
  684. // CHECK:STDOUT: %Convert.ref: %.13 = name_ref Convert, %.loc14_35.2 [template = constants.%.14]
  685. // CHECK:STDOUT: %.loc14_33.2: ref %CompleteClass.4 = temporary %.loc14_33.1, %F.call
  686. // CHECK:STDOUT: %.loc14_35.3: %CompleteClass.3 = converted %F.call, <error> [template = <error>]
  687. // CHECK:STDOUT: assign %v.var, <error>
  688. // CHECK:STDOUT: return
  689. // CHECK:STDOUT: }
  690. // CHECK:STDOUT:
  691. // CHECK:STDOUT: generic fn @F.1(constants.%T: type) {
  692. // CHECK:STDOUT: !definition:
  693. // CHECK:STDOUT:
  694. // CHECK:STDOUT: fn() -> i32;
  695. // CHECK:STDOUT: }
  696. // CHECK:STDOUT:
  697. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  698. // CHECK:STDOUT:
  699. // CHECK:STDOUT: fn @F.2() -> %CompleteClass.4;
  700. // CHECK:STDOUT:
  701. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%.1 (%.9)) {
  702. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  703. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.9)]
  704. // CHECK:STDOUT: %Self: %.9 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  705. // CHECK:STDOUT:
  706. // CHECK:STDOUT: fn[%self: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  707. // CHECK:STDOUT: }
  708. // CHECK:STDOUT:
  709. // CHECK:STDOUT: specific @CompleteClass(constants.%T) {
  710. // CHECK:STDOUT: %T => constants.%T
  711. // CHECK:STDOUT:
  712. // CHECK:STDOUT: !definition:
  713. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.2
  714. // CHECK:STDOUT: %.1 => constants.%.4
  715. // CHECK:STDOUT: %F.type => constants.%F.type.1
  716. // CHECK:STDOUT: %F => constants.%F.1
  717. // CHECK:STDOUT: }
  718. // CHECK:STDOUT:
  719. // CHECK:STDOUT: specific @CompleteClass(@CompleteClass.%T) {
  720. // CHECK:STDOUT: %T => constants.%T
  721. // CHECK:STDOUT: }
  722. // CHECK:STDOUT:
  723. // CHECK:STDOUT: specific @F.1(constants.%T) {}
  724. // CHECK:STDOUT:
  725. // CHECK:STDOUT: specific @CompleteClass(constants.%.5) {
  726. // CHECK:STDOUT: %T => constants.%.5
  727. // CHECK:STDOUT:
  728. // CHECK:STDOUT: !definition:
  729. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.3
  730. // CHECK:STDOUT: %.1 => constants.%.6
  731. // CHECK:STDOUT: %F.type => constants.%F.type.2
  732. // CHECK:STDOUT: %F => constants.%F.2
  733. // CHECK:STDOUT: }
  734. // CHECK:STDOUT:
  735. // CHECK:STDOUT: specific @CompleteClass(i32) {
  736. // CHECK:STDOUT: %T => i32
  737. // CHECK:STDOUT:
  738. // CHECK:STDOUT: !definition:
  739. // CHECK:STDOUT: %CompleteClass => constants.%CompleteClass.4
  740. // CHECK:STDOUT: %.1 => constants.%.8
  741. // CHECK:STDOUT: %F.type => constants.%F.type.4
  742. // CHECK:STDOUT: %F => constants.%F.4
  743. // CHECK:STDOUT: }
  744. // CHECK:STDOUT:
  745. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  746. // CHECK:STDOUT: %Dest => constants.%Dest
  747. // CHECK:STDOUT: }
  748. // CHECK:STDOUT:
  749. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  750. // CHECK:STDOUT: %Dest => constants.%Dest
  751. // CHECK:STDOUT: }
  752. // CHECK:STDOUT:
  753. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  754. // CHECK:STDOUT: %Dest => constants.%Dest
  755. // CHECK:STDOUT: }
  756. // CHECK:STDOUT:
  757. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  758. // CHECK:STDOUT: %Dest => constants.%Dest
  759. // CHECK:STDOUT: %.1 => constants.%.9
  760. // CHECK:STDOUT: %Self => constants.%Self.1
  761. // CHECK:STDOUT: }
  762. // CHECK:STDOUT:
  763. // CHECK:STDOUT: specific @ImplicitAs(constants.%CompleteClass.3) {
  764. // CHECK:STDOUT: %Dest => constants.%CompleteClass.3
  765. // CHECK:STDOUT:
  766. // CHECK:STDOUT: !definition:
  767. // CHECK:STDOUT: %.1 => constants.%.12
  768. // CHECK:STDOUT: %Self => constants.%Self.2
  769. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  770. // CHECK:STDOUT: %Convert => constants.%Convert.2
  771. // CHECK:STDOUT: %.2 => constants.%.13
  772. // CHECK:STDOUT: %.3 => constants.%.14
  773. // CHECK:STDOUT: }
  774. // CHECK:STDOUT:
  775. // CHECK:STDOUT: --- fail_foo.impl.carbon
  776. // CHECK:STDOUT:
  777. // CHECK:STDOUT: constants {
  778. // CHECK:STDOUT: %U: type = bind_symbolic_name U 0 [symbolic]
  779. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  780. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  781. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  782. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  783. // CHECK:STDOUT: %Class.2: type = class_type @Class, @Class(%T) [symbolic]
  784. // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
  785. // CHECK:STDOUT: %.2: %.type = struct_value () [template]
  786. // CHECK:STDOUT: %.3: type = class_type @.1, @.1(%U) [symbolic]
  787. // CHECK:STDOUT: }
  788. // CHECK:STDOUT:
  789. // CHECK:STDOUT: imports {
  790. // CHECK:STDOUT: %import_ref.1: %Class.type = import_ref Main//foo, inst+6, loaded [template = constants.%Class.1]
  791. // CHECK:STDOUT: %import_ref.2 = import_ref Main//foo, inst+14, unloaded
  792. // CHECK:STDOUT: %import_ref.3 = import_ref Main//foo, inst+55, unloaded
  793. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  794. // CHECK:STDOUT: import Core//prelude
  795. // CHECK:STDOUT: import Core//prelude/operators
  796. // CHECK:STDOUT: import Core//prelude/types
  797. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  798. // CHECK:STDOUT: import Core//prelude/operators/as
  799. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  800. // CHECK:STDOUT: import Core//prelude/operators/comparison
  801. // CHECK:STDOUT: import Core//prelude/types/bool
  802. // CHECK:STDOUT: }
  803. // CHECK:STDOUT: }
  804. // CHECK:STDOUT:
  805. // CHECK:STDOUT: file {
  806. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  807. // CHECK:STDOUT: .Class = imports.%import_ref.1
  808. // CHECK:STDOUT: .CompleteClass = imports.%import_ref.2
  809. // CHECK:STDOUT: .F = imports.%import_ref.3
  810. // CHECK:STDOUT: .Core = imports.%Core
  811. // CHECK:STDOUT: }
  812. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  813. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  814. // CHECK:STDOUT: %Core.import = import Core
  815. // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
  816. // CHECK:STDOUT: %U.loc14_13.1: type = param U, runtime_param<invalid>
  817. // CHECK:STDOUT: %U.loc14_13.2: type = bind_symbolic_name U 0, %U.loc14_13.1 [symbolic = @.1.%U (constants.%U)]
  818. // CHECK:STDOUT: }
  819. // CHECK:STDOUT: }
  820. // CHECK:STDOUT:
  821. // CHECK:STDOUT: generic class @Class(constants.%T: type) {
  822. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  823. // CHECK:STDOUT:
  824. // CHECK:STDOUT: class;
  825. // CHECK:STDOUT: }
  826. // CHECK:STDOUT:
  827. // CHECK:STDOUT: generic class @.1(file.%U.loc14_13.2: type) {
  828. // CHECK:STDOUT: %U: type = bind_symbolic_name U 0 [symbolic = %U (constants.%U)]
  829. // CHECK:STDOUT:
  830. // CHECK:STDOUT: !definition:
  831. // CHECK:STDOUT:
  832. // CHECK:STDOUT: class {
  833. // CHECK:STDOUT: %T.ref: <error> = name_ref T, <error> [template = <error>]
  834. // CHECK:STDOUT: %.loc18: <error> = field_decl x, element0 [template]
  835. // CHECK:STDOUT: %.loc19: <witness> = complete_type_witness <error> [template = <error>]
  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: