convert.carbon 30 KB

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