import.carbon 46 KB

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