init.carbon 26 KB

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