reorder_qualified.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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/reorder_qualified.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/reorder_qualified.carbon
  10. class A {
  11. class B {
  12. class C;
  13. fn BF();
  14. var b: i32;
  15. }
  16. class B.C {
  17. class D {
  18. fn F();
  19. fn DF();
  20. var d: i32;
  21. }
  22. fn D.DF() {
  23. // A, B, C, and D are complete here.
  24. var a: A = {.a = 1};
  25. var b: B = {.b = 2};
  26. var c: C = {.c = 3};
  27. var d: D = {.d = 4};
  28. // Unqualified lookup looks in all of them.
  29. AF();
  30. BF();
  31. CF();
  32. DF();
  33. }
  34. fn CF();
  35. var c: i32;
  36. }
  37. fn AF();
  38. var a: i32;
  39. }
  40. // CHECK:STDOUT: --- reorder_qualified.carbon
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: constants {
  43. // CHECK:STDOUT: %A: type = class_type @A [template]
  44. // CHECK:STDOUT: %B: type = class_type @B [template]
  45. // CHECK:STDOUT: %C: type = class_type @C [template]
  46. // CHECK:STDOUT: %BF.type: type = fn_type @BF [template]
  47. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  48. // CHECK:STDOUT: %BF: %BF.type = struct_value () [template]
  49. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  50. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  51. // CHECK:STDOUT: %.2: type = unbound_element_type %B, i32 [template]
  52. // CHECK:STDOUT: %.3: type = struct_type {.b: i32} [template]
  53. // CHECK:STDOUT: %D: type = class_type @D [template]
  54. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  55. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  56. // CHECK:STDOUT: %DF.type: type = fn_type @DF [template]
  57. // CHECK:STDOUT: %DF: %DF.type = struct_value () [template]
  58. // CHECK:STDOUT: %.4: type = unbound_element_type %D, i32 [template]
  59. // CHECK:STDOUT: %.5: type = struct_type {.d: i32} [template]
  60. // CHECK:STDOUT: %CF.type: type = fn_type @CF [template]
  61. // CHECK:STDOUT: %CF: %CF.type = struct_value () [template]
  62. // CHECK:STDOUT: %.6: type = unbound_element_type %C, i32 [template]
  63. // CHECK:STDOUT: %.7: type = struct_type {.c: i32} [template]
  64. // CHECK:STDOUT: %AF.type: type = fn_type @AF [template]
  65. // CHECK:STDOUT: %AF: %AF.type = struct_value () [template]
  66. // CHECK:STDOUT: %.8: type = unbound_element_type %A, i32 [template]
  67. // CHECK:STDOUT: %.9: type = struct_type {.a: i32} [template]
  68. // CHECK:STDOUT: %.10: type = ptr_type %.9 [template]
  69. // CHECK:STDOUT: %.11: i32 = int_literal 1 [template]
  70. // CHECK:STDOUT: %struct.1: %A = struct_value (%.11) [template]
  71. // CHECK:STDOUT: %.12: type = ptr_type %.3 [template]
  72. // CHECK:STDOUT: %.13: i32 = int_literal 2 [template]
  73. // CHECK:STDOUT: %struct.2: %B = struct_value (%.13) [template]
  74. // CHECK:STDOUT: %.14: type = ptr_type %.7 [template]
  75. // CHECK:STDOUT: %.15: i32 = int_literal 3 [template]
  76. // CHECK:STDOUT: %struct.3: %C = struct_value (%.15) [template]
  77. // CHECK:STDOUT: %.16: type = ptr_type %.5 [template]
  78. // CHECK:STDOUT: %.17: i32 = int_literal 4 [template]
  79. // CHECK:STDOUT: %struct.4: %D = struct_value (%.17) [template]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: file {
  83. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  84. // CHECK:STDOUT: .Core = %Core
  85. // CHECK:STDOUT: .A = %A.decl
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  88. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  89. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  90. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  91. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  92. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: class @A {
  96. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  97. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  98. // CHECK:STDOUT: %AF.decl: %AF.type = fn_decl @AF [template = constants.%AF] {}
  99. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  100. // CHECK:STDOUT: %.loc46_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  101. // CHECK:STDOUT: %.loc46_10.2: type = converted %int.make_type_32, %.loc46_10.1 [template = i32]
  102. // CHECK:STDOUT: %.loc46_8: %.8 = field_decl a, element0 [template]
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: !members:
  105. // CHECK:STDOUT: .Self = constants.%A
  106. // CHECK:STDOUT: .B = %B.decl
  107. // CHECK:STDOUT: .AF = %AF.decl
  108. // CHECK:STDOUT: .a = %.loc46_8
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: class @B {
  112. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  113. // CHECK:STDOUT: %BF.decl: %BF.type = fn_decl @BF [template = constants.%BF] {}
  114. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  115. // CHECK:STDOUT: %.loc16_12.1: type = value_of_initializer %int.make_type_32 [template = i32]
  116. // CHECK:STDOUT: %.loc16_12.2: type = converted %int.make_type_32, %.loc16_12.1 [template = i32]
  117. // CHECK:STDOUT: %.loc16_10: %.2 = field_decl b, element0 [template]
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: !members:
  120. // CHECK:STDOUT: .Self = constants.%B
  121. // CHECK:STDOUT: .C = %C.decl
  122. // CHECK:STDOUT: .BF = %BF.decl
  123. // CHECK:STDOUT: .b = %.loc16_10
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: class @C {
  127. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  128. // CHECK:STDOUT: %DF.decl: %DF.type = fn_decl @DF [template = constants.%DF] {}
  129. // CHECK:STDOUT: %CF.decl: %CF.type = fn_decl @CF [template = constants.%CF] {}
  130. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  131. // CHECK:STDOUT: %.loc42_12.1: type = value_of_initializer %int.make_type_32 [template = i32]
  132. // CHECK:STDOUT: %.loc42_12.2: type = converted %int.make_type_32, %.loc42_12.1 [template = i32]
  133. // CHECK:STDOUT: %.loc42_10: %.6 = field_decl c, element0 [template]
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: !members:
  136. // CHECK:STDOUT: .Self = constants.%C
  137. // CHECK:STDOUT: .D = %D.decl
  138. // CHECK:STDOUT: .CF = %CF.decl
  139. // CHECK:STDOUT: .c = %.loc42_10
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: class @D {
  143. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  144. // CHECK:STDOUT: %DF.decl: %DF.type = fn_decl @DF [template = constants.%DF] {}
  145. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  146. // CHECK:STDOUT: %.loc24_14.1: type = value_of_initializer %int.make_type_32 [template = i32]
  147. // CHECK:STDOUT: %.loc24_14.2: type = converted %int.make_type_32, %.loc24_14.1 [template = i32]
  148. // CHECK:STDOUT: %.loc24_12: %.4 = field_decl d, element0 [template]
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: !members:
  151. // CHECK:STDOUT: .Self = constants.%D
  152. // CHECK:STDOUT: .F = %F.decl
  153. // CHECK:STDOUT: .DF = %DF.decl
  154. // CHECK:STDOUT: .d = %.loc24_12
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: fn @BF();
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: fn @F();
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: fn @DF() {
  164. // CHECK:STDOUT: !entry:
  165. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  166. // CHECK:STDOUT: %a.var: ref %A = var a
  167. // CHECK:STDOUT: %a: ref %A = bind_name a, %a.var
  168. // CHECK:STDOUT: %.loc29_24: i32 = int_literal 1 [template = constants.%.11]
  169. // CHECK:STDOUT: %.loc29_25.1: %.9 = struct_literal (%.loc29_24)
  170. // CHECK:STDOUT: %.loc29_25.2: ref i32 = class_element_access %a.var, element0
  171. // CHECK:STDOUT: %.loc29_25.3: init i32 = initialize_from %.loc29_24 to %.loc29_25.2 [template = constants.%.11]
  172. // CHECK:STDOUT: %.loc29_25.4: init %A = class_init (%.loc29_25.3), %a.var [template = constants.%struct.1]
  173. // CHECK:STDOUT: %.loc29_26: init %A = converted %.loc29_25.1, %.loc29_25.4 [template = constants.%struct.1]
  174. // CHECK:STDOUT: assign %a.var, %.loc29_26
  175. // CHECK:STDOUT: %B.ref: type = name_ref B, @A.%B.decl [template = constants.%B]
  176. // CHECK:STDOUT: %b.var: ref %B = var b
  177. // CHECK:STDOUT: %b: ref %B = bind_name b, %b.var
  178. // CHECK:STDOUT: %.loc30_24: i32 = int_literal 2 [template = constants.%.13]
  179. // CHECK:STDOUT: %.loc30_25.1: %.3 = struct_literal (%.loc30_24)
  180. // CHECK:STDOUT: %.loc30_25.2: ref i32 = class_element_access %b.var, element0
  181. // CHECK:STDOUT: %.loc30_25.3: init i32 = initialize_from %.loc30_24 to %.loc30_25.2 [template = constants.%.13]
  182. // CHECK:STDOUT: %.loc30_25.4: init %B = class_init (%.loc30_25.3), %b.var [template = constants.%struct.2]
  183. // CHECK:STDOUT: %.loc30_26: init %B = converted %.loc30_25.1, %.loc30_25.4 [template = constants.%struct.2]
  184. // CHECK:STDOUT: assign %b.var, %.loc30_26
  185. // CHECK:STDOUT: %C.ref: type = name_ref C, @B.%C.decl [template = constants.%C]
  186. // CHECK:STDOUT: %c.var: ref %C = var c
  187. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  188. // CHECK:STDOUT: %.loc31_24: i32 = int_literal 3 [template = constants.%.15]
  189. // CHECK:STDOUT: %.loc31_25.1: %.7 = struct_literal (%.loc31_24)
  190. // CHECK:STDOUT: %.loc31_25.2: ref i32 = class_element_access %c.var, element0
  191. // CHECK:STDOUT: %.loc31_25.3: init i32 = initialize_from %.loc31_24 to %.loc31_25.2 [template = constants.%.15]
  192. // CHECK:STDOUT: %.loc31_25.4: init %C = class_init (%.loc31_25.3), %c.var [template = constants.%struct.3]
  193. // CHECK:STDOUT: %.loc31_26: init %C = converted %.loc31_25.1, %.loc31_25.4 [template = constants.%struct.3]
  194. // CHECK:STDOUT: assign %c.var, %.loc31_26
  195. // CHECK:STDOUT: %D.ref: type = name_ref D, @C.%D.decl [template = constants.%D]
  196. // CHECK:STDOUT: %d.var: ref %D = var d
  197. // CHECK:STDOUT: %d: ref %D = bind_name d, %d.var
  198. // CHECK:STDOUT: %.loc32_24: i32 = int_literal 4 [template = constants.%.17]
  199. // CHECK:STDOUT: %.loc32_25.1: %.5 = struct_literal (%.loc32_24)
  200. // CHECK:STDOUT: %.loc32_25.2: ref i32 = class_element_access %d.var, element0
  201. // CHECK:STDOUT: %.loc32_25.3: init i32 = initialize_from %.loc32_24 to %.loc32_25.2 [template = constants.%.17]
  202. // CHECK:STDOUT: %.loc32_25.4: init %D = class_init (%.loc32_25.3), %d.var [template = constants.%struct.4]
  203. // CHECK:STDOUT: %.loc32_26: init %D = converted %.loc32_25.1, %.loc32_25.4 [template = constants.%struct.4]
  204. // CHECK:STDOUT: assign %d.var, %.loc32_26
  205. // CHECK:STDOUT: %AF.ref: %AF.type = name_ref AF, @A.%AF.decl [template = constants.%AF]
  206. // CHECK:STDOUT: %AF.call: init %.1 = call %AF.ref()
  207. // CHECK:STDOUT: %BF.ref: %BF.type = name_ref BF, @B.%BF.decl [template = constants.%BF]
  208. // CHECK:STDOUT: %BF.call: init %.1 = call %BF.ref()
  209. // CHECK:STDOUT: %CF.ref: %CF.type = name_ref CF, @C.%CF.decl [template = constants.%CF]
  210. // CHECK:STDOUT: %CF.call: init %.1 = call %CF.ref()
  211. // CHECK:STDOUT: %DF.ref: %DF.type = name_ref DF, @D.%DF.decl [template = constants.%DF]
  212. // CHECK:STDOUT: %DF.call: init %.1 = call %DF.ref()
  213. // CHECK:STDOUT: return
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: fn @CF();
  217. // CHECK:STDOUT:
  218. // CHECK:STDOUT: fn @AF();
  219. // CHECK:STDOUT: