convert.carbon 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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/generic/template/convert.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/template/convert.carbon
  10. // --- convert.carbon
  11. library "[[@TEST_NAME]]";
  12. fn F[template T:! type](x: T) -> i32 {
  13. return x;
  14. }
  15. fn Test1(n: i32) -> i32 {
  16. return F(n);
  17. }
  18. class C {
  19. var n: i32;
  20. impl as Core.ImplicitAs(i32) {
  21. fn Convert[self: Self]() -> i32 { return self.n; }
  22. }
  23. }
  24. fn Test2(c: C) -> i32 {
  25. return F(c);
  26. }
  27. // --- fail_cannot_convert.carbon
  28. library "[[@TEST_NAME]]";
  29. fn F[template T:! type](x: T) -> i32 {
  30. // CHECK:STDERR: fail_cannot_convert.carbon:[[@LINE+6]]:3: error: cannot implicitly convert expression of type `D` to `i32` [ConversionFailure]
  31. // CHECK:STDERR: return x;
  32. // CHECK:STDERR: ^~~~~~~~~
  33. // CHECK:STDERR: fail_cannot_convert.carbon:[[@LINE+3]]:3: note: type `D` does not implement interface `Core.ImplicitAs(i32)` [MissingImplInMemberAccessNote]
  34. // CHECK:STDERR: return x;
  35. // CHECK:STDERR: ^~~~~~~~~
  36. return x;
  37. }
  38. class D {}
  39. fn Test(d: D) -> i32 {
  40. // CHECK:STDERR: fail_cannot_convert.carbon:[[@LINE+4]]:10: note: in `F(D)` used here [ResolvingSpecificHere]
  41. // CHECK:STDERR: return F(d);
  42. // CHECK:STDERR: ^
  43. // CHECK:STDERR:
  44. return F(d);
  45. }
  46. // CHECK:STDOUT: --- convert.carbon
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: constants {
  49. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, template [template]
  50. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  51. // CHECK:STDOUT: %pattern_type.7dcd0a.1: type = pattern_type %T [template]
  52. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  53. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  54. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  55. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  56. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  57. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  58. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  59. // CHECK:STDOUT: %i32.builtin: type = int_type signed, %int_32 [concrete]
  60. // CHECK:STDOUT: %complete_type.f8a: <witness> = complete_type_witness %i32.builtin [concrete]
  61. // CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [template]
  62. // CHECK:STDOUT: %Test1.type: type = fn_type @Test1 [concrete]
  63. // CHECK:STDOUT: %Test1: %Test1.type = struct_value () [concrete]
  64. // CHECK:STDOUT: %F.specific_fn.501: <specific function> = specific_function %F, @F(%i32) [concrete]
  65. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  66. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [concrete]
  67. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  68. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  69. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  70. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  71. // CHECK:STDOUT: %ImplicitAs.impl_witness.96d: <witness> = impl_witness @C.%ImplicitAs.impl_witness_table [concrete]
  72. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  73. // CHECK:STDOUT: %Convert.type.dae: type = fn_type @Convert.2 [concrete]
  74. // CHECK:STDOUT: %Convert.937: %Convert.type.dae = struct_value () [concrete]
  75. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value %C, (%ImplicitAs.impl_witness.96d) [concrete]
  76. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete]
  77. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [concrete]
  78. // CHECK:STDOUT: %Test2.type: type = fn_type @Test2 [concrete]
  79. // CHECK:STDOUT: %Test2: %Test2.type = struct_value () [concrete]
  80. // CHECK:STDOUT: %F.specific_fn.04a: <specific function> = specific_function %F, @F(%C) [concrete]
  81. // CHECK:STDOUT: %inst.as_compatible.d73: <instruction> = inst_value [concrete] {
  82. // CHECK:STDOUT: %.0b2: %i32 = as_compatible @F.%x.ref
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %inst.splice_block.c18: <instruction> = inst_value [concrete] {
  85. // CHECK:STDOUT: %.dc6: %i32 = splice_block %.0b2 {}
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %inst.as_compatible.c0a: <instruction> = inst_value [concrete] {
  88. // CHECK:STDOUT: %.fbe: %C = as_compatible @F.%x.ref
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %.2ce: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  91. // CHECK:STDOUT: %inst.splice_block.1fd: <instruction> = inst_value [concrete] {
  92. // CHECK:STDOUT: %.96d: %i32 = splice_block %.521 {
  93. // CHECK:STDOUT: %impl.elem0: %.2ce = impl_witness_access %ImplicitAs.impl_witness.96d, element0 [concrete = %Convert.937]
  94. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.fbe, %impl.elem0
  95. // CHECK:STDOUT: %Convert.call: init %i32 = call %bound_method(%.fbe)
  96. // CHECK:STDOUT: %.fa7: %i32 = value_of_initializer %Convert.call
  97. // CHECK:STDOUT: %.521: %i32 = converted %.fbe, %.fa7
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: imports {
  103. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  104. // CHECK:STDOUT: .Int = %Core.Int
  105. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  106. // CHECK:STDOUT: import Core//prelude
  107. // CHECK:STDOUT: import Core//prelude/...
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  110. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: file {
  114. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  115. // CHECK:STDOUT: .Core = imports.%Core
  116. // CHECK:STDOUT: .F = %F.decl
  117. // CHECK:STDOUT: .Test1 = %Test1.decl
  118. // CHECK:STDOUT: .C = %C.decl
  119. // CHECK:STDOUT: .Test2 = %Test2.decl
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %Core.import = import Core
  122. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  123. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0, template [concrete]
  124. // CHECK:STDOUT: %x.patt: @F.%pattern_type (%pattern_type.7dcd0a.1) = binding_pattern x [concrete]
  125. // CHECK:STDOUT: %x.param_patt: @F.%pattern_type (%pattern_type.7dcd0a.1) = value_param_pattern %x.patt, call_param0 [concrete]
  126. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  127. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  128. // CHECK:STDOUT: } {
  129. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  130. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  131. // CHECK:STDOUT: %T.loc4_15.1: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  132. // CHECK:STDOUT: %x.param: @F.%T.loc4_15.2 (%T) = value_param call_param0
  133. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc4_15.1 [template = %T.loc4_15.2 (constants.%T)]
  134. // CHECK:STDOUT: %x: @F.%T.loc4_15.2 (%T) = bind_name x, %x.param
  135. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  136. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %Test1.decl: %Test1.type = fn_decl @Test1 [concrete = constants.%Test1] {
  139. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = binding_pattern n [concrete]
  140. // CHECK:STDOUT: %n.param_patt: %pattern_type.7ce = value_param_pattern %n.patt, call_param0 [concrete]
  141. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  142. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  143. // CHECK:STDOUT: } {
  144. // CHECK:STDOUT: %int_32.loc8_21: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  145. // CHECK:STDOUT: %i32.loc8_21: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  146. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  147. // CHECK:STDOUT: %.loc8: type = splice_block %i32.loc8_13 [concrete = constants.%i32] {
  148. // CHECK:STDOUT: %int_32.loc8_13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  149. // CHECK:STDOUT: %i32.loc8_13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  152. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  153. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  156. // CHECK:STDOUT: %Test2.decl: %Test2.type = fn_decl @Test2 [concrete = constants.%Test2] {
  157. // CHECK:STDOUT: %c.patt: %pattern_type.c48 = binding_pattern c [concrete]
  158. // CHECK:STDOUT: %c.param_patt: %pattern_type.c48 = value_param_pattern %c.patt, call_param0 [concrete]
  159. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  160. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  161. // CHECK:STDOUT: } {
  162. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  163. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  164. // CHECK:STDOUT: %c.param: %C = value_param call_param0
  165. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  166. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  167. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  168. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: impl @impl.4e3: %Self.ref as %ImplicitAs.type {
  173. // CHECK:STDOUT: %Convert.decl: %Convert.type.dae = fn_decl @Convert.2 [concrete = constants.%Convert.937] {
  174. // CHECK:STDOUT: %self.patt: %pattern_type.c48 = binding_pattern self [concrete]
  175. // CHECK:STDOUT: %self.param_patt: %pattern_type.c48 = value_param_pattern %self.patt, call_param0 [concrete]
  176. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  177. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  178. // CHECK:STDOUT: } {
  179. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  180. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  181. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  182. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  183. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  184. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  185. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: !members:
  189. // CHECK:STDOUT: .Convert = %Convert.decl
  190. // CHECK:STDOUT: witness = @C.%ImplicitAs.impl_witness
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: class @C {
  194. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  195. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  196. // CHECK:STDOUT: %.loc13: %C.elem = field_decl n, element0 [concrete]
  197. // CHECK:STDOUT: impl_decl @impl.4e3 [concrete] {} {
  198. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  199. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  200. // CHECK:STDOUT: %ImplicitAs.ref: %ImplicitAs.type.cc7 = name_ref ImplicitAs, imports.%Core.ImplicitAs [concrete = constants.%ImplicitAs.generic]
  201. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  202. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  203. // CHECK:STDOUT: %ImplicitAs.type: type = facet_type <@ImplicitAs, @ImplicitAs(constants.%i32)> [concrete = constants.%ImplicitAs.type.205]
  204. // CHECK:STDOUT: }
  205. // CHECK:STDOUT: %ImplicitAs.impl_witness_table = impl_witness_table (@impl.4e3.%Convert.decl), @impl.4e3 [concrete]
  206. // CHECK:STDOUT: %ImplicitAs.impl_witness: <witness> = impl_witness %ImplicitAs.impl_witness_table [concrete = constants.%ImplicitAs.impl_witness.96d]
  207. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete = constants.%struct_type.n]
  208. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.54b]
  209. // CHECK:STDOUT: complete_type_witness = %complete_type
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: !members:
  212. // CHECK:STDOUT: .Self = constants.%C
  213. // CHECK:STDOUT: .n = %.loc13
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: generic fn @F(%T.loc4_15.1: type) {
  217. // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  218. // CHECK:STDOUT: %pattern_type: type = pattern_type %T.loc4_15.2 [template = %pattern_type (constants.%pattern_type.7dcd0a.1)]
  219. // CHECK:STDOUT:
  220. // CHECK:STDOUT: !definition:
  221. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T.loc4_15.2 [template = %require_complete (constants.%require_complete.4ae)]
  222. // CHECK:STDOUT: %.loc5_11.3: <instruction> = refine_type_action %x.ref, %T.loc4_15.2 [template]
  223. // CHECK:STDOUT: %.loc5_11.4: <instruction> = convert_to_value_action %.loc5_11.1, constants.%i32 [template]
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: fn(%x.param: @F.%T.loc4_15.2 (%T)) -> %i32 {
  226. // CHECK:STDOUT: !entry:
  227. // CHECK:STDOUT: %x.ref: @F.%T.loc4_15.2 (%T) = name_ref x, %x
  228. // CHECK:STDOUT: %.loc5_11.1: @F.%T.loc4_15.2 (%T) = splice_inst %.loc5_11.3
  229. // CHECK:STDOUT: %.loc5_11.2: %i32 = splice_inst %.loc5_11.4
  230. // CHECK:STDOUT: return %.loc5_11.2
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: fn @Test1(%n.param: %i32) -> %i32 {
  235. // CHECK:STDOUT: !entry:
  236. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  237. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  238. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F(constants.%i32) [concrete = constants.%F.specific_fn.501]
  239. // CHECK:STDOUT: %F.call: init %i32 = call %F.specific_fn(%n.ref)
  240. // CHECK:STDOUT: %.loc9_14.1: %i32 = value_of_initializer %F.call
  241. // CHECK:STDOUT: %.loc9_14.2: %i32 = converted %F.call, %.loc9_14.1
  242. // CHECK:STDOUT: return %.loc9_14.2
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT:
  245. // CHECK:STDOUT: fn @Convert.2(%self.param: %C) -> %i32 {
  246. // CHECK:STDOUT: !entry:
  247. // CHECK:STDOUT: %self.ref: %C = name_ref self, %self
  248. // CHECK:STDOUT: %n.ref: %C.elem = name_ref n, @C.%.loc13 [concrete = @C.%.loc13]
  249. // CHECK:STDOUT: %.loc15_50.1: ref %i32 = class_element_access %self.ref, element0
  250. // CHECK:STDOUT: %.loc15_50.2: %i32 = bind_value %.loc15_50.1
  251. // CHECK:STDOUT: return %.loc15_50.2
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: fn @Test2(%c.param: %C) -> %i32 {
  255. // CHECK:STDOUT: !entry:
  256. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  257. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  258. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F(constants.%C) [concrete = constants.%F.specific_fn.04a]
  259. // CHECK:STDOUT: %F.call: init %i32 = call %F.specific_fn(%c.ref)
  260. // CHECK:STDOUT: %.loc20_14.1: %i32 = value_of_initializer %F.call
  261. // CHECK:STDOUT: %.loc20_14.2: %i32 = converted %F.call, %.loc20_14.1
  262. // CHECK:STDOUT: return %.loc20_14.2
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: specific @F(constants.%T) {
  266. // CHECK:STDOUT: %T.loc4_15.2 => constants.%T
  267. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7dcd0a.1
  268. // CHECK:STDOUT: }
  269. // CHECK:STDOUT:
  270. // CHECK:STDOUT: specific @F(constants.%i32) {
  271. // CHECK:STDOUT: %T.loc4_15.2 => constants.%i32
  272. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7ce
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: !definition:
  275. // CHECK:STDOUT: %require_complete => constants.%complete_type.f8a
  276. // CHECK:STDOUT: %.loc5_11.3 => constants.%inst.as_compatible.d73
  277. // CHECK:STDOUT: %.loc5_11.4 => constants.%inst.splice_block.c18
  278. // CHECK:STDOUT: }
  279. // CHECK:STDOUT:
  280. // CHECK:STDOUT: specific @F(constants.%C) {
  281. // CHECK:STDOUT: %T.loc4_15.2 => constants.%C
  282. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.c48
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: !definition:
  285. // CHECK:STDOUT: %require_complete => constants.%complete_type.54b
  286. // CHECK:STDOUT: %.loc5_11.3 => constants.%inst.as_compatible.c0a
  287. // CHECK:STDOUT: %.loc5_11.4 => constants.%inst.splice_block.1fd
  288. // CHECK:STDOUT: }
  289. // CHECK:STDOUT:
  290. // CHECK:STDOUT: --- fail_cannot_convert.carbon
  291. // CHECK:STDOUT:
  292. // CHECK:STDOUT: constants {
  293. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, template [template]
  294. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  295. // CHECK:STDOUT: %pattern_type.7dcd0a.1: type = pattern_type %T [template]
  296. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  297. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  298. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  299. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  300. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  301. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  302. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  303. // CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [template]
  304. // CHECK:STDOUT: %D: type = class_type @D [concrete]
  305. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  306. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  307. // CHECK:STDOUT: %pattern_type.510: type = pattern_type %D [concrete]
  308. // CHECK:STDOUT: %Test.type: type = fn_type @Test [concrete]
  309. // CHECK:STDOUT: %Test: %Test.type = struct_value () [concrete]
  310. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F, @F(%D) [concrete]
  311. // CHECK:STDOUT: %inst.as_compatible: <instruction> = inst_value [concrete] {
  312. // CHECK:STDOUT: %.63b: %D = as_compatible @F.%x.ref
  313. // CHECK:STDOUT: }
  314. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  315. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  316. // CHECK:STDOUT: %inst.splice_block: <instruction> = inst_value [concrete] {
  317. // CHECK:STDOUT: %.593: <error> = splice_block <error> [concrete = <error>] {
  318. // CHECK:STDOUT: %.16e: %i32 = converted %.63b, <error> [concrete = <error>]
  319. // CHECK:STDOUT: }
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT: }
  322. // CHECK:STDOUT:
  323. // CHECK:STDOUT: imports {
  324. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  325. // CHECK:STDOUT: .Int = %Core.Int
  326. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  327. // CHECK:STDOUT: import Core//prelude
  328. // CHECK:STDOUT: import Core//prelude/...
  329. // CHECK:STDOUT: }
  330. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  331. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  332. // CHECK:STDOUT: }
  333. // CHECK:STDOUT:
  334. // CHECK:STDOUT: file {
  335. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  336. // CHECK:STDOUT: .Core = imports.%Core
  337. // CHECK:STDOUT: .F = %F.decl
  338. // CHECK:STDOUT: .D = %D.decl
  339. // CHECK:STDOUT: .Test = %Test.decl
  340. // CHECK:STDOUT: }
  341. // CHECK:STDOUT: %Core.import = import Core
  342. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  343. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0, template [concrete]
  344. // CHECK:STDOUT: %x.patt: @F.%pattern_type (%pattern_type.7dcd0a.1) = binding_pattern x [concrete]
  345. // CHECK:STDOUT: %x.param_patt: @F.%pattern_type (%pattern_type.7dcd0a.1) = value_param_pattern %x.patt, call_param0 [concrete]
  346. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  347. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  348. // CHECK:STDOUT: } {
  349. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  350. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  351. // CHECK:STDOUT: %T.loc4_15.1: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  352. // CHECK:STDOUT: %x.param: @F.%T.loc4_15.2 (%T) = value_param call_param0
  353. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc4_15.1 [template = %T.loc4_15.2 (constants.%T)]
  354. // CHECK:STDOUT: %x: @F.%T.loc4_15.2 (%T) = bind_name x, %x.param
  355. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  356. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT: %D.decl: type = class_decl @D [concrete = constants.%D] {} {}
  359. // CHECK:STDOUT: %Test.decl: %Test.type = fn_decl @Test [concrete = constants.%Test] {
  360. // CHECK:STDOUT: %d.patt: %pattern_type.510 = binding_pattern d [concrete]
  361. // CHECK:STDOUT: %d.param_patt: %pattern_type.510 = value_param_pattern %d.patt, call_param0 [concrete]
  362. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  363. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  364. // CHECK:STDOUT: } {
  365. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  366. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  367. // CHECK:STDOUT: %d.param: %D = value_param call_param0
  368. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [concrete = constants.%D]
  369. // CHECK:STDOUT: %d: %D = bind_name d, %d.param
  370. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  371. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  372. // CHECK:STDOUT: }
  373. // CHECK:STDOUT: }
  374. // CHECK:STDOUT:
  375. // CHECK:STDOUT: class @D {
  376. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  377. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  378. // CHECK:STDOUT: complete_type_witness = %complete_type
  379. // CHECK:STDOUT:
  380. // CHECK:STDOUT: !members:
  381. // CHECK:STDOUT: .Self = constants.%D
  382. // CHECK:STDOUT: }
  383. // CHECK:STDOUT:
  384. // CHECK:STDOUT: generic fn @F(%T.loc4_15.1: type) {
  385. // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  386. // CHECK:STDOUT: %pattern_type: type = pattern_type %T.loc4_15.2 [template = %pattern_type (constants.%pattern_type.7dcd0a.1)]
  387. // CHECK:STDOUT:
  388. // CHECK:STDOUT: !definition:
  389. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T.loc4_15.2 [template = %require_complete (constants.%require_complete.4ae)]
  390. // CHECK:STDOUT: %.loc11_11.3: <instruction> = refine_type_action %x.ref, %T.loc4_15.2 [template]
  391. // CHECK:STDOUT: %.loc11_11.4: <instruction> = convert_to_value_action %.loc11_11.1, constants.%i32 [template]
  392. // CHECK:STDOUT:
  393. // CHECK:STDOUT: fn(%x.param: @F.%T.loc4_15.2 (%T)) -> %i32 {
  394. // CHECK:STDOUT: !entry:
  395. // CHECK:STDOUT: %x.ref: @F.%T.loc4_15.2 (%T) = name_ref x, %x
  396. // CHECK:STDOUT: %.loc11_11.1: @F.%T.loc4_15.2 (%T) = splice_inst %.loc11_11.3
  397. // CHECK:STDOUT: %.loc11_11.2: %i32 = splice_inst %.loc11_11.4
  398. // CHECK:STDOUT: return %.loc11_11.2
  399. // CHECK:STDOUT: }
  400. // CHECK:STDOUT: }
  401. // CHECK:STDOUT:
  402. // CHECK:STDOUT: fn @Test(%d.param: %D) -> %i32 {
  403. // CHECK:STDOUT: !entry:
  404. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  405. // CHECK:STDOUT: %d.ref: %D = name_ref d, %d
  406. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F(constants.%D) [concrete = constants.%F.specific_fn]
  407. // CHECK:STDOUT: %F.call: init %i32 = call %F.specific_fn(%d.ref)
  408. // CHECK:STDOUT: %.loc21_14.1: %i32 = value_of_initializer %F.call
  409. // CHECK:STDOUT: %.loc21_14.2: %i32 = converted %F.call, %.loc21_14.1
  410. // CHECK:STDOUT: return %.loc21_14.2
  411. // CHECK:STDOUT: }
  412. // CHECK:STDOUT:
  413. // CHECK:STDOUT: specific @F(constants.%T) {
  414. // CHECK:STDOUT: %T.loc4_15.2 => constants.%T
  415. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7dcd0a.1
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT:
  418. // CHECK:STDOUT: specific @F(constants.%D) {
  419. // CHECK:STDOUT: %T.loc4_15.2 => constants.%D
  420. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.510
  421. // CHECK:STDOUT:
  422. // CHECK:STDOUT: !definition:
  423. // CHECK:STDOUT: %require_complete => constants.%complete_type.357
  424. // CHECK:STDOUT: %.loc11_11.3 => constants.%inst.as_compatible
  425. // CHECK:STDOUT: %.loc11_11.4 => constants.%inst.splice_block
  426. // CHECK:STDOUT: }
  427. // CHECK:STDOUT: