import_order.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/alias/no_prelude/import_order.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/no_prelude/import_order.carbon
  10. // --- a.carbon
  11. library "a";
  12. class C { var v: (); }
  13. alias a = C;
  14. alias b = a;
  15. alias c = b;
  16. alias d = c;
  17. // --- b.carbon
  18. library "b";
  19. import library "a";
  20. // Access imports in reverse order of export.
  21. var d_val: d = {.v = ()};
  22. var c_val: c = {.v = d_val.v};
  23. var b_val: b = {.v = c_val.v};
  24. var a_val: a = {.v = b_val.v};
  25. // CHECK:STDOUT: --- a.carbon
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: constants {
  28. // CHECK:STDOUT: %C: type = class_type @C [template]
  29. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  30. // CHECK:STDOUT: %.2: type = unbound_element_type %C, %.1 [template]
  31. // CHECK:STDOUT: %.3: type = struct_type {.v: %.1} [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: file {
  35. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  36. // CHECK:STDOUT: .C = %C.decl
  37. // CHECK:STDOUT: .a = %a
  38. // CHECK:STDOUT: .b = %b
  39. // CHECK:STDOUT: .c = %c
  40. // CHECK:STDOUT: .d = %d
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  43. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  44. // CHECK:STDOUT: %a: type = bind_alias a, %C.decl [template = constants.%C]
  45. // CHECK:STDOUT: %a.ref: type = name_ref a, %a [template = constants.%C]
  46. // CHECK:STDOUT: %b: type = bind_alias b, %a [template = constants.%C]
  47. // CHECK:STDOUT: %b.ref: type = name_ref b, %b [template = constants.%C]
  48. // CHECK:STDOUT: %c: type = bind_alias c, %b [template = constants.%C]
  49. // CHECK:STDOUT: %c.ref: type = name_ref c, %c [template = constants.%C]
  50. // CHECK:STDOUT: %d: type = bind_alias d, %c [template = constants.%C]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: class @C {
  54. // CHECK:STDOUT: %.loc4_19.1: %.1 = tuple_literal ()
  55. // CHECK:STDOUT: %.loc4_19.2: type = converted %.loc4_19.1, constants.%.1 [template = constants.%.1]
  56. // CHECK:STDOUT: %.loc4_16: %.2 = field_decl v, element0 [template]
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: !members:
  59. // CHECK:STDOUT: .Self = constants.%C
  60. // CHECK:STDOUT: .v = %.loc4_16
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: --- b.carbon
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: constants {
  66. // CHECK:STDOUT: %C: type = class_type @C [template]
  67. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  68. // CHECK:STDOUT: %.2: type = struct_type {.v: %.1} [template]
  69. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  70. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  71. // CHECK:STDOUT: %struct: %C = struct_value (%tuple) [template]
  72. // CHECK:STDOUT: %.4: type = unbound_element_type %C, %.1 [template]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: file {
  76. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  77. // CHECK:STDOUT: .C = %import_ref.1
  78. // CHECK:STDOUT: .a = %import_ref.2
  79. // CHECK:STDOUT: .b = %import_ref.3
  80. // CHECK:STDOUT: .c = %import_ref.4
  81. // CHECK:STDOUT: .d = %import_ref.5
  82. // CHECK:STDOUT: .d_val = %d_val
  83. // CHECK:STDOUT: .c_val = %c_val
  84. // CHECK:STDOUT: .b_val = %b_val
  85. // CHECK:STDOUT: .a_val = %a_val
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+1, unloaded
  88. // CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+12, loaded [template = constants.%C]
  89. // CHECK:STDOUT: %import_ref.3: type = import_ref ir1, inst+14, loaded [template = constants.%C]
  90. // CHECK:STDOUT: %import_ref.4: type = import_ref ir1, inst+16, loaded [template = constants.%C]
  91. // CHECK:STDOUT: %import_ref.5: type = import_ref ir1, inst+18, loaded [template = constants.%C]
  92. // CHECK:STDOUT: %import_ref.6 = import_ref ir1, inst+2, unloaded
  93. // CHECK:STDOUT: %import_ref.7: %.4 = import_ref ir1, inst+7, loaded [template = imports.%.1]
  94. // CHECK:STDOUT: %d.ref: type = name_ref d, %import_ref.5 [template = constants.%C]
  95. // CHECK:STDOUT: %d_val.var: ref %C = var d_val
  96. // CHECK:STDOUT: %d_val: ref %C = bind_name d_val, %d_val.var
  97. // CHECK:STDOUT: %c.ref: type = name_ref c, %import_ref.4 [template = constants.%C]
  98. // CHECK:STDOUT: %c_val.var: ref %C = var c_val
  99. // CHECK:STDOUT: %c_val: ref %C = bind_name c_val, %c_val.var
  100. // CHECK:STDOUT: %b.ref: type = name_ref b, %import_ref.3 [template = constants.%C]
  101. // CHECK:STDOUT: %b_val.var: ref %C = var b_val
  102. // CHECK:STDOUT: %b_val: ref %C = bind_name b_val, %b_val.var
  103. // CHECK:STDOUT: %a.ref: type = name_ref a, %import_ref.2 [template = constants.%C]
  104. // CHECK:STDOUT: %a_val.var: ref %C = var a_val
  105. // CHECK:STDOUT: %a_val: ref %C = bind_name a_val, %a_val.var
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: class @C {
  109. // CHECK:STDOUT: !members:
  110. // CHECK:STDOUT: .Self = file.%import_ref.6
  111. // CHECK:STDOUT: .v = file.%import_ref.7
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: fn @__global_init() {
  115. // CHECK:STDOUT: !entry:
  116. // CHECK:STDOUT: %.loc7_23.1: %.1 = tuple_literal ()
  117. // CHECK:STDOUT: %.loc7_24.1: %.2 = struct_literal (%.loc7_23.1)
  118. // CHECK:STDOUT: %.loc7_24.2: ref %.1 = class_element_access file.%d_val.var, element0
  119. // CHECK:STDOUT: %.loc7_23.2: init %.1 = tuple_init () to %.loc7_24.2 [template = constants.%tuple]
  120. // CHECK:STDOUT: %.loc7_24.3: init %.1 = converted %.loc7_23.1, %.loc7_23.2 [template = constants.%tuple]
  121. // CHECK:STDOUT: %.loc7_24.4: init %C = class_init (%.loc7_24.3), file.%d_val.var [template = constants.%struct]
  122. // CHECK:STDOUT: %.loc7_25: init %C = converted %.loc7_24.1, %.loc7_24.4 [template = constants.%struct]
  123. // CHECK:STDOUT: assign file.%d_val.var, %.loc7_25
  124. // CHECK:STDOUT: %d_val.ref: ref %C = name_ref d_val, file.%d_val
  125. // CHECK:STDOUT: %v.ref.loc8: %.4 = name_ref v, file.%import_ref.7 [template = imports.%.1]
  126. // CHECK:STDOUT: %.loc8_27.1: ref %.1 = class_element_access %d_val.ref, element0
  127. // CHECK:STDOUT: %.loc8_29.1: %.2 = struct_literal (%.loc8_27.1)
  128. // CHECK:STDOUT: %.loc8_29.2: ref %.1 = class_element_access file.%c_val.var, element0
  129. // CHECK:STDOUT: %.loc8_27.2: init %.1 = tuple_init () to %.loc8_29.2 [template = constants.%tuple]
  130. // CHECK:STDOUT: %.loc8_29.3: init %.1 = converted %.loc8_27.1, %.loc8_27.2 [template = constants.%tuple]
  131. // CHECK:STDOUT: %.loc8_29.4: init %C = class_init (%.loc8_29.3), file.%c_val.var [template = constants.%struct]
  132. // CHECK:STDOUT: %.loc8_30: init %C = converted %.loc8_29.1, %.loc8_29.4 [template = constants.%struct]
  133. // CHECK:STDOUT: assign file.%c_val.var, %.loc8_30
  134. // CHECK:STDOUT: %c_val.ref: ref %C = name_ref c_val, file.%c_val
  135. // CHECK:STDOUT: %v.ref.loc9: %.4 = name_ref v, file.%import_ref.7 [template = imports.%.1]
  136. // CHECK:STDOUT: %.loc9_27.1: ref %.1 = class_element_access %c_val.ref, element0
  137. // CHECK:STDOUT: %.loc9_29.1: %.2 = struct_literal (%.loc9_27.1)
  138. // CHECK:STDOUT: %.loc9_29.2: ref %.1 = class_element_access file.%b_val.var, element0
  139. // CHECK:STDOUT: %.loc9_27.2: init %.1 = tuple_init () to %.loc9_29.2 [template = constants.%tuple]
  140. // CHECK:STDOUT: %.loc9_29.3: init %.1 = converted %.loc9_27.1, %.loc9_27.2 [template = constants.%tuple]
  141. // CHECK:STDOUT: %.loc9_29.4: init %C = class_init (%.loc9_29.3), file.%b_val.var [template = constants.%struct]
  142. // CHECK:STDOUT: %.loc9_30: init %C = converted %.loc9_29.1, %.loc9_29.4 [template = constants.%struct]
  143. // CHECK:STDOUT: assign file.%b_val.var, %.loc9_30
  144. // CHECK:STDOUT: %b_val.ref: ref %C = name_ref b_val, file.%b_val
  145. // CHECK:STDOUT: %v.ref.loc10: %.4 = name_ref v, file.%import_ref.7 [template = imports.%.1]
  146. // CHECK:STDOUT: %.loc10_27.1: ref %.1 = class_element_access %b_val.ref, element0
  147. // CHECK:STDOUT: %.loc10_29.1: %.2 = struct_literal (%.loc10_27.1)
  148. // CHECK:STDOUT: %.loc10_29.2: ref %.1 = class_element_access file.%a_val.var, element0
  149. // CHECK:STDOUT: %.loc10_27.2: init %.1 = tuple_init () to %.loc10_29.2 [template = constants.%tuple]
  150. // CHECK:STDOUT: %.loc10_29.3: init %.1 = converted %.loc10_27.1, %.loc10_27.2 [template = constants.%tuple]
  151. // CHECK:STDOUT: %.loc10_29.4: init %C = class_init (%.loc10_29.3), file.%a_val.var [template = constants.%struct]
  152. // CHECK:STDOUT: %.loc10_30: init %C = converted %.loc10_29.1, %.loc10_29.4 [template = constants.%struct]
  153. // CHECK:STDOUT: assign file.%a_val.var, %.loc10_30
  154. // CHECK:STDOUT: return
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT: