stringify.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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/stringify.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/stringify.carbon
  10. // --- fail_empty_params.carbon
  11. library "[[@TEST_NAME]]";
  12. class NoParams {}
  13. class EmptyParams() {}
  14. var v: NoParams;
  15. // CHECK:STDERR: fail_empty_params.carbon:[[@LINE+7]]:1: error: cannot implicitly convert from `NoParams` to `EmptyParams()` [ImplicitAsConversionFailure]
  16. // CHECK:STDERR: var w: EmptyParams() = v;
  17. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  18. // CHECK:STDERR: fail_empty_params.carbon:[[@LINE+4]]:1: note: type `NoParams` does not implement interface `ImplicitAs(EmptyParams())` [MissingImplInMemberAccessNote]
  19. // CHECK:STDERR: var w: EmptyParams() = v;
  20. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  21. // CHECK:STDERR:
  22. var w: EmptyParams() = v;
  23. // --- fail_nested.carbon
  24. library "[[@TEST_NAME]]";
  25. class Outer(T:! type) {
  26. class Inner(U:! type) {
  27. }
  28. }
  29. var v: Outer({}*);
  30. // TODO: It would be nice to include the `Outer({}*).` prefix in the name of `Inner`.
  31. // CHECK:STDERR: fail_nested.carbon:[[@LINE+6]]:1: error: cannot implicitly convert from `Outer({}*)` to `Inner({.a: i32}*)` [ImplicitAsConversionFailure]
  32. // CHECK:STDERR: var w: Outer({}*).Inner({.a: i32}*) = v;
  33. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. // CHECK:STDERR: fail_nested.carbon:[[@LINE+3]]:1: note: type `Outer({}*)` does not implement interface `ImplicitAs(Inner({.a: i32}*))` [MissingImplInMemberAccessNote]
  35. // CHECK:STDERR: var w: Outer({}*).Inner({.a: i32}*) = v;
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. var w: Outer({}*).Inner({.a: i32}*) = v;
  38. // CHECK:STDOUT: --- fail_empty_params.carbon
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: constants {
  41. // CHECK:STDOUT: %NoParams: type = class_type @NoParams [template]
  42. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  43. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  44. // CHECK:STDOUT: %EmptyParams.type: type = generic_class_type @EmptyParams [template]
  45. // CHECK:STDOUT: %EmptyParams.1: %EmptyParams.type = struct_value () [template]
  46. // CHECK:STDOUT: %EmptyParams.2: type = class_type @EmptyParams [template]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  51. // CHECK:STDOUT: .ImplicitAs = %import_ref.1
  52. // CHECK:STDOUT: import Core//prelude
  53. // CHECK:STDOUT: import Core//prelude/...
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  59. // CHECK:STDOUT: .Core = imports.%Core
  60. // CHECK:STDOUT: .NoParams = %NoParams.decl
  61. // CHECK:STDOUT: .EmptyParams = %EmptyParams.decl
  62. // CHECK:STDOUT: .v = %v
  63. // CHECK:STDOUT: .w = %w
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Core.import = import Core
  66. // CHECK:STDOUT: %NoParams.decl: type = class_decl @NoParams [template = constants.%NoParams] {} {}
  67. // CHECK:STDOUT: %EmptyParams.decl: %EmptyParams.type = class_decl @EmptyParams [template = constants.%EmptyParams.1] {} {}
  68. // CHECK:STDOUT: %NoParams.ref: type = name_ref NoParams, %NoParams.decl [template = constants.%NoParams]
  69. // CHECK:STDOUT: %v.var: ref %NoParams = var v
  70. // CHECK:STDOUT: %v: ref %NoParams = bind_name v, %v.var
  71. // CHECK:STDOUT: %EmptyParams.ref: %EmptyParams.type = name_ref EmptyParams, %EmptyParams.decl [template = constants.%EmptyParams.1]
  72. // CHECK:STDOUT: %EmptyParams: type = class_type @EmptyParams [template = constants.%EmptyParams.2]
  73. // CHECK:STDOUT: %w.var: ref %EmptyParams.2 = var w
  74. // CHECK:STDOUT: %w: ref %EmptyParams.2 = bind_name w, %w.var
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: class @NoParams {
  78. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .Self = constants.%NoParams
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: class @EmptyParams {
  85. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = constants.%EmptyParams.2
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @__global_init() {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: %v.ref: ref %NoParams = name_ref v, file.%v
  94. // CHECK:STDOUT: %.loc15: %EmptyParams.2 = converted %v.ref, <error> [template = <error>]
  95. // CHECK:STDOUT: assign file.%w.var, <error>
  96. // CHECK:STDOUT: return
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: --- fail_nested.carbon
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: constants {
  102. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  103. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  104. // CHECK:STDOUT: %Outer.type: type = generic_class_type @Outer [template]
  105. // CHECK:STDOUT: %Outer.1: %Outer.type = struct_value () [template]
  106. // CHECK:STDOUT: %Outer.2: type = class_type @Outer, @Outer(%T) [symbolic]
  107. // CHECK:STDOUT: %U: type = bind_symbolic_name U, 1 [symbolic]
  108. // CHECK:STDOUT: %U.patt: type = symbolic_binding_pattern U, 1 [symbolic]
  109. // CHECK:STDOUT: %Inner.type.1: type = generic_class_type @Inner, @Outer(%T) [symbolic]
  110. // CHECK:STDOUT: %Inner.1: %Inner.type.1 = struct_value () [symbolic]
  111. // CHECK:STDOUT: %Inner.2: type = class_type @Inner, @Inner(%T, %U) [symbolic]
  112. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  113. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  114. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  115. // CHECK:STDOUT: %Outer.3: type = class_type @Outer, @Outer(%.3) [template]
  116. // CHECK:STDOUT: %Inner.type.2: type = generic_class_type @Inner, @Outer(%.3) [template]
  117. // CHECK:STDOUT: %Inner.3: %Inner.type.2 = struct_value () [template]
  118. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  119. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  120. // CHECK:STDOUT: %.4: type = struct_type {.a: i32} [template]
  121. // CHECK:STDOUT: %.5: type = ptr_type %.4 [template]
  122. // CHECK:STDOUT: %Inner.4: type = class_type @Inner, @Inner(%.3, %.5) [template]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: imports {
  126. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  127. // CHECK:STDOUT: .Int32 = %import_ref.1
  128. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  129. // CHECK:STDOUT: import Core//prelude
  130. // CHECK:STDOUT: import Core//prelude/...
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: file {
  135. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  136. // CHECK:STDOUT: .Core = imports.%Core
  137. // CHECK:STDOUT: .Outer = %Outer.decl
  138. // CHECK:STDOUT: .v = %v
  139. // CHECK:STDOUT: .w = %w
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %Core.import = import Core
  142. // CHECK:STDOUT: %Outer.decl: %Outer.type = class_decl @Outer [template = constants.%Outer.1] {
  143. // CHECK:STDOUT: %T.patt.loc4_13.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_13.2 (constants.%T.patt)]
  144. // 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)]
  145. // CHECK:STDOUT: } {
  146. // CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
  147. // CHECK:STDOUT: %T.loc4_13.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc4_13.2 (constants.%T)]
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: %Outer.ref.loc9: %Outer.type = name_ref Outer, %Outer.decl [template = constants.%Outer.1]
  150. // CHECK:STDOUT: %.loc9_15: %.1 = struct_literal ()
  151. // CHECK:STDOUT: %.loc9_16.1: type = converted %.loc9_15, constants.%.1 [template = constants.%.1]
  152. // CHECK:STDOUT: %.loc9_16.2: type = ptr_type %.1 [template = constants.%.3]
  153. // CHECK:STDOUT: %Outer.loc9: type = class_type @Outer, @Outer(constants.%.3) [template = constants.%Outer.3]
  154. // CHECK:STDOUT: %v.var: ref %Outer.3 = var v
  155. // CHECK:STDOUT: %v: ref %Outer.3 = bind_name v, %v.var
  156. // CHECK:STDOUT: %Outer.ref.loc18: %Outer.type = name_ref Outer, %Outer.decl [template = constants.%Outer.1]
  157. // CHECK:STDOUT: %.loc18_15: %.1 = struct_literal ()
  158. // CHECK:STDOUT: %.loc18_16.1: type = converted %.loc18_15, constants.%.1 [template = constants.%.1]
  159. // CHECK:STDOUT: %.loc18_16.2: type = ptr_type %.1 [template = constants.%.3]
  160. // CHECK:STDOUT: %Outer.loc18: type = class_type @Outer, @Outer(constants.%.3) [template = constants.%Outer.3]
  161. // CHECK:STDOUT: %.loc18_18: %Inner.type.2 = specific_constant @Outer.%Inner.decl, @Outer(constants.%.3) [template = constants.%Inner.3]
  162. // CHECK:STDOUT: %Inner.ref: %Inner.type.2 = name_ref Inner, %.loc18_18 [template = constants.%Inner.3]
  163. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  164. // CHECK:STDOUT: %.loc18_30.1: type = value_of_initializer %int.make_type_32 [template = i32]
  165. // CHECK:STDOUT: %.loc18_30.2: type = converted %int.make_type_32, %.loc18_30.1 [template = i32]
  166. // CHECK:STDOUT: %.loc18_33: type = struct_type {.a: i32} [template = constants.%.4]
  167. // CHECK:STDOUT: %.loc18_34: type = ptr_type %.4 [template = constants.%.5]
  168. // CHECK:STDOUT: %Inner: type = class_type @Inner, @Inner(constants.%.3, constants.%.5) [template = constants.%Inner.4]
  169. // CHECK:STDOUT: %w.var: ref %Inner.4 = var w
  170. // CHECK:STDOUT: %w: ref %Inner.4 = bind_name w, %w.var
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: generic class @Outer(%T.loc4_13.1: type) {
  174. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_13.2 (constants.%T)]
  175. // CHECK:STDOUT: %T.patt.loc4_13.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_13.2 (constants.%T.patt)]
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: !definition:
  178. // CHECK:STDOUT: %Inner.type: type = generic_class_type @Inner, @Outer(%T.loc4_13.2) [symbolic = %Inner.type (constants.%Inner.type.1)]
  179. // CHECK:STDOUT: %Inner: @Outer.%Inner.type (%Inner.type.1) = struct_value () [symbolic = %Inner (constants.%Inner.1)]
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: class {
  182. // CHECK:STDOUT: %Inner.decl: @Outer.%Inner.type (%Inner.type.1) = class_decl @Inner [symbolic = @Outer.%Inner (constants.%Inner.1)] {
  183. // CHECK:STDOUT: %U.patt.loc5_15.1: type = symbolic_binding_pattern U, 1 [symbolic = %U.patt.loc5_15.2 (constants.%U.patt)]
  184. // CHECK:STDOUT: %U.param_patt: type = value_param_pattern %U.patt.loc5_15.1, runtime_param<invalid> [symbolic = %U.patt.loc5_15.2 (constants.%U.patt)]
  185. // CHECK:STDOUT: } {
  186. // CHECK:STDOUT: %U.param: type = value_param runtime_param<invalid>
  187. // CHECK:STDOUT: %U.loc5_15.1: type = bind_symbolic_name U, 1, %U.param [symbolic = %U.loc5_15.2 (constants.%U)]
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.1 [template = constants.%.2]
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: !members:
  192. // CHECK:STDOUT: .Self = constants.%Outer.2
  193. // CHECK:STDOUT: .Inner = %Inner.decl
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: generic class @Inner(@Outer.%T.loc4_13.1: type, %U.loc5_15.1: type) {
  198. // CHECK:STDOUT: %U.loc5_15.2: type = bind_symbolic_name U, 1 [symbolic = %U.loc5_15.2 (constants.%U)]
  199. // CHECK:STDOUT: %U.patt.loc5_15.2: type = symbolic_binding_pattern U, 1 [symbolic = %U.patt.loc5_15.2 (constants.%U.patt)]
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: !definition:
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: class {
  204. // CHECK:STDOUT: %.loc6: <witness> = complete_type_witness %.1 [template = constants.%.2]
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: !members:
  207. // CHECK:STDOUT: .Self = constants.%Inner.2
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: fn @__global_init() {
  212. // CHECK:STDOUT: !entry:
  213. // CHECK:STDOUT: %v.ref: ref %Outer.3 = name_ref v, file.%v
  214. // CHECK:STDOUT: %.loc18: %Inner.4 = converted %v.ref, <error> [template = <error>]
  215. // CHECK:STDOUT: assign file.%w.var, <error>
  216. // CHECK:STDOUT: return
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: specific @Outer(constants.%T) {
  220. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  221. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%T
  222. // CHECK:STDOUT: }
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: specific @Inner(constants.%T, constants.%U) {
  225. // CHECK:STDOUT: %U.loc5_15.2 => constants.%U
  226. // CHECK:STDOUT: %U.patt.loc5_15.2 => constants.%U
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: specific @Outer(%T.loc4_13.2) {
  230. // CHECK:STDOUT: %T.loc4_13.2 => constants.%T
  231. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%T
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: specific @Outer(constants.%.3) {
  235. // CHECK:STDOUT: %T.loc4_13.2 => constants.%.3
  236. // CHECK:STDOUT: %T.patt.loc4_13.2 => constants.%.3
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: !definition:
  239. // CHECK:STDOUT: %Inner.type => constants.%Inner.type.2
  240. // CHECK:STDOUT: %Inner => constants.%Inner.3
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: specific @Inner(constants.%.3, constants.%.5) {
  244. // CHECK:STDOUT: %U.loc5_15.2 => constants.%.5
  245. // CHECK:STDOUT: %U.patt.loc5_15.2 => constants.%.5
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: !definition:
  248. // CHECK:STDOUT: }
  249. // CHECK:STDOUT: