import_struct_cyle.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/import_struct_cyle.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/import_struct_cyle.carbon
  10. // --- a.carbon
  11. library "[[@TEST_NAME]]";
  12. class Cycle;
  13. var a: {.b: Cycle*};
  14. class Cycle {
  15. // The type here is equivalent to the `a` above, but on import can be resolved first.
  16. var c: {.b: Cycle*};
  17. }
  18. // --- b.carbon
  19. library "[[@TEST_NAME]]";
  20. import library "a";
  21. fn Run() {
  22. a.b = (*a.b).c.b;
  23. }
  24. // CHECK:STDOUT: --- a.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  28. // CHECK:STDOUT: %.1: type = ptr_type %Cycle [template]
  29. // CHECK:STDOUT: %.2: type = struct_type {.b: %.1} [template]
  30. // CHECK:STDOUT: %.3: type = unbound_element_type %Cycle, %.2 [template]
  31. // CHECK:STDOUT: %.4: type = struct_type {.c: %.2} [template]
  32. // CHECK:STDOUT: %.5: <witness> = complete_type_witness %.4 [template]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/operators
  39. // CHECK:STDOUT: import Core//prelude/types
  40. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  41. // CHECK:STDOUT: import Core//prelude/operators/as
  42. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  43. // CHECK:STDOUT: import Core//prelude/operators/comparison
  44. // CHECK:STDOUT: import Core//prelude/types/bool
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = imports.%Core
  51. // CHECK:STDOUT: .Cycle = %Cycle.decl.loc4
  52. // CHECK:STDOUT: .a = %a
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.import = import Core
  55. // CHECK:STDOUT: %Cycle.decl.loc4: type = class_decl @Cycle [template = constants.%Cycle] {} {}
  56. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, %Cycle.decl.loc4 [template = constants.%Cycle]
  57. // CHECK:STDOUT: %.loc6_18: type = ptr_type %Cycle [template = constants.%.1]
  58. // CHECK:STDOUT: %.loc6_19: type = struct_type {.b: %.1} [template = constants.%.2]
  59. // CHECK:STDOUT: %a.var: ref %.2 = var a
  60. // CHECK:STDOUT: %a: ref %.2 = bind_name a, %a.var
  61. // CHECK:STDOUT: %Cycle.decl.loc8: type = class_decl @Cycle [template = constants.%Cycle] {} {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class @Cycle {
  65. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, file.%Cycle.decl.loc4 [template = constants.%Cycle]
  66. // CHECK:STDOUT: %.loc10_20: type = ptr_type %Cycle [template = constants.%.1]
  67. // CHECK:STDOUT: %.loc10_21: type = struct_type {.b: %.1} [template = constants.%.2]
  68. // CHECK:STDOUT: %.loc10_8: %.3 = field_decl c, element0 [template]
  69. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.4 [template = constants.%.5]
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = constants.%Cycle
  73. // CHECK:STDOUT: .c = %.loc10_8
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: --- b.carbon
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: constants {
  79. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  80. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  81. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  82. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  83. // CHECK:STDOUT: %.2: type = ptr_type %Cycle [template]
  84. // CHECK:STDOUT: %.3: type = struct_type {.b: %.2} [template]
  85. // CHECK:STDOUT: %.4: type = struct_type {.c: %.3} [template]
  86. // CHECK:STDOUT: %.5: <witness> = complete_type_witness %.4 [template]
  87. // CHECK:STDOUT: %.6: type = ptr_type %.4 [template]
  88. // CHECK:STDOUT: %.7: type = unbound_element_type %Cycle, %.3 [template]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: imports {
  92. // CHECK:STDOUT: %import_ref.1 = import_ref Main//a, inst+3, unloaded
  93. // CHECK:STDOUT: %import_ref.2: ref %.3 = import_ref Main//a, inst+13, loaded
  94. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  95. // CHECK:STDOUT: import Core//prelude
  96. // CHECK:STDOUT: import Core//prelude/operators
  97. // CHECK:STDOUT: import Core//prelude/types
  98. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  99. // CHECK:STDOUT: import Core//prelude/operators/as
  100. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  101. // CHECK:STDOUT: import Core//prelude/operators/comparison
  102. // CHECK:STDOUT: import Core//prelude/types/bool
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %import_ref.3 = import_ref Main//a, inst+4, unloaded
  105. // CHECK:STDOUT: %import_ref.4: %.7 = import_ref Main//a, inst+20, loaded [template = %.1]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: file {
  109. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  110. // CHECK:STDOUT: .Cycle = imports.%import_ref.1
  111. // CHECK:STDOUT: .a = imports.%import_ref.2
  112. // CHECK:STDOUT: .Core = imports.%Core
  113. // CHECK:STDOUT: .Run = %Run.decl
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %Core.import = import Core
  116. // CHECK:STDOUT: %default.import = import <invalid>
  117. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {}
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: class @Cycle {
  121. // CHECK:STDOUT: !members:
  122. // CHECK:STDOUT: .Self = imports.%import_ref.3
  123. // CHECK:STDOUT: .c = imports.%import_ref.4
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: fn @Run() {
  127. // CHECK:STDOUT: !entry:
  128. // CHECK:STDOUT: %a.ref.loc7_3: ref %.3 = name_ref a, imports.%import_ref.2
  129. // CHECK:STDOUT: %.loc7_4: ref %.2 = struct_access %a.ref.loc7_3, element0
  130. // CHECK:STDOUT: %a.ref.loc7_11: ref %.3 = name_ref a, imports.%import_ref.2
  131. // CHECK:STDOUT: %.loc7_12.1: ref %.2 = struct_access %a.ref.loc7_11, element0
  132. // CHECK:STDOUT: %.loc7_12.2: %.2 = bind_value %.loc7_12.1
  133. // CHECK:STDOUT: %.loc7_10: ref %Cycle = deref %.loc7_12.2
  134. // CHECK:STDOUT: %c.ref: %.7 = name_ref c, imports.%import_ref.4 [template = imports.%.1]
  135. // CHECK:STDOUT: %.loc7_15: ref %.3 = class_element_access %.loc7_10, element0
  136. // CHECK:STDOUT: %.loc7_17.1: ref %.2 = struct_access %.loc7_15, element0
  137. // CHECK:STDOUT: %.loc7_17.2: %.2 = bind_value %.loc7_17.1
  138. // CHECK:STDOUT: assign %.loc7_4, %.loc7_17.2
  139. // CHECK:STDOUT: return
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: