convert.carbon 30 KB

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