destroy_calls.carbon 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/destroy_calls.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/destroy_calls.carbon
  12. // --- implicit_return.carbon
  13. library "[[@TEST_NAME]]";
  14. class A {}
  15. class B {}
  16. class C {}
  17. //@dump-sem-ir-begin
  18. fn F() {
  19. var unused a: A = {};
  20. var unused b: B = {};
  21. var unused c: C = {};
  22. }
  23. //@dump-sem-ir-end
  24. // --- nested_scope.carbon
  25. library "[[@TEST_NAME]]";
  26. class A {}
  27. class B {}
  28. class C {}
  29. //@dump-sem-ir-begin
  30. fn F() {
  31. var unused a: A = {};
  32. var unused b: B = {};
  33. if (true) {
  34. var unused c: C = {};
  35. }
  36. }
  37. //@dump-sem-ir-end
  38. // --- temp.carbon
  39. library "[[@TEST_NAME]]";
  40. class A { fn Make() -> A; }
  41. class B { fn Make() -> B; }
  42. class C { fn Make() -> C; }
  43. //@dump-sem-ir-begin
  44. fn F() {
  45. // TODO: The scoping of these destroy calls is incorrect. Maybe we need to
  46. // establish statement scopes?
  47. A.Make();
  48. B.Make();
  49. C.Make();
  50. }
  51. //@dump-sem-ir-end
  52. // --- generic_class.carbon
  53. library "[[@TEST_NAME]]";
  54. class C {}
  55. class D(template T:! type) {}
  56. //@dump-sem-ir-begin
  57. fn F() {
  58. var unused a: D(C) = {};
  59. }
  60. //@dump-sem-ir-end
  61. // --- generic_use_inside_generic.carbon
  62. library "[[@TEST_NAME]]";
  63. class C(template T:! type) {}
  64. //@dump-sem-ir-begin
  65. fn F(template T:! type) {
  66. var unused v: C(T) = {};
  67. }
  68. //@dump-sem-ir-end
  69. fn G() { F({}); }
  70. // CHECK:STDOUT: --- implicit_return.carbon
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: constants {
  73. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  74. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  75. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  76. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  77. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  78. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  79. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  80. // CHECK:STDOUT: %pattern_type.1ab: type = pattern_type %A [concrete]
  81. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  82. // CHECK:STDOUT: %A.val: %A = struct_value () [concrete]
  83. // CHECK:STDOUT: %pattern_type.1f4: type = pattern_type %B [concrete]
  84. // CHECK:STDOUT: %B.val: %B = struct_value () [concrete]
  85. // CHECK:STDOUT: %pattern_type.7c7: type = pattern_type %C [concrete]
  86. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  87. // CHECK:STDOUT: %Destroy.Op.type.bae255.2: type = fn_type @Destroy.Op.loc12_3.2 [concrete]
  88. // CHECK:STDOUT: %Destroy.Op.651ba6.2: %Destroy.Op.type.bae255.2 = struct_value () [concrete]
  89. // CHECK:STDOUT: %Destroy.Op.type.bae255.3: type = fn_type @Destroy.Op.loc11 [concrete]
  90. // CHECK:STDOUT: %Destroy.Op.651ba6.3: %Destroy.Op.type.bae255.3 = struct_value () [concrete]
  91. // CHECK:STDOUT: %Destroy.Op.type.bae255.4: type = fn_type @Destroy.Op.loc10 [concrete]
  92. // CHECK:STDOUT: %Destroy.Op.651ba6.4: %Destroy.Op.type.bae255.4 = struct_value () [concrete]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: file {
  96. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @F() {
  100. // CHECK:STDOUT: !entry:
  101. // CHECK:STDOUT: name_binding_decl {
  102. // CHECK:STDOUT: %a.patt: %pattern_type.1ab = ref_binding_pattern a [concrete]
  103. // CHECK:STDOUT: %a.var_patt: %pattern_type.1ab = var_pattern %a.patt [concrete]
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: %a.var: ref %A = var %a.var_patt
  106. // CHECK:STDOUT: %.loc10_22.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  107. // CHECK:STDOUT: %.loc10_22.2: init %A to %a.var = class_init () [concrete = constants.%A.val]
  108. // CHECK:STDOUT: %.loc10_3: init %A = converted %.loc10_22.1, %.loc10_22.2 [concrete = constants.%A.val]
  109. // CHECK:STDOUT: assign %a.var, %.loc10_3
  110. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  111. // CHECK:STDOUT: %a: ref %A = ref_binding a, %a.var
  112. // CHECK:STDOUT: name_binding_decl {
  113. // CHECK:STDOUT: %b.patt: %pattern_type.1f4 = ref_binding_pattern b [concrete]
  114. // CHECK:STDOUT: %b.var_patt: %pattern_type.1f4 = var_pattern %b.patt [concrete]
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %b.var: ref %B = var %b.var_patt
  117. // CHECK:STDOUT: %.loc11_22.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  118. // CHECK:STDOUT: %.loc11_22.2: init %B to %b.var = class_init () [concrete = constants.%B.val]
  119. // CHECK:STDOUT: %.loc11_3: init %B = converted %.loc11_22.1, %.loc11_22.2 [concrete = constants.%B.val]
  120. // CHECK:STDOUT: assign %b.var, %.loc11_3
  121. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  122. // CHECK:STDOUT: %b: ref %B = ref_binding b, %b.var
  123. // CHECK:STDOUT: name_binding_decl {
  124. // CHECK:STDOUT: %c.patt: %pattern_type.7c7 = ref_binding_pattern c [concrete]
  125. // CHECK:STDOUT: %c.var_patt: %pattern_type.7c7 = var_pattern %c.patt [concrete]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %c.var: ref %C = var %c.var_patt
  128. // CHECK:STDOUT: %.loc12_22.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  129. // CHECK:STDOUT: %.loc12_22.2: init %C to %c.var = class_init () [concrete = constants.%C.val]
  130. // CHECK:STDOUT: %.loc12_3: init %C = converted %.loc12_22.1, %.loc12_22.2 [concrete = constants.%C.val]
  131. // CHECK:STDOUT: assign %c.var, %.loc12_3
  132. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  133. // CHECK:STDOUT: %c: ref %C = ref_binding c, %c.var
  134. // CHECK:STDOUT: %Destroy.Op.bound.loc12: <bound method> = bound_method %c.var, constants.%Destroy.Op.651ba6.2
  135. // CHECK:STDOUT: %Destroy.Op.call.loc12: init %empty_tuple.type = call %Destroy.Op.bound.loc12(%c.var)
  136. // CHECK:STDOUT: %Destroy.Op.bound.loc11: <bound method> = bound_method %b.var, constants.%Destroy.Op.651ba6.3
  137. // CHECK:STDOUT: %Destroy.Op.call.loc11: init %empty_tuple.type = call %Destroy.Op.bound.loc11(%b.var)
  138. // CHECK:STDOUT: %Destroy.Op.bound.loc10: <bound method> = bound_method %a.var, constants.%Destroy.Op.651ba6.4
  139. // CHECK:STDOUT: %Destroy.Op.call.loc10: init %empty_tuple.type = call %Destroy.Op.bound.loc10(%a.var)
  140. // CHECK:STDOUT: return
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: fn @Destroy.Op.loc12_3.1(%self.param: ref %empty_struct_type) = "no_op";
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: fn @Destroy.Op.loc12_3.2(%self.param: ref %C) {
  146. // CHECK:STDOUT: !entry:
  147. // CHECK:STDOUT: return
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @Destroy.Op.loc11(%self.param: ref %B) {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: return
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: fn @Destroy.Op.loc10(%self.param: ref %A) {
  156. // CHECK:STDOUT: !entry:
  157. // CHECK:STDOUT: return
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: --- nested_scope.carbon
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: constants {
  163. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  164. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  165. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  166. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  167. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  168. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  169. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  170. // CHECK:STDOUT: %pattern_type.1ab: type = pattern_type %A [concrete]
  171. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  172. // CHECK:STDOUT: %A.val: %A = struct_value () [concrete]
  173. // CHECK:STDOUT: %pattern_type.1f4: type = pattern_type %B [concrete]
  174. // CHECK:STDOUT: %B.val: %B = struct_value () [concrete]
  175. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  176. // CHECK:STDOUT: %pattern_type.7c7: type = pattern_type %C [concrete]
  177. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  178. // CHECK:STDOUT: %Destroy.Op.type.bae255.2: type = fn_type @Destroy.Op.loc13_5.2 [concrete]
  179. // CHECK:STDOUT: %Destroy.Op.651ba6.2: %Destroy.Op.type.bae255.2 = struct_value () [concrete]
  180. // CHECK:STDOUT: %Destroy.Op.type.bae255.3: type = fn_type @Destroy.Op.loc11 [concrete]
  181. // CHECK:STDOUT: %Destroy.Op.651ba6.3: %Destroy.Op.type.bae255.3 = struct_value () [concrete]
  182. // CHECK:STDOUT: %Destroy.Op.type.bae255.4: type = fn_type @Destroy.Op.loc10 [concrete]
  183. // CHECK:STDOUT: %Destroy.Op.651ba6.4: %Destroy.Op.type.bae255.4 = struct_value () [concrete]
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: file {
  187. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: fn @F() {
  191. // CHECK:STDOUT: !entry:
  192. // CHECK:STDOUT: name_binding_decl {
  193. // CHECK:STDOUT: %a.patt: %pattern_type.1ab = ref_binding_pattern a [concrete]
  194. // CHECK:STDOUT: %a.var_patt: %pattern_type.1ab = var_pattern %a.patt [concrete]
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT: %a.var: ref %A = var %a.var_patt
  197. // CHECK:STDOUT: %.loc10_22.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  198. // CHECK:STDOUT: %.loc10_22.2: init %A to %a.var = class_init () [concrete = constants.%A.val]
  199. // CHECK:STDOUT: %.loc10_3: init %A = converted %.loc10_22.1, %.loc10_22.2 [concrete = constants.%A.val]
  200. // CHECK:STDOUT: assign %a.var, %.loc10_3
  201. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  202. // CHECK:STDOUT: %a: ref %A = ref_binding a, %a.var
  203. // CHECK:STDOUT: name_binding_decl {
  204. // CHECK:STDOUT: %b.patt: %pattern_type.1f4 = ref_binding_pattern b [concrete]
  205. // CHECK:STDOUT: %b.var_patt: %pattern_type.1f4 = var_pattern %b.patt [concrete]
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT: %b.var: ref %B = var %b.var_patt
  208. // CHECK:STDOUT: %.loc11_22.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  209. // CHECK:STDOUT: %.loc11_22.2: init %B to %b.var = class_init () [concrete = constants.%B.val]
  210. // CHECK:STDOUT: %.loc11_3: init %B = converted %.loc11_22.1, %.loc11_22.2 [concrete = constants.%B.val]
  211. // CHECK:STDOUT: assign %b.var, %.loc11_3
  212. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  213. // CHECK:STDOUT: %b: ref %B = ref_binding b, %b.var
  214. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  215. // CHECK:STDOUT: if %true br !if.then else br !if.else
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: !if.then:
  218. // CHECK:STDOUT: name_binding_decl {
  219. // CHECK:STDOUT: %c.patt: %pattern_type.7c7 = ref_binding_pattern c [concrete]
  220. // CHECK:STDOUT: %c.var_patt: %pattern_type.7c7 = var_pattern %c.patt [concrete]
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT: %c.var: ref %C = var %c.var_patt
  223. // CHECK:STDOUT: %.loc13_24.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  224. // CHECK:STDOUT: %.loc13_24.2: init %C to %c.var = class_init () [concrete = constants.%C.val]
  225. // CHECK:STDOUT: %.loc13_5: init %C = converted %.loc13_24.1, %.loc13_24.2 [concrete = constants.%C.val]
  226. // CHECK:STDOUT: assign %c.var, %.loc13_5
  227. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  228. // CHECK:STDOUT: %c: ref %C = ref_binding c, %c.var
  229. // CHECK:STDOUT: br !if.else
  230. // CHECK:STDOUT:
  231. // CHECK:STDOUT: !if.else:
  232. // CHECK:STDOUT: %Destroy.Op.bound.loc13: <bound method> = bound_method %c.var, constants.%Destroy.Op.651ba6.2
  233. // CHECK:STDOUT: %Destroy.Op.call.loc13: init %empty_tuple.type = call %Destroy.Op.bound.loc13(%c.var)
  234. // CHECK:STDOUT: %Destroy.Op.bound.loc11: <bound method> = bound_method %b.var, constants.%Destroy.Op.651ba6.3
  235. // CHECK:STDOUT: %Destroy.Op.call.loc11: init %empty_tuple.type = call %Destroy.Op.bound.loc11(%b.var)
  236. // CHECK:STDOUT: %Destroy.Op.bound.loc10: <bound method> = bound_method %a.var, constants.%Destroy.Op.651ba6.4
  237. // CHECK:STDOUT: %Destroy.Op.call.loc10: init %empty_tuple.type = call %Destroy.Op.bound.loc10(%a.var)
  238. // CHECK:STDOUT: return
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT:
  241. // CHECK:STDOUT: fn @Destroy.Op.loc13_5.1(%self.param: ref %empty_struct_type) = "no_op";
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: fn @Destroy.Op.loc13_5.2(%self.param: ref %C) {
  244. // CHECK:STDOUT: !entry:
  245. // CHECK:STDOUT: return
  246. // CHECK:STDOUT: }
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: fn @Destroy.Op.loc11(%self.param: ref %B) {
  249. // CHECK:STDOUT: !entry:
  250. // CHECK:STDOUT: return
  251. // CHECK:STDOUT: }
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: fn @Destroy.Op.loc10(%self.param: ref %A) {
  254. // CHECK:STDOUT: !entry:
  255. // CHECK:STDOUT: return
  256. // CHECK:STDOUT: }
  257. // CHECK:STDOUT:
  258. // CHECK:STDOUT: --- temp.carbon
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: constants {
  261. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  262. // CHECK:STDOUT: %A.Make.type: type = fn_type @A.Make [concrete]
  263. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  264. // CHECK:STDOUT: %A.Make: %A.Make.type = struct_value () [concrete]
  265. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  266. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  267. // CHECK:STDOUT: %B.Make.type: type = fn_type @B.Make [concrete]
  268. // CHECK:STDOUT: %B.Make: %B.Make.type = struct_value () [concrete]
  269. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  270. // CHECK:STDOUT: %C.Make.type: type = fn_type @C.Make [concrete]
  271. // CHECK:STDOUT: %C.Make: %C.Make.type = struct_value () [concrete]
  272. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  273. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  274. // CHECK:STDOUT: %Destroy.Op.type.bae255.2: type = fn_type @Destroy.Op.loc14_10.2 [concrete]
  275. // CHECK:STDOUT: %Destroy.Op.651ba6.2: %Destroy.Op.type.bae255.2 = struct_value () [concrete]
  276. // CHECK:STDOUT: %Destroy.Op.type.bae255.3: type = fn_type @Destroy.Op.loc13 [concrete]
  277. // CHECK:STDOUT: %Destroy.Op.651ba6.3: %Destroy.Op.type.bae255.3 = struct_value () [concrete]
  278. // CHECK:STDOUT: %Destroy.Op.type.bae255.4: type = fn_type @Destroy.Op.loc12 [concrete]
  279. // CHECK:STDOUT: %Destroy.Op.651ba6.4: %Destroy.Op.type.bae255.4 = struct_value () [concrete]
  280. // CHECK:STDOUT: }
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: file {
  283. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  284. // CHECK:STDOUT: }
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: fn @F() {
  287. // CHECK:STDOUT: !entry:
  288. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  289. // CHECK:STDOUT: %Make.ref.loc12: %A.Make.type = name_ref Make, @A.%A.Make.decl [concrete = constants.%A.Make]
  290. // CHECK:STDOUT: %.loc12_10.1: ref %A = temporary_storage
  291. // CHECK:STDOUT: %A.Make.call: init %A to %.loc12_10.1 = call %Make.ref.loc12()
  292. // CHECK:STDOUT: %.loc12_10.2: ref %A = temporary %.loc12_10.1, %A.Make.call
  293. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  294. // CHECK:STDOUT: %Make.ref.loc13: %B.Make.type = name_ref Make, @B.%B.Make.decl [concrete = constants.%B.Make]
  295. // CHECK:STDOUT: %.loc13_10.1: ref %B = temporary_storage
  296. // CHECK:STDOUT: %B.Make.call: init %B to %.loc13_10.1 = call %Make.ref.loc13()
  297. // CHECK:STDOUT: %.loc13_10.2: ref %B = temporary %.loc13_10.1, %B.Make.call
  298. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  299. // CHECK:STDOUT: %Make.ref.loc14: %C.Make.type = name_ref Make, @C.%C.Make.decl [concrete = constants.%C.Make]
  300. // CHECK:STDOUT: %.loc14_10.1: ref %C = temporary_storage
  301. // CHECK:STDOUT: %C.Make.call: init %C to %.loc14_10.1 = call %Make.ref.loc14()
  302. // CHECK:STDOUT: %.loc14_10.2: ref %C = temporary %.loc14_10.1, %C.Make.call
  303. // CHECK:STDOUT: %Destroy.Op.bound.loc14: <bound method> = bound_method %.loc14_10.2, constants.%Destroy.Op.651ba6.2
  304. // CHECK:STDOUT: %Destroy.Op.call.loc14: init %empty_tuple.type = call %Destroy.Op.bound.loc14(%.loc14_10.2)
  305. // CHECK:STDOUT: %Destroy.Op.bound.loc13: <bound method> = bound_method %.loc13_10.2, constants.%Destroy.Op.651ba6.3
  306. // CHECK:STDOUT: %Destroy.Op.call.loc13: init %empty_tuple.type = call %Destroy.Op.bound.loc13(%.loc13_10.2)
  307. // CHECK:STDOUT: %Destroy.Op.bound.loc12: <bound method> = bound_method %.loc12_10.2, constants.%Destroy.Op.651ba6.4
  308. // CHECK:STDOUT: %Destroy.Op.call.loc12: init %empty_tuple.type = call %Destroy.Op.bound.loc12(%.loc12_10.2)
  309. // CHECK:STDOUT: return
  310. // CHECK:STDOUT: }
  311. // CHECK:STDOUT:
  312. // CHECK:STDOUT: fn @Destroy.Op.loc14_10.1(%self.param: ref %empty_struct_type) = "no_op";
  313. // CHECK:STDOUT:
  314. // CHECK:STDOUT: fn @Destroy.Op.loc14_10.2(%self.param: ref %C) {
  315. // CHECK:STDOUT: !entry:
  316. // CHECK:STDOUT: return
  317. // CHECK:STDOUT: }
  318. // CHECK:STDOUT:
  319. // CHECK:STDOUT: fn @Destroy.Op.loc13(%self.param: ref %B) {
  320. // CHECK:STDOUT: !entry:
  321. // CHECK:STDOUT: return
  322. // CHECK:STDOUT: }
  323. // CHECK:STDOUT:
  324. // CHECK:STDOUT: fn @Destroy.Op.loc12(%self.param: ref %A) {
  325. // CHECK:STDOUT: !entry:
  326. // CHECK:STDOUT: return
  327. // CHECK:STDOUT: }
  328. // CHECK:STDOUT:
  329. // CHECK:STDOUT: --- generic_class.carbon
  330. // CHECK:STDOUT:
  331. // CHECK:STDOUT: constants {
  332. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  333. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  334. // CHECK:STDOUT: %D.type: type = generic_class_type @D [concrete]
  335. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  336. // CHECK:STDOUT: %D.generic: %D.type = struct_value () [concrete]
  337. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  338. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  339. // CHECK:STDOUT: %D.213: type = class_type @D, @D(%C) [concrete]
  340. // CHECK:STDOUT: %pattern_type.002: type = pattern_type %D.213 [concrete]
  341. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  342. // CHECK:STDOUT: %D.val: %D.213 = struct_value () [concrete]
  343. // CHECK:STDOUT: %Destroy.Op.type.bae255.2: type = fn_type @Destroy.Op.loc9_3.2 [concrete]
  344. // CHECK:STDOUT: %Destroy.Op.651ba6.2: %Destroy.Op.type.bae255.2 = struct_value () [concrete]
  345. // CHECK:STDOUT: }
  346. // CHECK:STDOUT:
  347. // CHECK:STDOUT: file {
  348. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  349. // CHECK:STDOUT: }
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: fn @F() {
  352. // CHECK:STDOUT: !entry:
  353. // CHECK:STDOUT: name_binding_decl {
  354. // CHECK:STDOUT: %a.patt: %pattern_type.002 = ref_binding_pattern a [concrete]
  355. // CHECK:STDOUT: %a.var_patt: %pattern_type.002 = var_pattern %a.patt [concrete]
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT: %a.var: ref %D.213 = var %a.var_patt
  358. // CHECK:STDOUT: %.loc9_25.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  359. // CHECK:STDOUT: %.loc9_25.2: init %D.213 to %a.var = class_init () [concrete = constants.%D.val]
  360. // CHECK:STDOUT: %.loc9_3: init %D.213 = converted %.loc9_25.1, %.loc9_25.2 [concrete = constants.%D.val]
  361. // CHECK:STDOUT: assign %a.var, %.loc9_3
  362. // CHECK:STDOUT: %.loc9_20: type = splice_block %D [concrete = constants.%D.213] {
  363. // CHECK:STDOUT: %D.ref: %D.type = name_ref D, file.%D.decl [concrete = constants.%D.generic]
  364. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  365. // CHECK:STDOUT: %D: type = class_type @D, @D(constants.%C) [concrete = constants.%D.213]
  366. // CHECK:STDOUT: }
  367. // CHECK:STDOUT: %a: ref %D.213 = ref_binding a, %a.var
  368. // CHECK:STDOUT: %Destroy.Op.bound: <bound method> = bound_method %a.var, constants.%Destroy.Op.651ba6.2
  369. // CHECK:STDOUT: %Destroy.Op.call: init %empty_tuple.type = call %Destroy.Op.bound(%a.var)
  370. // CHECK:STDOUT: return
  371. // CHECK:STDOUT: }
  372. // CHECK:STDOUT:
  373. // CHECK:STDOUT: fn @Destroy.Op.loc9_3.1(%self.param: ref %empty_struct_type) = "no_op";
  374. // CHECK:STDOUT:
  375. // CHECK:STDOUT: fn @Destroy.Op.loc9_3.2(%self.param: ref %D.213) {
  376. // CHECK:STDOUT: !entry:
  377. // CHECK:STDOUT: return
  378. // CHECK:STDOUT: }
  379. // CHECK:STDOUT:
  380. // CHECK:STDOUT: --- generic_use_inside_generic.carbon
  381. // CHECK:STDOUT:
  382. // CHECK:STDOUT: constants {
  383. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  384. // CHECK:STDOUT: %T: type = symbolic_binding T, 0, template [template]
  385. // CHECK:STDOUT: %C.type: type = generic_class_type @C [concrete]
  386. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  387. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [concrete]
  388. // CHECK:STDOUT: %C.5a3: type = class_type @C, @C(%T) [template]
  389. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  390. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  391. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  392. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  393. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %C.5a3 [template]
  394. // CHECK:STDOUT: %pattern_type.3d5: type = pattern_type %C.5a3 [template]
  395. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  396. // CHECK:STDOUT: %C.val.8b3: %C.5a3 = struct_value () [template]
  397. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  398. // CHECK:STDOUT: %Destroy.lookup_impl_witness: <witness> = lookup_impl_witness %C.5a3, @Destroy [template]
  399. // CHECK:STDOUT: %Destroy.facet.472: %Destroy.type = facet_value %C.5a3, (%Destroy.lookup_impl_witness) [template]
  400. // CHECK:STDOUT: %Destroy.WithSelf.Op.type.7d1: type = fn_type @Destroy.WithSelf.Op, @Destroy.WithSelf(%Destroy.facet.472) [template]
  401. // CHECK:STDOUT: %.306: type = fn_type_with_self_type %Destroy.WithSelf.Op.type.7d1, %Destroy.facet.472 [template]
  402. // CHECK:STDOUT: %impl.elem0: %.306 = impl_witness_access %Destroy.lookup_impl_witness, element0 [template]
  403. // CHECK:STDOUT: %specific_impl_fn: <specific function> = specific_impl_function %impl.elem0, @Destroy.WithSelf.Op(%Destroy.facet.472) [template]
  404. // CHECK:STDOUT: %C.850: type = class_type @C, @C(%empty_struct_type) [concrete]
  405. // CHECK:STDOUT: %pattern_type.526: type = pattern_type %C.850 [concrete]
  406. // CHECK:STDOUT: %C.val.09d: %C.850 = struct_value () [concrete]
  407. // CHECK:STDOUT: %Destroy.Op.type.bae255.2: type = fn_type @Destroy.Op.loc7_3.2 [concrete]
  408. // CHECK:STDOUT: %Destroy.Op.651ba6.2: %Destroy.Op.type.bae255.2 = struct_value () [concrete]
  409. // CHECK:STDOUT: %custom_witness.8d7fae.2: <witness> = custom_witness (%Destroy.Op.651ba6.2), @Destroy [concrete]
  410. // CHECK:STDOUT: %Destroy.facet.81b: %Destroy.type = facet_value %C.850, (%custom_witness.8d7fae.2) [concrete]
  411. // CHECK:STDOUT: %Destroy.WithSelf.Op.type.599: type = fn_type @Destroy.WithSelf.Op, @Destroy.WithSelf(%Destroy.facet.81b) [concrete]
  412. // CHECK:STDOUT: %.540: type = fn_type_with_self_type %Destroy.WithSelf.Op.type.599, %Destroy.facet.81b [concrete]
  413. // CHECK:STDOUT: }
  414. // CHECK:STDOUT:
  415. // CHECK:STDOUT: file {
  416. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  417. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0, template [concrete]
  418. // CHECK:STDOUT: } {
  419. // CHECK:STDOUT: %.loc6_19.1: type = splice_block %.loc6_19.2 [concrete = type] {
  420. // CHECK:STDOUT: <elided>
  421. // CHECK:STDOUT: %.loc6_19.2: type = type_literal type [concrete = type]
  422. // CHECK:STDOUT: }
  423. // CHECK:STDOUT: %T.loc6_16.2: type = symbolic_binding T, 0, template [template = %T.loc6_16.1 (constants.%T)]
  424. // CHECK:STDOUT: }
  425. // CHECK:STDOUT: }
  426. // CHECK:STDOUT:
  427. // CHECK:STDOUT: generic fn @F(%T.loc6_16.2: type) {
  428. // CHECK:STDOUT: %T.loc6_16.1: type = symbolic_binding T, 0, template [template = %T.loc6_16.1 (constants.%T)]
  429. // CHECK:STDOUT:
  430. // CHECK:STDOUT: !definition:
  431. // CHECK:STDOUT: %C.loc7_20.2: type = class_type @C, @C(%T.loc6_16.1) [template = %C.loc7_20.2 (constants.%C.5a3)]
  432. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %C.loc7_20.2 [template = %require_complete (constants.%require_complete)]
  433. // CHECK:STDOUT: %pattern_type: type = pattern_type %C.loc7_20.2 [template = %pattern_type (constants.%pattern_type.3d5)]
  434. // CHECK:STDOUT: %C.val: @F.%C.loc7_20.2 (%C.5a3) = struct_value () [template = %C.val (constants.%C.val.8b3)]
  435. // CHECK:STDOUT: %Destroy.lookup_impl_witness: <witness> = lookup_impl_witness %C.loc7_20.2, @Destroy [template = %Destroy.lookup_impl_witness (constants.%Destroy.lookup_impl_witness)]
  436. // CHECK:STDOUT: %Destroy.facet: %Destroy.type = facet_value %C.loc7_20.2, (%Destroy.lookup_impl_witness) [template = %Destroy.facet (constants.%Destroy.facet.472)]
  437. // CHECK:STDOUT: %Destroy.WithSelf.Op.type: type = fn_type @Destroy.WithSelf.Op, @Destroy.WithSelf(%Destroy.facet) [template = %Destroy.WithSelf.Op.type (constants.%Destroy.WithSelf.Op.type.7d1)]
  438. // CHECK:STDOUT: %.loc7_3.2: type = fn_type_with_self_type %Destroy.WithSelf.Op.type, %Destroy.facet [template = %.loc7_3.2 (constants.%.306)]
  439. // CHECK:STDOUT: %impl.elem0.loc7_3.2: @F.%.loc7_3.2 (%.306) = impl_witness_access %Destroy.lookup_impl_witness, element0 [template = %impl.elem0.loc7_3.2 (constants.%impl.elem0)]
  440. // CHECK:STDOUT: %specific_impl_fn.loc7_3.2: <specific function> = specific_impl_function %impl.elem0.loc7_3.2, @Destroy.WithSelf.Op(%Destroy.facet) [template = %specific_impl_fn.loc7_3.2 (constants.%specific_impl_fn)]
  441. // CHECK:STDOUT:
  442. // CHECK:STDOUT: fn() {
  443. // CHECK:STDOUT: !entry:
  444. // CHECK:STDOUT: name_binding_decl {
  445. // CHECK:STDOUT: %v.patt: @F.%pattern_type (%pattern_type.3d5) = ref_binding_pattern v [concrete]
  446. // CHECK:STDOUT: %v.var_patt: @F.%pattern_type (%pattern_type.3d5) = var_pattern %v.patt [concrete]
  447. // CHECK:STDOUT: }
  448. // CHECK:STDOUT: %v.var: ref @F.%C.loc7_20.2 (%C.5a3) = var %v.var_patt
  449. // CHECK:STDOUT: %.loc7_25.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  450. // CHECK:STDOUT: %.loc7_25.2: init @F.%C.loc7_20.2 (%C.5a3) to %v.var = class_init () [template = %C.val (constants.%C.val.8b3)]
  451. // CHECK:STDOUT: %.loc7_3.1: init @F.%C.loc7_20.2 (%C.5a3) = converted %.loc7_25.1, %.loc7_25.2 [template = %C.val (constants.%C.val.8b3)]
  452. // CHECK:STDOUT: assign %v.var, %.loc7_3.1
  453. // CHECK:STDOUT: %.loc7_20: type = splice_block %C.loc7_20.1 [template = %C.loc7_20.2 (constants.%C.5a3)] {
  454. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [concrete = constants.%C.generic]
  455. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc6_16.2 [template = %T.loc6_16.1 (constants.%T)]
  456. // CHECK:STDOUT: %C.loc7_20.1: type = class_type @C, @C(constants.%T) [template = %C.loc7_20.2 (constants.%C.5a3)]
  457. // CHECK:STDOUT: }
  458. // CHECK:STDOUT: %v: ref @F.%C.loc7_20.2 (%C.5a3) = ref_binding v, %v.var
  459. // CHECK:STDOUT: %impl.elem0.loc7_3.1: @F.%.loc7_3.2 (%.306) = impl_witness_access constants.%Destroy.lookup_impl_witness, element0 [template = %impl.elem0.loc7_3.2 (constants.%impl.elem0)]
  460. // CHECK:STDOUT: %bound_method.loc7_3.1: <bound method> = bound_method %v.var, %impl.elem0.loc7_3.1
  461. // CHECK:STDOUT: %specific_impl_fn.loc7_3.1: <specific function> = specific_impl_function %impl.elem0.loc7_3.1, @Destroy.WithSelf.Op(constants.%Destroy.facet.472) [template = %specific_impl_fn.loc7_3.2 (constants.%specific_impl_fn)]
  462. // CHECK:STDOUT: %bound_method.loc7_3.2: <bound method> = bound_method %v.var, %specific_impl_fn.loc7_3.1
  463. // CHECK:STDOUT: %Destroy.WithSelf.Op.call: init %empty_tuple.type = call %bound_method.loc7_3.2(%v.var)
  464. // CHECK:STDOUT: return
  465. // CHECK:STDOUT: }
  466. // CHECK:STDOUT: }
  467. // CHECK:STDOUT:
  468. // CHECK:STDOUT: fn @Destroy.Op.loc7_3.1(%self.param: ref %empty_struct_type) = "no_op";
  469. // CHECK:STDOUT:
  470. // CHECK:STDOUT: fn @Destroy.Op.loc7_3.2(%self.param: ref %C.850) {
  471. // CHECK:STDOUT: !entry:
  472. // CHECK:STDOUT: return
  473. // CHECK:STDOUT: }
  474. // CHECK:STDOUT:
  475. // CHECK:STDOUT: specific @F(constants.%T) {
  476. // CHECK:STDOUT: %T.loc6_16.1 => constants.%T
  477. // CHECK:STDOUT: }
  478. // CHECK:STDOUT:
  479. // CHECK:STDOUT: specific @F(constants.%empty_struct_type) {
  480. // CHECK:STDOUT: %T.loc6_16.1 => constants.%empty_struct_type
  481. // CHECK:STDOUT:
  482. // CHECK:STDOUT: !definition:
  483. // CHECK:STDOUT: %C.loc7_20.2 => constants.%C.850
  484. // CHECK:STDOUT: %require_complete => constants.%complete_type
  485. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.526
  486. // CHECK:STDOUT: %C.val => constants.%C.val.09d
  487. // CHECK:STDOUT: %Destroy.lookup_impl_witness => constants.%custom_witness.8d7fae.2
  488. // CHECK:STDOUT: %Destroy.facet => constants.%Destroy.facet.81b
  489. // CHECK:STDOUT: %Destroy.WithSelf.Op.type => constants.%Destroy.WithSelf.Op.type.599
  490. // CHECK:STDOUT: %.loc7_3.2 => constants.%.540
  491. // CHECK:STDOUT: %impl.elem0.loc7_3.2 => constants.%Destroy.Op.651ba6.2
  492. // CHECK:STDOUT: %specific_impl_fn.loc7_3.2 => constants.%Destroy.Op.651ba6.2
  493. // CHECK:STDOUT: }
  494. // CHECK:STDOUT: