import.carbon 45 KB

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