implicit_as.carbon 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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/operators/overloaded/implicit_as.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/implicit_as.carbon
  10. class X {
  11. var n: i32;
  12. }
  13. impl i32 as Core.ImplicitAs(X) {
  14. fn Convert[self: i32]() -> X { return {.n = self}; }
  15. }
  16. impl X as Core.ImplicitAs(i32) {
  17. fn Convert[self: X]() -> i32 { return self.n; }
  18. }
  19. // TODO: fn Sink(T:! type, x: T);
  20. // ... once we stop deducing `T` from the type of the second argument in this case.
  21. fn Sink_i32(n: i32);
  22. fn Sink_X(x: X);
  23. fn Source(T:! type) -> T;
  24. fn Test() {
  25. Sink_i32(Source(X));
  26. Sink_X(Source(i32));
  27. }
  28. // CHECK:STDOUT: --- implicit_as.carbon
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: constants {
  31. // CHECK:STDOUT: %X: type = class_type @X [template]
  32. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  33. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  34. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  35. // CHECK:STDOUT: %.2: type = unbound_element_type %X, i32 [template]
  36. // CHECK:STDOUT: %.3: type = struct_type {.n: i32} [template]
  37. // CHECK:STDOUT: %ImplicitAs.type: type = generic_interface_type @ImplicitAs [template]
  38. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type = struct_value () [template]
  39. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic]
  40. // CHECK:STDOUT: %.4: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  41. // CHECK:STDOUT: %Self.1: @ImplicitAs.%.1 (%.4) = bind_symbolic_name Self 1 [symbolic]
  42. // CHECK:STDOUT: %Self.2: %.4 = bind_symbolic_name Self 1 [symbolic]
  43. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert.1, @ImplicitAs(%Dest) [symbolic]
  44. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  45. // CHECK:STDOUT: %.5: type = assoc_entity_type %.4, %Convert.type.1 [symbolic]
  46. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  47. // CHECK:STDOUT: %.7: type = interface_type @ImplicitAs, @ImplicitAs(%X) [template]
  48. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.2 [template]
  49. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  50. // CHECK:STDOUT: %Convert.type.3: type = fn_type @Convert.1, @ImplicitAs(%X) [template]
  51. // CHECK:STDOUT: %Convert.3: %Convert.type.3 = struct_value () [template]
  52. // CHECK:STDOUT: %.8: type = assoc_entity_type %.7, %Convert.type.3 [template]
  53. // CHECK:STDOUT: %.9: %.8 = assoc_entity element0, imports.%import_ref.6 [template]
  54. // CHECK:STDOUT: %.10: <witness> = interface_witness (%Convert.2) [template]
  55. // CHECK:STDOUT: %.11: type = ptr_type %.3 [template]
  56. // CHECK:STDOUT: %.12: type = interface_type @ImplicitAs, @ImplicitAs(i32) [template]
  57. // CHECK:STDOUT: %Convert.type.4: type = fn_type @Convert.3 [template]
  58. // CHECK:STDOUT: %Convert.4: %Convert.type.4 = struct_value () [template]
  59. // CHECK:STDOUT: %Convert.type.5: type = fn_type @Convert.1, @ImplicitAs(i32) [template]
  60. // CHECK:STDOUT: %Convert.5: %Convert.type.5 = struct_value () [template]
  61. // CHECK:STDOUT: %.13: type = assoc_entity_type %.12, %Convert.type.5 [template]
  62. // CHECK:STDOUT: %.14: %.13 = assoc_entity element0, imports.%import_ref.6 [template]
  63. // CHECK:STDOUT: %.15: <witness> = interface_witness (%Convert.4) [template]
  64. // CHECK:STDOUT: %Sink_i32.type: type = fn_type @Sink_i32 [template]
  65. // CHECK:STDOUT: %Sink_i32: %Sink_i32.type = struct_value () [template]
  66. // CHECK:STDOUT: %Sink_X.type: type = fn_type @Sink_X [template]
  67. // CHECK:STDOUT: %Sink_X: %Sink_X.type = struct_value () [template]
  68. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  69. // CHECK:STDOUT: %Source.type: type = fn_type @Source [template]
  70. // CHECK:STDOUT: %Source: %Source.type = struct_value () [template]
  71. // CHECK:STDOUT: %Test.type: type = fn_type @Test [template]
  72. // CHECK:STDOUT: %Test: %Test.type = struct_value () [template]
  73. // CHECK:STDOUT: %.16: %.5 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: imports {
  77. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  78. // CHECK:STDOUT: .Int32 = %import_ref.1
  79. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  80. // CHECK:STDOUT: import Core//prelude
  81. // CHECK:STDOUT: import Core//prelude/operators
  82. // CHECK:STDOUT: import Core//prelude/types
  83. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  84. // CHECK:STDOUT: import Core//prelude/operators/as
  85. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  86. // CHECK:STDOUT: import Core//prelude/operators/comparison
  87. // CHECK:STDOUT: import Core//prelude/types/bool
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  90. // CHECK:STDOUT: %import_ref.2: %ImplicitAs.type = import_ref Core//prelude/operators/as, inst+37, loaded [template = constants.%ImplicitAs]
  91. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/as, inst+42, unloaded
  92. // CHECK:STDOUT: %import_ref.4: @ImplicitAs.%.2 (%.5) = import_ref Core//prelude/operators/as, inst+59, loaded [symbolic = @ImplicitAs.%.3 (constants.%.16)]
  93. // CHECK:STDOUT: %import_ref.5: @ImplicitAs.%Convert.type (%Convert.type.1) = import_ref Core//prelude/operators/as, inst+52, loaded [symbolic = @ImplicitAs.%Convert (constants.%Convert.1)]
  94. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+52, unloaded
  95. // CHECK:STDOUT: %import_ref.7 = import_ref Core//prelude/operators/as, inst+52, unloaded
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: file {
  99. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  100. // CHECK:STDOUT: .Core = imports.%Core
  101. // CHECK:STDOUT: .X = %X.decl
  102. // CHECK:STDOUT: .Sink_i32 = %Sink_i32.decl
  103. // CHECK:STDOUT: .Sink_X = %Sink_X.decl
  104. // CHECK:STDOUT: .Source = %Source.decl
  105. // CHECK:STDOUT: .Test = %Test.decl
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %Core.import = import Core
  108. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {}
  109. // CHECK:STDOUT: %.loc15_30.1: type = value_of_initializer %.loc15_28 [template = constants.%.7]
  110. // CHECK:STDOUT: %.loc15_30.2: type = converted %.loc15_28, %.loc15_30.1 [template = constants.%.7]
  111. // CHECK:STDOUT: impl_decl @impl.1 {
  112. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  113. // CHECK:STDOUT: %.loc15_6.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  114. // CHECK:STDOUT: %.loc15_6.2: type = converted %int.make_type_32.loc15, %.loc15_6.1 [template = i32]
  115. // CHECK:STDOUT: %Core.ref.loc15: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  116. // CHECK:STDOUT: %ImplicitAs.ref.loc15: %ImplicitAs.type = name_ref ImplicitAs, imports.%import_ref.2 [template = constants.%ImplicitAs]
  117. // CHECK:STDOUT: %X.ref.loc15: type = name_ref X, %X.decl [template = constants.%X]
  118. // CHECK:STDOUT: %.loc15_28: init type = call %ImplicitAs.ref.loc15(%X.ref.loc15) [template = constants.%.7]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %.loc19_30.1: type = value_of_initializer %.loc19_26.3 [template = constants.%.12]
  121. // CHECK:STDOUT: %.loc19_30.2: type = converted %.loc19_26.3, %.loc19_30.1 [template = constants.%.12]
  122. // CHECK:STDOUT: impl_decl @impl.2 {
  123. // CHECK:STDOUT: %X.ref.loc19: type = name_ref X, %X.decl [template = constants.%X]
  124. // CHECK:STDOUT: %Core.ref.loc19: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  125. // CHECK:STDOUT: %ImplicitAs.ref.loc19: %ImplicitAs.type = name_ref ImplicitAs, imports.%import_ref.2 [template = constants.%ImplicitAs]
  126. // CHECK:STDOUT: %int.make_type_32.loc19: init type = call constants.%Int32() [template = i32]
  127. // CHECK:STDOUT: %.loc19_26.1: type = value_of_initializer %int.make_type_32.loc19 [template = i32]
  128. // CHECK:STDOUT: %.loc19_26.2: type = converted %int.make_type_32.loc19, %.loc19_26.1 [template = i32]
  129. // CHECK:STDOUT: %.loc19_26.3: init type = call %ImplicitAs.ref.loc19(%.loc19_26.2) [template = constants.%.12]
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %Sink_i32.decl: %Sink_i32.type = fn_decl @Sink_i32 [template = constants.%Sink_i32] {
  132. // CHECK:STDOUT: %int.make_type_32.loc25: init type = call constants.%Int32() [template = i32]
  133. // CHECK:STDOUT: %.loc25_16.1: type = value_of_initializer %int.make_type_32.loc25 [template = i32]
  134. // CHECK:STDOUT: %.loc25_16.2: type = converted %int.make_type_32.loc25, %.loc25_16.1 [template = i32]
  135. // CHECK:STDOUT: %n.loc25_13.1: i32 = param n
  136. // CHECK:STDOUT: @Sink_i32.%n: i32 = bind_name n, %n.loc25_13.1
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %Sink_X.decl: %Sink_X.type = fn_decl @Sink_X [template = constants.%Sink_X] {
  139. // CHECK:STDOUT: %X.ref.loc26: type = name_ref X, %X.decl [template = constants.%X]
  140. // CHECK:STDOUT: %x.loc26_11.1: %X = param x
  141. // CHECK:STDOUT: @Sink_X.%x: %X = bind_name x, %x.loc26_11.1
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %Source.decl: %Source.type = fn_decl @Source [template = constants.%Source] {
  144. // CHECK:STDOUT: %T.loc27_11.1: type = param T
  145. // CHECK:STDOUT: @Source.%T.loc27: type = bind_symbolic_name T 0, %T.loc27_11.1 [symbolic = @Source.%T.1 (constants.%T)]
  146. // CHECK:STDOUT: %T.ref: type = name_ref T, @Source.%T.loc27 [symbolic = @Source.%T.1 (constants.%T)]
  147. // CHECK:STDOUT: @Source.%return: ref @Source.%T.1 (%T) = var <return slot>
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: %Test.decl: %Test.type = fn_decl @Test [template = constants.%Test] {}
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  153. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: !definition:
  156. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.4)]
  157. // CHECK:STDOUT: %Self: %.4 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  158. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert.1, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  159. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  160. // CHECK:STDOUT: %.2: type = assoc_entity_type @ImplicitAs.%.1 (%.4), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.2 (constants.%.5)]
  161. // CHECK:STDOUT: %.3: @ImplicitAs.%.2 (%.5) = assoc_entity element0, imports.%import_ref.6 [symbolic = %.3 (constants.%.6)]
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: interface {
  164. // CHECK:STDOUT: !members:
  165. // CHECK:STDOUT: .Self = imports.%import_ref.3
  166. // CHECK:STDOUT: .Convert = imports.%import_ref.4
  167. // CHECK:STDOUT: witness = (imports.%import_ref.5)
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: impl @impl.1: i32 as %.7 {
  172. // CHECK:STDOUT: %Convert.decl: %Convert.type.2 = fn_decl @Convert.2 [template = constants.%Convert.2] {
  173. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  174. // CHECK:STDOUT: %.loc16_20.1: type = value_of_initializer %int.make_type_32 [template = i32]
  175. // CHECK:STDOUT: %.loc16_20.2: type = converted %int.make_type_32, %.loc16_20.1 [template = i32]
  176. // CHECK:STDOUT: %self.loc16_14.1: i32 = param self
  177. // CHECK:STDOUT: %self.loc16_14.2: i32 = bind_name self, %self.loc16_14.1
  178. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  179. // CHECK:STDOUT: %return.var: ref %X = var <return slot>
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT: %.loc15: <witness> = interface_witness (%Convert.decl) [template = constants.%.10]
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: !members:
  184. // CHECK:STDOUT: .Convert = %Convert.decl
  185. // CHECK:STDOUT: witness = %.loc15
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: impl @impl.2: %X as %.12 {
  189. // CHECK:STDOUT: %Convert.decl: %Convert.type.4 = fn_decl @Convert.3 [template = constants.%Convert.4] {
  190. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  191. // CHECK:STDOUT: %self.loc20_14.1: %X = param self
  192. // CHECK:STDOUT: %self.loc20_14.2: %X = bind_name self, %self.loc20_14.1
  193. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  194. // CHECK:STDOUT: %.loc20_28.1: type = value_of_initializer %int.make_type_32 [template = i32]
  195. // CHECK:STDOUT: %.loc20_28.2: type = converted %int.make_type_32, %.loc20_28.1 [template = i32]
  196. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT: %.loc19: <witness> = interface_witness (%Convert.decl) [template = constants.%.15]
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: !members:
  201. // CHECK:STDOUT: .Convert = %Convert.decl
  202. // CHECK:STDOUT: witness = %.loc19
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: class @X {
  206. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  207. // CHECK:STDOUT: %.loc12_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  208. // CHECK:STDOUT: %.loc12_10.2: type = converted %int.make_type_32, %.loc12_10.1 [template = i32]
  209. // CHECK:STDOUT: %.loc12_8: %.2 = field_decl n, element0 [template]
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: !members:
  212. // CHECK:STDOUT: .Self = constants.%X
  213. // CHECK:STDOUT: .n = %.loc12_8
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: generic fn @Convert.1(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%.1 (%.4)) {
  219. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  220. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.4)]
  221. // CHECK:STDOUT: %Self: %.4 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  222. // CHECK:STDOUT:
  223. // CHECK:STDOUT: fn[%self: @Convert.1.%Self (%Self.2)]() -> @Convert.1.%Dest (%Dest);
  224. // CHECK:STDOUT: }
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: fn @Convert.2[@impl.1.%self.loc16_14.2: i32]() -> @impl.1.%return.var: %X {
  227. // CHECK:STDOUT: !entry:
  228. // CHECK:STDOUT: %self.ref: i32 = name_ref self, @impl.1.%self.loc16_14.2
  229. // CHECK:STDOUT: %.loc16_51.1: %.3 = struct_literal (%self.ref)
  230. // CHECK:STDOUT: %.loc16_51.2: ref i32 = class_element_access @impl.1.%return.var, element0
  231. // CHECK:STDOUT: %.loc16_51.3: init i32 = initialize_from %self.ref to %.loc16_51.2
  232. // CHECK:STDOUT: %.loc16_51.4: init %X = class_init (%.loc16_51.3), @impl.1.%return.var
  233. // CHECK:STDOUT: %.loc16_52: init %X = converted %.loc16_51.1, %.loc16_51.4
  234. // CHECK:STDOUT: return %.loc16_52 to @impl.1.%return.var
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: fn @Convert.3[@impl.2.%self.loc20_14.2: %X]() -> i32 {
  238. // CHECK:STDOUT: !entry:
  239. // CHECK:STDOUT: %self.ref: %X = name_ref self, @impl.2.%self.loc20_14.2
  240. // CHECK:STDOUT: %n.ref: %.2 = name_ref n, @X.%.loc12_8 [template = @X.%.loc12_8]
  241. // CHECK:STDOUT: %.loc20_45.1: ref i32 = class_element_access %self.ref, element0
  242. // CHECK:STDOUT: %.loc20_45.2: i32 = bind_value %.loc20_45.1
  243. // CHECK:STDOUT: return %.loc20_45.2
  244. // CHECK:STDOUT: }
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: fn @Sink_i32(%n: i32);
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: fn @Sink_X(%x: %X);
  249. // CHECK:STDOUT:
  250. // CHECK:STDOUT: generic fn @Source(%T.loc27: type) {
  251. // CHECK:STDOUT: %T.1: type = bind_symbolic_name T 0 [symbolic = %T.1 (constants.%T)]
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: fn(%T.loc27: type) -> @Source.%T.1 (%T);
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: fn @Test() {
  257. // CHECK:STDOUT: !entry:
  258. // CHECK:STDOUT: %Sink_i32.ref: %Sink_i32.type = name_ref Sink_i32, file.%Sink_i32.decl [template = constants.%Sink_i32]
  259. // CHECK:STDOUT: %Source.ref.loc30: %Source.type = name_ref Source, file.%Source.decl [template = constants.%Source]
  260. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  261. // CHECK:STDOUT: %.loc30_18.1: ref %X = temporary_storage
  262. // CHECK:STDOUT: %Source.call.loc30: init %X = call %Source.ref.loc30(%X.ref) to %.loc30_18.1
  263. // CHECK:STDOUT: %.loc30_11.1: init type = call constants.%ImplicitAs(i32) [template = constants.%.12]
  264. // CHECK:STDOUT: %.loc30_11.2: %.13 = specific_constant imports.%import_ref.4, @ImplicitAs(i32) [template = constants.%.14]
  265. // CHECK:STDOUT: %Convert.ref.loc30: %.13 = name_ref Convert, %.loc30_11.2 [template = constants.%.14]
  266. // CHECK:STDOUT: %.loc30_18.2: ref %X = temporary %.loc30_18.1, %Source.call.loc30
  267. // CHECK:STDOUT: %.loc30_11.3: %Convert.type.5 = interface_witness_access @impl.2.%.loc19, element0 [template = constants.%Convert.4]
  268. // CHECK:STDOUT: %.loc30_11.4: <bound method> = bound_method %.loc30_18.2, %.loc30_11.3
  269. // CHECK:STDOUT: %.loc30_18.3: %X = bind_value %.loc30_18.2
  270. // CHECK:STDOUT: %Convert.call.loc30: init i32 = call %.loc30_11.4(%.loc30_18.3)
  271. // CHECK:STDOUT: %.loc30_11.5: init i32 = converted %Source.call.loc30, %Convert.call.loc30
  272. // CHECK:STDOUT: %.loc30_11.6: ref i32 = temporary_storage
  273. // CHECK:STDOUT: %.loc30_11.7: ref i32 = temporary %.loc30_11.6, %.loc30_11.5
  274. // CHECK:STDOUT: %.loc30_11.8: %X = bind_value %.loc30_11.7
  275. // CHECK:STDOUT: %Sink_i32.call: init %.1 = call %Sink_i32.ref(%.loc30_11.8)
  276. // CHECK:STDOUT: %Sink_X.ref: %Sink_X.type = name_ref Sink_X, file.%Sink_X.decl [template = constants.%Sink_X]
  277. // CHECK:STDOUT: %Source.ref.loc31: %Source.type = name_ref Source, file.%Source.decl [template = constants.%Source]
  278. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  279. // CHECK:STDOUT: %.loc31_16.1: type = value_of_initializer %int.make_type_32 [template = i32]
  280. // CHECK:STDOUT: %.loc31_16.2: type = converted %int.make_type_32, %.loc31_16.1 [template = i32]
  281. // CHECK:STDOUT: %Source.call.loc31: init i32 = call %Source.ref.loc31(%.loc31_16.2)
  282. // CHECK:STDOUT: %.loc31_9.1: init type = call constants.%ImplicitAs(constants.%X) [template = constants.%.7]
  283. // CHECK:STDOUT: %.loc31_9.2: %.8 = specific_constant imports.%import_ref.4, @ImplicitAs(constants.%X) [template = constants.%.9]
  284. // CHECK:STDOUT: %Convert.ref.loc31: %.8 = name_ref Convert, %.loc31_9.2 [template = constants.%.9]
  285. // CHECK:STDOUT: %.loc31_16.3: ref i32 = temporary_storage
  286. // CHECK:STDOUT: %.loc31_16.4: ref i32 = temporary %.loc31_16.3, %Source.call.loc31
  287. // CHECK:STDOUT: %.loc31_9.3: %Convert.type.3 = interface_witness_access @impl.1.%.loc15, element0 [template = constants.%Convert.2]
  288. // CHECK:STDOUT: %.loc31_9.4: <bound method> = bound_method %.loc31_16.4, %.loc31_9.3
  289. // CHECK:STDOUT: %.loc31_9.5: ref %X = temporary_storage
  290. // CHECK:STDOUT: %.loc31_16.5: i32 = bind_value %.loc31_16.4
  291. // CHECK:STDOUT: %Convert.call.loc31: init %X = call %.loc31_9.4(%.loc31_16.5) to %.loc31_9.5
  292. // CHECK:STDOUT: %.loc31_9.6: init %X = converted %Source.call.loc31, %Convert.call.loc31
  293. // CHECK:STDOUT: %.loc31_9.7: ref %X = temporary %.loc31_9.5, %.loc31_9.6
  294. // CHECK:STDOUT: %.loc31_9.8: i32 = bind_value %.loc31_9.7
  295. // CHECK:STDOUT: %Sink_X.call: init %.1 = call %Sink_X.ref(%.loc31_9.8)
  296. // CHECK:STDOUT: return
  297. // CHECK:STDOUT: }
  298. // CHECK:STDOUT:
  299. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  300. // CHECK:STDOUT: %Dest => constants.%Dest
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  304. // CHECK:STDOUT: %Dest => constants.%Dest
  305. // CHECK:STDOUT: }
  306. // CHECK:STDOUT:
  307. // CHECK:STDOUT: specific @ImplicitAs(@Convert.1.%Dest) {
  308. // CHECK:STDOUT: %Dest => constants.%Dest
  309. // CHECK:STDOUT: }
  310. // CHECK:STDOUT:
  311. // CHECK:STDOUT: specific @Convert.1(constants.%Dest, constants.%Self.1) {
  312. // CHECK:STDOUT: %Dest => constants.%Dest
  313. // CHECK:STDOUT: %.1 => constants.%.4
  314. // CHECK:STDOUT: %Self => constants.%Self.1
  315. // CHECK:STDOUT: }
  316. // CHECK:STDOUT:
  317. // CHECK:STDOUT: specific @ImplicitAs(constants.%X) {
  318. // CHECK:STDOUT: %Dest => constants.%X
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: !definition:
  321. // CHECK:STDOUT: %.1 => constants.%.7
  322. // CHECK:STDOUT: %Self => constants.%Self.2
  323. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.3
  324. // CHECK:STDOUT: %Convert => constants.%Convert.3
  325. // CHECK:STDOUT: %.2 => constants.%.8
  326. // CHECK:STDOUT: %.3 => constants.%.9
  327. // CHECK:STDOUT: }
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: specific @Convert.1(constants.%X, i32) {
  330. // CHECK:STDOUT: %Dest => constants.%X
  331. // CHECK:STDOUT: %.1 => constants.%.7
  332. // CHECK:STDOUT: %Self => i32
  333. // CHECK:STDOUT: }
  334. // CHECK:STDOUT:
  335. // CHECK:STDOUT: specific @ImplicitAs(i32) {
  336. // CHECK:STDOUT: %Dest => i32
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: !definition:
  339. // CHECK:STDOUT: %.1 => constants.%.12
  340. // CHECK:STDOUT: %Self => constants.%Self.2
  341. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.5
  342. // CHECK:STDOUT: %Convert => constants.%Convert.5
  343. // CHECK:STDOUT: %.2 => constants.%.13
  344. // CHECK:STDOUT: %.3 => constants.%.14
  345. // CHECK:STDOUT: }
  346. // CHECK:STDOUT:
  347. // CHECK:STDOUT: specific @Convert.1(i32, constants.%X) {
  348. // CHECK:STDOUT: %Dest => i32
  349. // CHECK:STDOUT: %.1 => constants.%.12
  350. // CHECK:STDOUT: %Self => constants.%X
  351. // CHECK:STDOUT: }
  352. // CHECK:STDOUT:
  353. // CHECK:STDOUT: specific @Source(constants.%T) {
  354. // CHECK:STDOUT: %T.1 => constants.%T
  355. // CHECK:STDOUT: }
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: specific @Source(constants.%X) {
  358. // CHECK:STDOUT: %T.1 => constants.%X
  359. // CHECK:STDOUT: }
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: specific @Source(i32) {
  362. // CHECK:STDOUT: %T.1 => i32
  363. // CHECK:STDOUT: }
  364. // CHECK:STDOUT: