dependent_param.carbon 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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/generic/dependent_param.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/dependent_param.carbon
  10. // --- nested_class.carbon
  11. library "[[@TEST_NAME]]";
  12. class Outer(T:! type) {
  13. class Inner(U:! T) {
  14. fn Get() -> T { return U; }
  15. }
  16. }
  17. var n: i32 = Outer(i32).Inner(42).Get();
  18. // CHECK:STDOUT: --- nested_class.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  22. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  23. // CHECK:STDOUT: %Outer.type: type = generic_class_type @Outer [concrete]
  24. // CHECK:STDOUT: %Outer.generic: %Outer.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %Outer.9d6: type = class_type @Outer, @Outer(%T) [symbolic]
  26. // CHECK:STDOUT: %U: %T = bind_symbolic_name U, 1 [symbolic]
  27. // CHECK:STDOUT: %pattern_type.7dcd0a.1: type = pattern_type %T [symbolic]
  28. // CHECK:STDOUT: %Inner.type.eae: type = generic_class_type @Inner, @Outer(%T) [symbolic]
  29. // CHECK:STDOUT: %Inner.generic.137: %Inner.type.eae = struct_value () [symbolic]
  30. // CHECK:STDOUT: %Inner.879: type = class_type @Inner, @Inner(%T, %U) [symbolic]
  31. // CHECK:STDOUT: %Get.type.889: type = fn_type @Get, @Inner(%T, %U) [symbolic]
  32. // CHECK:STDOUT: %Get.118: %Get.type.889 = struct_value () [symbolic]
  33. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  34. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  35. // CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [symbolic]
  36. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  37. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  38. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  39. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  40. // CHECK:STDOUT: %i32.builtin: type = int_type signed, %int_32 [concrete]
  41. // CHECK:STDOUT: %complete_type.f8a: <witness> = complete_type_witness %i32.builtin [concrete]
  42. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  43. // CHECK:STDOUT: %Outer.545: type = class_type @Outer, @Outer(%i32) [concrete]
  44. // CHECK:STDOUT: %Inner.type.bac: type = generic_class_type @Inner, @Outer(%i32) [concrete]
  45. // CHECK:STDOUT: %Inner.generic.ba0: %Inner.type.bac = struct_value () [concrete]
  46. // CHECK:STDOUT: %int_42.20e: Core.IntLiteral = int_value 42 [concrete]
  47. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  48. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  49. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  50. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  51. // CHECK:STDOUT: %To.c80: Core.IntLiteral = bind_symbolic_name To, 0 [symbolic]
  52. // CHECK:STDOUT: %Convert.type.0f9: type = fn_type @Convert.2, @impl.4f9(%To.c80) [symbolic]
  53. // CHECK:STDOUT: %Convert.f06: %Convert.type.0f9 = struct_value () [symbolic]
  54. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  55. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  56. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  57. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  58. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  59. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_42.20e, %Convert.956 [concrete]
  60. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  61. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_42.20e, %Convert.specific_fn [concrete]
  62. // CHECK:STDOUT: %int_42.c68: %i32 = int_value 42 [concrete]
  63. // CHECK:STDOUT: %Inner.025: type = class_type @Inner, @Inner(%i32, %int_42.c68) [concrete]
  64. // CHECK:STDOUT: %Get.type.512: type = fn_type @Get, @Inner(%i32, %int_42.c68) [concrete]
  65. // CHECK:STDOUT: %Get.18c: %Get.type.512 = struct_value () [concrete]
  66. // CHECK:STDOUT: %Get.specific_fn: <specific function> = specific_function %Get.18c, @Get(%i32, %int_42.c68) [concrete]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: imports {
  70. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  71. // CHECK:STDOUT: .Int = %Core.Int
  72. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  73. // CHECK:STDOUT: import Core//prelude
  74. // CHECK:STDOUT: import Core//prelude/...
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  77. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  78. // CHECK:STDOUT: %Core.import_ref.a5b: @impl.4f9.%Convert.type (%Convert.type.0f9) = import_ref Core//prelude/types/int, loc19_39, loaded [symbolic = @impl.4f9.%Convert (constants.%Convert.f06)]
  79. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (%Core.import_ref.a5b), @impl.4f9 [concrete]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: file {
  83. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  84. // CHECK:STDOUT: .Core = imports.%Core
  85. // CHECK:STDOUT: .Outer = %Outer.decl
  86. // CHECK:STDOUT: .n = %n
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %Core.import = import Core
  89. // CHECK:STDOUT: %Outer.decl: %Outer.type = class_decl @Outer [concrete = constants.%Outer.generic] {
  90. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  91. // CHECK:STDOUT: } {
  92. // CHECK:STDOUT: %T.loc4_13.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_13.2 (constants.%T)]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: name_binding_decl {
  95. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = binding_pattern n [concrete]
  96. // CHECK:STDOUT: %.loc10_1: %pattern_type.7ce = var_pattern %n.patt [concrete]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %n.var: ref %i32 = var n
  99. // CHECK:STDOUT: %.loc10_8: type = splice_block %i32 [concrete = constants.%i32] {
  100. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  101. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %n: ref %i32 = bind_name n, %n.var
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: generic class @Outer(%T.loc4_13.1: type) {
  107. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_13.2 (constants.%T)]
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !definition:
  110. // CHECK:STDOUT: %Inner.type: type = generic_class_type @Inner, @Outer(%T.loc4_13.2) [symbolic = %Inner.type (constants.%Inner.type.eae)]
  111. // CHECK:STDOUT: %Inner.generic: @Outer.%Inner.type (%Inner.type.eae) = struct_value () [symbolic = %Inner.generic (constants.%Inner.generic.137)]
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: class {
  114. // CHECK:STDOUT: %Inner.decl: @Outer.%Inner.type (%Inner.type.eae) = class_decl @Inner [symbolic = @Outer.%Inner.generic (constants.%Inner.generic.137)] {
  115. // CHECK:STDOUT: %U.patt: @Inner.%pattern_type (%pattern_type.7dcd0a.1) = symbolic_binding_pattern U, 1 [concrete]
  116. // CHECK:STDOUT: } {
  117. // CHECK:STDOUT: %T.ref: type = name_ref T, @Outer.%T.loc4_13.1 [symbolic = %T (constants.%T)]
  118. // CHECK:STDOUT: %U.loc5_15.1: @Inner.%T (%T) = bind_symbolic_name U, 1 [symbolic = %U.loc5_15.2 (constants.%U)]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  121. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  122. // CHECK:STDOUT: complete_type_witness = %complete_type
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: !members:
  125. // CHECK:STDOUT: .Self = constants.%Outer.9d6
  126. // CHECK:STDOUT: .T = <poisoned>
  127. // CHECK:STDOUT: .Inner = %Inner.decl
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: generic class @Inner(@Outer.%T.loc4_13.1: type, %U.loc5_15.1: @Inner.%T (%T)) {
  132. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  133. // CHECK:STDOUT: %U.loc5_15.2: @Inner.%T (%T) = bind_symbolic_name U, 1 [symbolic = %U.loc5_15.2 (constants.%U)]
  134. // CHECK:STDOUT: %pattern_type: type = pattern_type %T [symbolic = %pattern_type (constants.%pattern_type.7dcd0a.1)]
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: !definition:
  137. // CHECK:STDOUT: %Get.type: type = fn_type @Get, @Inner(%T, %U.loc5_15.2) [symbolic = %Get.type (constants.%Get.type.889)]
  138. // CHECK:STDOUT: %Get: @Inner.%Get.type (%Get.type.889) = struct_value () [symbolic = %Get (constants.%Get.118)]
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: class {
  141. // CHECK:STDOUT: %Get.decl: @Inner.%Get.type (%Get.type.889) = fn_decl @Get [symbolic = @Inner.%Get (constants.%Get.118)] {
  142. // CHECK:STDOUT: %return.patt: @Get.%pattern_type (%pattern_type.7dcd0a.1) = return_slot_pattern [concrete]
  143. // CHECK:STDOUT: %return.param_patt: @Get.%pattern_type (%pattern_type.7dcd0a.1) = out_param_pattern %return.patt, call_param0 [concrete]
  144. // CHECK:STDOUT: } {
  145. // CHECK:STDOUT: %T.ref: type = name_ref T, @Outer.%T.loc4_13.1 [symbolic = %T (constants.%T)]
  146. // CHECK:STDOUT: %return.param: ref @Get.%T (%T) = out_param call_param0
  147. // CHECK:STDOUT: %return: ref @Get.%T (%T) = return_slot %return.param
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  150. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  151. // CHECK:STDOUT: complete_type_witness = %complete_type
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: !members:
  154. // CHECK:STDOUT: .Self = constants.%Inner.879
  155. // CHECK:STDOUT: .T = <poisoned>
  156. // CHECK:STDOUT: .Get = %Get.decl
  157. // CHECK:STDOUT: .U = <poisoned>
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: generic fn @Get(@Outer.%T.loc4_13.1: type, @Inner.%U.loc5_15.1: @Inner.%T (%T)) {
  162. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  163. // CHECK:STDOUT: %pattern_type: type = pattern_type %T [symbolic = %pattern_type (constants.%pattern_type.7dcd0a.1)]
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: !definition:
  166. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T [symbolic = %require_complete (constants.%require_complete.4ae)]
  167. // CHECK:STDOUT: %U: @Get.%T (%T) = bind_symbolic_name U, 1 [symbolic = %U (constants.%U)]
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: fn() -> @Get.%T (%T) {
  170. // CHECK:STDOUT: !entry:
  171. // CHECK:STDOUT: %U.ref: @Get.%T (%T) = name_ref U, @Inner.%U.loc5_15.1 [symbolic = %U (constants.%U)]
  172. // CHECK:STDOUT: return %U.ref
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: fn @__global_init() {
  177. // CHECK:STDOUT: !entry:
  178. // CHECK:STDOUT: %Outer.ref: %Outer.type = name_ref Outer, file.%Outer.decl [concrete = constants.%Outer.generic]
  179. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  180. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  181. // CHECK:STDOUT: %Outer: type = class_type @Outer, @Outer(constants.%i32) [concrete = constants.%Outer.545]
  182. // CHECK:STDOUT: %.loc10_24: %Inner.type.bac = specific_constant @Outer.%Inner.decl, @Outer(constants.%i32) [concrete = constants.%Inner.generic.ba0]
  183. // CHECK:STDOUT: %Inner.ref: %Inner.type.bac = name_ref Inner, %.loc10_24 [concrete = constants.%Inner.generic.ba0]
  184. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete = constants.%int_42.20e]
  185. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  186. // CHECK:STDOUT: %bound_method.loc10_33.1: <bound method> = bound_method constants.%int_42.20e, %impl.elem0 [concrete = constants.%Convert.bound]
  187. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  188. // CHECK:STDOUT: %bound_method.loc10_33.2: <bound method> = bound_method constants.%int_42.20e, %specific_fn [concrete = constants.%bound_method]
  189. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc10_33.2(constants.%int_42.20e) [concrete = constants.%int_42.c68]
  190. // CHECK:STDOUT: %.loc10_33.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_42.c68]
  191. // CHECK:STDOUT: %.loc10_33.2: %i32 = converted constants.%int_42.20e, %.loc10_33.1 [concrete = constants.%int_42.c68]
  192. // CHECK:STDOUT: %Inner: type = class_type @Inner, @Inner(constants.%i32, constants.%int_42.c68) [concrete = constants.%Inner.025]
  193. // CHECK:STDOUT: %.loc10_34: %Get.type.512 = specific_constant @Inner.%Get.decl, @Inner(constants.%i32, constants.%int_42.c68) [concrete = constants.%Get.18c]
  194. // CHECK:STDOUT: %Get.ref: %Get.type.512 = name_ref Get, %.loc10_34 [concrete = constants.%Get.18c]
  195. // CHECK:STDOUT: %Get.specific_fn: <specific function> = specific_function %Get.ref, @Get(constants.%i32, constants.%int_42.c68) [concrete = constants.%Get.specific_fn]
  196. // CHECK:STDOUT: %Get.call: init %i32 = call %Get.specific_fn()
  197. // CHECK:STDOUT: assign file.%n.var, %Get.call
  198. // CHECK:STDOUT: return
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: specific @Outer(constants.%T) {
  202. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: !definition:
  205. // CHECK:STDOUT: %Inner.type => constants.%Inner.type.eae
  206. // CHECK:STDOUT: %Inner.generic => constants.%Inner.generic.137
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: specific @Inner(constants.%T, constants.%U) {
  210. // CHECK:STDOUT: %T => constants.%T
  211. // CHECK:STDOUT: %U.loc5_15.2 => constants.%U
  212. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7dcd0a.1
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: !definition:
  215. // CHECK:STDOUT: %Get.type => constants.%Get.type.889
  216. // CHECK:STDOUT: %Get => constants.%Get.118
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: specific @Get(constants.%T, constants.%U) {
  220. // CHECK:STDOUT: %T => constants.%T
  221. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7dcd0a.1
  222. // CHECK:STDOUT: }
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: specific @Outer(constants.%i32) {
  225. // CHECK:STDOUT: %T.loc4_13.2 => constants.%i32
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: !definition:
  228. // CHECK:STDOUT: %Inner.type => constants.%Inner.type.bac
  229. // CHECK:STDOUT: %Inner.generic => constants.%Inner.generic.ba0
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: specific @Inner(constants.%i32, constants.%int_42.c68) {
  233. // CHECK:STDOUT: %T => constants.%i32
  234. // CHECK:STDOUT: %U.loc5_15.2 => constants.%int_42.c68
  235. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7ce
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: !definition:
  238. // CHECK:STDOUT: %Get.type => constants.%Get.type.512
  239. // CHECK:STDOUT: %Get => constants.%Get.18c
  240. // CHECK:STDOUT: }
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: specific @Get(constants.%i32, constants.%int_42.c68) {
  243. // CHECK:STDOUT: %T => constants.%i32
  244. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.7ce
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: !definition:
  247. // CHECK:STDOUT: %require_complete => constants.%complete_type.f8a
  248. // CHECK:STDOUT: %U => constants.%int_42.c68
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT: