convert.carbon 23 KB

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