init.carbon 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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/class/generic/init.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/init.carbon
  10. // --- from_struct.carbon
  11. library "[[@TEST_NAME]]";
  12. class Class(T:! type) {
  13. var k: T;
  14. }
  15. fn InitFromStructGeneric(T:! type, x: T) -> T {
  16. var v: Class(T) = {.k = x};
  17. return v.k;
  18. }
  19. fn InitFromStructSpecific(x: i32) -> i32 {
  20. var v: Class(i32) = {.k = x};
  21. return v.k;
  22. }
  23. // --- adapt.carbon
  24. library "[[@TEST_NAME]]";
  25. class Adapt(T:! type) {
  26. adapt T;
  27. }
  28. fn InitFromAdaptedGeneric(T:! type, x: T) -> T {
  29. return (x as Adapt(T)) as T;
  30. }
  31. fn InitFromAdaptedSpecific(x: i32) -> i32 {
  32. return (x as Adapt(i32)) as i32;
  33. }
  34. // CHECK:STDOUT: --- from_struct.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  38. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  39. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  40. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  41. // CHECK:STDOUT: %Class.2: type = class_type @Class, @Class(%T) [symbolic]
  42. // CHECK:STDOUT: %.2: type = unbound_element_type %Class.2, %T [symbolic]
  43. // CHECK:STDOUT: %.3: type = struct_type {.k: %T} [symbolic]
  44. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [symbolic]
  45. // CHECK:STDOUT: %InitFromStructGeneric.type: type = fn_type @InitFromStructGeneric [template]
  46. // CHECK:STDOUT: %InitFromStructGeneric: %InitFromStructGeneric.type = struct_value () [template]
  47. // CHECK:STDOUT: %.5: type = ptr_type %.3 [symbolic]
  48. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  49. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  50. // CHECK:STDOUT: %InitFromStructSpecific.type: type = fn_type @InitFromStructSpecific [template]
  51. // CHECK:STDOUT: %InitFromStructSpecific: %InitFromStructSpecific.type = struct_value () [template]
  52. // CHECK:STDOUT: %Class.3: type = class_type @Class, @Class(i32) [template]
  53. // CHECK:STDOUT: %.6: type = unbound_element_type %Class.3, i32 [template]
  54. // CHECK:STDOUT: %.7: type = struct_type {.k: i32} [template]
  55. // CHECK:STDOUT: %.8: <witness> = complete_type_witness %.7 [template]
  56. // CHECK:STDOUT: %.9: type = ptr_type %.7 [template]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: imports {
  60. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  61. // CHECK:STDOUT: .Int32 = %import_ref
  62. // CHECK:STDOUT: import Core//prelude
  63. // CHECK:STDOUT: import Core//prelude/operators
  64. // CHECK:STDOUT: import Core//prelude/types
  65. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  66. // CHECK:STDOUT: import Core//prelude/operators/as
  67. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  68. // CHECK:STDOUT: import Core//prelude/operators/comparison
  69. // CHECK:STDOUT: import Core//prelude/types/bool
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  76. // CHECK:STDOUT: .Core = imports.%Core
  77. // CHECK:STDOUT: .Class = %Class.decl
  78. // CHECK:STDOUT: .InitFromStructGeneric = %InitFromStructGeneric.decl
  79. // CHECK:STDOUT: .InitFromStructSpecific = %InitFromStructSpecific.decl
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %Core.import = import Core
  82. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  83. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  84. // CHECK:STDOUT: } {
  85. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  86. // CHECK:STDOUT: %T.loc4_13.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc4_13.2 (constants.%T)]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %InitFromStructGeneric.decl: %InitFromStructGeneric.type = fn_decl @InitFromStructGeneric [template = constants.%InitFromStructGeneric] {
  89. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  90. // CHECK:STDOUT: %x.patt: @InitFromStructGeneric.%T.loc8_26.2 (%T) = binding_pattern x
  91. // CHECK:STDOUT: } {
  92. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  93. // CHECK:STDOUT: %T.loc8_26.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc8_26.2 (constants.%T)]
  94. // CHECK:STDOUT: %T.ref.loc8_39: type = name_ref T, %T.loc8_26.1 [symbolic = %T.loc8_26.2 (constants.%T)]
  95. // CHECK:STDOUT: %x.param: @InitFromStructGeneric.%T.loc8_26.2 (%T) = param x, runtime_param0
  96. // CHECK:STDOUT: %x: @InitFromStructGeneric.%T.loc8_26.2 (%T) = bind_name x, %x.param
  97. // CHECK:STDOUT: %T.ref.loc8_45: type = name_ref T, %T.loc8_26.1 [symbolic = %T.loc8_26.2 (constants.%T)]
  98. // CHECK:STDOUT: %return: ref @InitFromStructGeneric.%T.loc8_26.2 (%T) = var <return slot>
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: %InitFromStructSpecific.decl: %InitFromStructSpecific.type = fn_decl @InitFromStructSpecific [template = constants.%InitFromStructSpecific] {
  101. // CHECK:STDOUT: %x.patt: i32 = binding_pattern x
  102. // CHECK:STDOUT: } {
  103. // CHECK:STDOUT: %int.make_type_32.loc13_30: init type = call constants.%Int32() [template = i32]
  104. // CHECK:STDOUT: %.loc13_30.1: type = value_of_initializer %int.make_type_32.loc13_30 [template = i32]
  105. // CHECK:STDOUT: %.loc13_30.2: type = converted %int.make_type_32.loc13_30, %.loc13_30.1 [template = i32]
  106. // CHECK:STDOUT: %x.param: i32 = param x, runtime_param0
  107. // CHECK:STDOUT: %x: i32 = bind_name x, %x.param
  108. // CHECK:STDOUT: %int.make_type_32.loc13_38: init type = call constants.%Int32() [template = i32]
  109. // CHECK:STDOUT: %.loc13_38.1: type = value_of_initializer %int.make_type_32.loc13_38 [template = i32]
  110. // CHECK:STDOUT: %.loc13_38.2: type = converted %int.make_type_32.loc13_38, %.loc13_38.1 [template = i32]
  111. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: generic class @Class(%T.loc4_13.1: type) {
  116. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_13.2 (constants.%T)]
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: !definition:
  119. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T.loc4_13.2) [symbolic = %Class (constants.%Class.2)]
  120. // CHECK:STDOUT: %.loc5_8.2: type = unbound_element_type @Class.%Class (%Class.2), @Class.%T.loc4_13.2 (%T) [symbolic = %.loc5_8.2 (constants.%.2)]
  121. // CHECK:STDOUT: %.loc6_1.2: type = struct_type {.k: @Class.%T.loc4_13.2 (%T)} [symbolic = %.loc6_1.2 (constants.%.3)]
  122. // CHECK:STDOUT: %.loc6_1.3: <witness> = complete_type_witness @Class.%.loc6_1.2 (%.3) [symbolic = %.loc6_1.3 (constants.%.4)]
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: class {
  125. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc4_13.1 [symbolic = %T.loc4_13.2 (constants.%T)]
  126. // CHECK:STDOUT: %.loc5_8.1: @Class.%.loc5_8.2 (%.2) = field_decl k, element0 [template]
  127. // CHECK:STDOUT: %.loc6_1.1: <witness> = complete_type_witness %.3 [symbolic = %.loc6_1.3 (constants.%.4)]
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: !members:
  130. // CHECK:STDOUT: .Self = constants.%Class.2
  131. // CHECK:STDOUT: .k = %.loc5_8.1
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: generic fn @InitFromStructGeneric(%T.loc8_26.1: type) {
  136. // CHECK:STDOUT: %T.loc8_26.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc8_26.2 (constants.%T)]
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: !definition:
  139. // CHECK:STDOUT: %Class.loc9_15.2: type = class_type @Class, @Class(%T.loc8_26.2) [symbolic = %Class.loc9_15.2 (constants.%Class.2)]
  140. // CHECK:STDOUT: %.loc9_28.5: type = struct_type {.k: @InitFromStructGeneric.%T.loc8_26.2 (%T)} [symbolic = %.loc9_28.5 (constants.%.3)]
  141. // CHECK:STDOUT: %.loc10_11.3: type = unbound_element_type @InitFromStructGeneric.%Class.loc9_15.2 (%Class.2), @InitFromStructGeneric.%T.loc8_26.2 (%T) [symbolic = %.loc10_11.3 (constants.%.2)]
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: fn(%T.loc8_26.1: type, %x: @InitFromStructGeneric.%T.loc8_26.2 (%T)) -> @InitFromStructGeneric.%T.loc8_26.2 (%T) {
  144. // CHECK:STDOUT: !entry:
  145. // CHECK:STDOUT: %Class.ref: %Class.type = name_ref Class, file.%Class.decl [template = constants.%Class.1]
  146. // CHECK:STDOUT: %T.ref.loc9: type = name_ref T, %T.loc8_26.1 [symbolic = %T.loc8_26.2 (constants.%T)]
  147. // CHECK:STDOUT: %Class.loc9_15.1: type = class_type @Class, @Class(constants.%T) [symbolic = %Class.loc9_15.2 (constants.%Class.2)]
  148. // CHECK:STDOUT: %v.var: ref @InitFromStructGeneric.%Class.loc9_15.2 (%Class.2) = var v
  149. // CHECK:STDOUT: %v: ref @InitFromStructGeneric.%Class.loc9_15.2 (%Class.2) = bind_name v, %v.var
  150. // CHECK:STDOUT: %x.ref: @InitFromStructGeneric.%T.loc8_26.2 (%T) = name_ref x, %x
  151. // CHECK:STDOUT: %.loc9_28.1: @InitFromStructGeneric.%.loc9_28.5 (%.3) = struct_literal (%x.ref)
  152. // CHECK:STDOUT: %.loc9_28.2: ref @InitFromStructGeneric.%T.loc8_26.2 (%T) = class_element_access %v.var, element0
  153. // CHECK:STDOUT: %.loc9_28.3: init @InitFromStructGeneric.%T.loc8_26.2 (%T) = initialize_from %x.ref to %.loc9_28.2
  154. // CHECK:STDOUT: %.loc9_28.4: init @InitFromStructGeneric.%Class.loc9_15.2 (%Class.2) = class_init (%.loc9_28.3), %v.var
  155. // CHECK:STDOUT: %.loc9_29: init @InitFromStructGeneric.%Class.loc9_15.2 (%Class.2) = converted %.loc9_28.1, %.loc9_28.4
  156. // CHECK:STDOUT: assign %v.var, %.loc9_29
  157. // CHECK:STDOUT: %v.ref: ref @InitFromStructGeneric.%Class.loc9_15.2 (%Class.2) = name_ref v, %v
  158. // CHECK:STDOUT: %k.ref: @InitFromStructGeneric.%.loc10_11.3 (%.2) = name_ref k, @Class.%.loc5_8.1 [template = @Class.%.loc5_8.1]
  159. // CHECK:STDOUT: %.loc10_11.1: ref @InitFromStructGeneric.%T.loc8_26.2 (%T) = class_element_access %v.ref, element0
  160. // CHECK:STDOUT: %.loc10_11.2: @InitFromStructGeneric.%T.loc8_26.2 (%T) = bind_value %.loc10_11.1
  161. // CHECK:STDOUT: return %.loc10_11.2
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: fn @InitFromStructSpecific(%x: i32) -> i32 {
  168. // CHECK:STDOUT: !entry:
  169. // CHECK:STDOUT: %Class.ref: %Class.type = name_ref Class, file.%Class.decl [template = constants.%Class.1]
  170. // CHECK:STDOUT: %int.make_type_32.loc14: init type = call constants.%Int32() [template = i32]
  171. // CHECK:STDOUT: %.loc14_15.1: type = value_of_initializer %int.make_type_32.loc14 [template = i32]
  172. // CHECK:STDOUT: %.loc14_15.2: type = converted %int.make_type_32.loc14, %.loc14_15.1 [template = i32]
  173. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(i32) [template = constants.%Class.3]
  174. // CHECK:STDOUT: %v.var: ref %Class.3 = var v
  175. // CHECK:STDOUT: %v: ref %Class.3 = bind_name v, %v.var
  176. // CHECK:STDOUT: %x.ref: i32 = name_ref x, %x
  177. // CHECK:STDOUT: %.loc14_30.1: %.7 = struct_literal (%x.ref)
  178. // CHECK:STDOUT: %.loc14_30.2: ref i32 = class_element_access %v.var, element0
  179. // CHECK:STDOUT: %.loc14_30.3: init i32 = initialize_from %x.ref to %.loc14_30.2
  180. // CHECK:STDOUT: %.loc14_30.4: init %Class.3 = class_init (%.loc14_30.3), %v.var
  181. // CHECK:STDOUT: %.loc14_31: init %Class.3 = converted %.loc14_30.1, %.loc14_30.4
  182. // CHECK:STDOUT: assign %v.var, %.loc14_31
  183. // CHECK:STDOUT: %v.ref: ref %Class.3 = name_ref v, %v
  184. // CHECK:STDOUT: %k.ref: %.6 = name_ref k, @Class.%.loc5_8.1 [template = @Class.%.loc5_8.1]
  185. // CHECK:STDOUT: %.loc15_11.1: ref i32 = class_element_access %v.ref, element0
  186. // CHECK:STDOUT: %.loc15_11.2: i32 = bind_value %.loc15_11.1
  187. // CHECK:STDOUT: return %.loc15_11.2
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: specific @Class(constants.%T) {
  191. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: !definition:
  194. // CHECK:STDOUT: %Class => constants.%Class.2
  195. // CHECK:STDOUT: %.loc5_8.2 => constants.%.2
  196. // CHECK:STDOUT: %.loc6_1.2 => constants.%.3
  197. // CHECK:STDOUT: %.loc6_1.3 => constants.%.4
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: specific @Class(@Class.%T.loc4_13.2) {
  201. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: specific @InitFromStructGeneric(constants.%T) {
  205. // CHECK:STDOUT: %T.loc8_26.2 => constants.%T
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: specific @Class(@InitFromStructGeneric.%T.loc8_26.2) {
  209. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: specific @Class(i32) {
  213. // CHECK:STDOUT: %T.loc4_13.2 => i32
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: !definition:
  216. // CHECK:STDOUT: %Class => constants.%Class.3
  217. // CHECK:STDOUT: %.loc5_8.2 => constants.%.6
  218. // CHECK:STDOUT: %.loc6_1.2 => constants.%.7
  219. // CHECK:STDOUT: %.loc6_1.3 => constants.%.8
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: --- adapt.carbon
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: constants {
  225. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  226. // CHECK:STDOUT: %Adapt.type: type = generic_class_type @Adapt [template]
  227. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  228. // CHECK:STDOUT: %Adapt.1: %Adapt.type = struct_value () [template]
  229. // CHECK:STDOUT: %Adapt.2: type = class_type @Adapt, @Adapt(%T) [symbolic]
  230. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %T [symbolic]
  231. // CHECK:STDOUT: %InitFromAdaptedGeneric.type: type = fn_type @InitFromAdaptedGeneric [template]
  232. // CHECK:STDOUT: %InitFromAdaptedGeneric: %InitFromAdaptedGeneric.type = struct_value () [template]
  233. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  234. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  235. // CHECK:STDOUT: %InitFromAdaptedSpecific.type: type = fn_type @InitFromAdaptedSpecific [template]
  236. // CHECK:STDOUT: %InitFromAdaptedSpecific: %InitFromAdaptedSpecific.type = struct_value () [template]
  237. // CHECK:STDOUT: %Adapt.3: type = class_type @Adapt, @Adapt(i32) [template]
  238. // CHECK:STDOUT: %.3: <witness> = complete_type_witness i32 [template]
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT:
  241. // CHECK:STDOUT: imports {
  242. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  243. // CHECK:STDOUT: .Int32 = %import_ref
  244. // CHECK:STDOUT: import Core//prelude
  245. // CHECK:STDOUT: import Core//prelude/operators
  246. // CHECK:STDOUT: import Core//prelude/types
  247. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  248. // CHECK:STDOUT: import Core//prelude/operators/as
  249. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  250. // CHECK:STDOUT: import Core//prelude/operators/comparison
  251. // CHECK:STDOUT: import Core//prelude/types/bool
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: file {
  257. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  258. // CHECK:STDOUT: .Core = imports.%Core
  259. // CHECK:STDOUT: .Adapt = %Adapt.decl
  260. // CHECK:STDOUT: .InitFromAdaptedGeneric = %InitFromAdaptedGeneric.decl
  261. // CHECK:STDOUT: .InitFromAdaptedSpecific = %InitFromAdaptedSpecific.decl
  262. // CHECK:STDOUT: }
  263. // CHECK:STDOUT: %Core.import = import Core
  264. // CHECK:STDOUT: %Adapt.decl: %Adapt.type = class_decl @Adapt [template = constants.%Adapt.1] {
  265. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  266. // CHECK:STDOUT: } {
  267. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  268. // CHECK:STDOUT: %T.loc4_13.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc4_13.2 (constants.%T)]
  269. // CHECK:STDOUT: }
  270. // CHECK:STDOUT: %InitFromAdaptedGeneric.decl: %InitFromAdaptedGeneric.type = fn_decl @InitFromAdaptedGeneric [template = constants.%InitFromAdaptedGeneric] {
  271. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  272. // CHECK:STDOUT: %x.patt: @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) = binding_pattern x
  273. // CHECK:STDOUT: } {
  274. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  275. // CHECK:STDOUT: %T.loc8_27.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc8_27.2 (constants.%T)]
  276. // CHECK:STDOUT: %T.ref.loc8_40: type = name_ref T, %T.loc8_27.1 [symbolic = %T.loc8_27.2 (constants.%T)]
  277. // CHECK:STDOUT: %x.param: @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) = param x, runtime_param0
  278. // CHECK:STDOUT: %x: @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) = bind_name x, %x.param
  279. // CHECK:STDOUT: %T.ref.loc8_46: type = name_ref T, %T.loc8_27.1 [symbolic = %T.loc8_27.2 (constants.%T)]
  280. // CHECK:STDOUT: %return: ref @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) = var <return slot>
  281. // CHECK:STDOUT: }
  282. // CHECK:STDOUT: %InitFromAdaptedSpecific.decl: %InitFromAdaptedSpecific.type = fn_decl @InitFromAdaptedSpecific [template = constants.%InitFromAdaptedSpecific] {
  283. // CHECK:STDOUT: %x.patt: i32 = binding_pattern x
  284. // CHECK:STDOUT: } {
  285. // CHECK:STDOUT: %int.make_type_32.loc12_31: init type = call constants.%Int32() [template = i32]
  286. // CHECK:STDOUT: %.loc12_31.1: type = value_of_initializer %int.make_type_32.loc12_31 [template = i32]
  287. // CHECK:STDOUT: %.loc12_31.2: type = converted %int.make_type_32.loc12_31, %.loc12_31.1 [template = i32]
  288. // CHECK:STDOUT: %x.param: i32 = param x, runtime_param0
  289. // CHECK:STDOUT: %x: i32 = bind_name x, %x.param
  290. // CHECK:STDOUT: %int.make_type_32.loc12_39: init type = call constants.%Int32() [template = i32]
  291. // CHECK:STDOUT: %.loc12_39.1: type = value_of_initializer %int.make_type_32.loc12_39 [template = i32]
  292. // CHECK:STDOUT: %.loc12_39.2: type = converted %int.make_type_32.loc12_39, %.loc12_39.1 [template = i32]
  293. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  294. // CHECK:STDOUT: }
  295. // CHECK:STDOUT: }
  296. // CHECK:STDOUT:
  297. // CHECK:STDOUT: generic class @Adapt(%T.loc4_13.1: type) {
  298. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_13.2 (constants.%T)]
  299. // CHECK:STDOUT:
  300. // CHECK:STDOUT: !definition:
  301. // CHECK:STDOUT: %.loc6_1.2: <witness> = complete_type_witness @Adapt.%T.loc4_13.2 (%T) [symbolic = %.loc6_1.2 (constants.%.2)]
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: class {
  304. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc4_13.1 [symbolic = %T.loc4_13.2 (constants.%T)]
  305. // CHECK:STDOUT: adapt_decl %T
  306. // CHECK:STDOUT: %.loc6_1.1: <witness> = complete_type_witness %T [symbolic = %.loc6_1.2 (constants.%.2)]
  307. // CHECK:STDOUT:
  308. // CHECK:STDOUT: !members:
  309. // CHECK:STDOUT: .Self = constants.%Adapt.2
  310. // CHECK:STDOUT: }
  311. // CHECK:STDOUT: }
  312. // CHECK:STDOUT:
  313. // CHECK:STDOUT: generic fn @InitFromAdaptedGeneric(%T.loc8_27.1: type) {
  314. // CHECK:STDOUT: %T.loc8_27.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc8_27.2 (constants.%T)]
  315. // CHECK:STDOUT:
  316. // CHECK:STDOUT: !definition:
  317. // CHECK:STDOUT: %Adapt.loc9_21.2: type = class_type @Adapt, @Adapt(%T.loc8_27.2) [symbolic = %Adapt.loc9_21.2 (constants.%Adapt.2)]
  318. // CHECK:STDOUT:
  319. // CHECK:STDOUT: fn(%T.loc8_27.1: type, %x: @InitFromAdaptedGeneric.%T.loc8_27.2 (%T)) -> @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) {
  320. // CHECK:STDOUT: !entry:
  321. // CHECK:STDOUT: %x.ref: @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) = name_ref x, %x
  322. // CHECK:STDOUT: %Adapt.ref: %Adapt.type = name_ref Adapt, file.%Adapt.decl [template = constants.%Adapt.1]
  323. // CHECK:STDOUT: %T.ref.loc9_22: type = name_ref T, %T.loc8_27.1 [symbolic = %T.loc8_27.2 (constants.%T)]
  324. // CHECK:STDOUT: %Adapt.loc9_21.1: type = class_type @Adapt, @Adapt(constants.%T) [symbolic = %Adapt.loc9_21.2 (constants.%Adapt.2)]
  325. // CHECK:STDOUT: %.loc9_13.1: @InitFromAdaptedGeneric.%Adapt.loc9_21.2 (%Adapt.2) = as_compatible %x.ref
  326. // CHECK:STDOUT: %.loc9_13.2: @InitFromAdaptedGeneric.%Adapt.loc9_21.2 (%Adapt.2) = converted %x.ref, %.loc9_13.1
  327. // CHECK:STDOUT: %T.ref.loc9_29: type = name_ref T, %T.loc8_27.1 [symbolic = %T.loc8_27.2 (constants.%T)]
  328. // CHECK:STDOUT: %.loc9_26.1: @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) = as_compatible %.loc9_13.2
  329. // CHECK:STDOUT: %.loc9_26.2: @InitFromAdaptedGeneric.%T.loc8_27.2 (%T) = converted %.loc9_13.2, %.loc9_26.1
  330. // CHECK:STDOUT: return %.loc9_26.2
  331. // CHECK:STDOUT: }
  332. // CHECK:STDOUT: }
  333. // CHECK:STDOUT:
  334. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: fn @InitFromAdaptedSpecific(%x: i32) -> i32 {
  337. // CHECK:STDOUT: !entry:
  338. // CHECK:STDOUT: %x.ref: i32 = name_ref x, %x
  339. // CHECK:STDOUT: %Adapt.ref: %Adapt.type = name_ref Adapt, file.%Adapt.decl [template = constants.%Adapt.1]
  340. // CHECK:STDOUT: %int.make_type_32.loc13_22: init type = call constants.%Int32() [template = i32]
  341. // CHECK:STDOUT: %.loc13_21.1: type = value_of_initializer %int.make_type_32.loc13_22 [template = i32]
  342. // CHECK:STDOUT: %.loc13_21.2: type = converted %int.make_type_32.loc13_22, %.loc13_21.1 [template = i32]
  343. // CHECK:STDOUT: %Adapt: type = class_type @Adapt, @Adapt(i32) [template = constants.%Adapt.3]
  344. // CHECK:STDOUT: %.loc13_13.1: %Adapt.3 = as_compatible %x.ref
  345. // CHECK:STDOUT: %.loc13_13.2: %Adapt.3 = converted %x.ref, %.loc13_13.1
  346. // CHECK:STDOUT: %int.make_type_32.loc13_31: init type = call constants.%Int32() [template = i32]
  347. // CHECK:STDOUT: %.loc13_31.1: type = value_of_initializer %int.make_type_32.loc13_31 [template = i32]
  348. // CHECK:STDOUT: %.loc13_31.2: type = converted %int.make_type_32.loc13_31, %.loc13_31.1 [template = i32]
  349. // CHECK:STDOUT: %.loc13_28.1: i32 = as_compatible %.loc13_13.2
  350. // CHECK:STDOUT: %.loc13_28.2: i32 = converted %.loc13_13.2, %.loc13_28.1
  351. // CHECK:STDOUT: return %.loc13_28.2
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: specific @Adapt(constants.%T) {
  355. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: !definition:
  358. // CHECK:STDOUT: %.loc6_1.2 => constants.%.2
  359. // CHECK:STDOUT: }
  360. // CHECK:STDOUT:
  361. // CHECK:STDOUT: specific @InitFromAdaptedGeneric(constants.%T) {
  362. // CHECK:STDOUT: %T.loc8_27.2 => constants.%T
  363. // CHECK:STDOUT: }
  364. // CHECK:STDOUT:
  365. // CHECK:STDOUT: specific @Adapt(@InitFromAdaptedGeneric.%T.loc8_27.2) {
  366. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  367. // CHECK:STDOUT: }
  368. // CHECK:STDOUT:
  369. // CHECK:STDOUT: specific @Adapt(i32) {
  370. // CHECK:STDOUT: %T.loc4_13.2 => i32
  371. // CHECK:STDOUT:
  372. // CHECK:STDOUT: !definition:
  373. // CHECK:STDOUT: %.loc6_1.2 => constants.%.3
  374. // CHECK:STDOUT: }
  375. // CHECK:STDOUT: