import_struct_cyle.carbon 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "a";
  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 "b";
  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: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: file {
  35. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  36. // CHECK:STDOUT: .Core = %Core
  37. // CHECK:STDOUT: .Cycle = %Cycle.decl.loc4
  38. // CHECK:STDOUT: .a = %a
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  41. // CHECK:STDOUT: %Cycle.decl.loc4: type = class_decl @Cycle [template = constants.%Cycle] {}
  42. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, %Cycle.decl.loc4 [template = constants.%Cycle]
  43. // CHECK:STDOUT: %.loc6_18: type = ptr_type %Cycle [template = constants.%.1]
  44. // CHECK:STDOUT: %.loc6_19: type = struct_type {.b: %.1} [template = constants.%.2]
  45. // CHECK:STDOUT: %a.var: ref %.2 = var a
  46. // CHECK:STDOUT: %a: ref %.2 = bind_name a, %a.var
  47. // CHECK:STDOUT: %Cycle.decl.loc8: type = class_decl @Cycle [template = constants.%Cycle] {}
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: class @Cycle {
  51. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, file.%Cycle.decl.loc4 [template = constants.%Cycle]
  52. // CHECK:STDOUT: %.loc10_20: type = ptr_type %Cycle [template = constants.%.1]
  53. // CHECK:STDOUT: %.loc10_21: type = struct_type {.b: %.1} [template = constants.%.2]
  54. // CHECK:STDOUT: %.loc10_8: %.3 = field_decl c, element0 [template]
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: !members:
  57. // CHECK:STDOUT: .Self = constants.%Cycle
  58. // CHECK:STDOUT: .c = %.loc10_8
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: --- b.carbon
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: constants {
  64. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  65. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  66. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  67. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  68. // CHECK:STDOUT: %.2: type = ptr_type %Cycle [template]
  69. // CHECK:STDOUT: %.3: type = struct_type {.b: %.2} [template]
  70. // CHECK:STDOUT: %.4: type = struct_type {.c: %.3} [template]
  71. // CHECK:STDOUT: %.5: type = ptr_type %.4 [template]
  72. // CHECK:STDOUT: %.6: type = unbound_element_type %Cycle, %.3 [template]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: file {
  76. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  77. // CHECK:STDOUT: .Cycle = %import_ref.1
  78. // CHECK:STDOUT: .a = %import_ref.2
  79. // CHECK:STDOUT: .Core = %Core
  80. // CHECK:STDOUT: .Run = %Run.decl
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+2, unloaded
  83. // CHECK:STDOUT: %import_ref.2: ref %.3 = import_ref ir1, inst+12, loaded
  84. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  85. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {}
  86. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+3, unloaded
  87. // CHECK:STDOUT: %import_ref.4: %.6 = import_ref ir1, inst+19, loaded [template = imports.%.1]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: class @Cycle {
  91. // CHECK:STDOUT: !members:
  92. // CHECK:STDOUT: .Self = file.%import_ref.3
  93. // CHECK:STDOUT: .c = file.%import_ref.4
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @Run() {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: %a.ref.loc7_3: ref %.3 = name_ref a, file.%import_ref.2
  99. // CHECK:STDOUT: %.loc7_4: ref %.2 = struct_access %a.ref.loc7_3, element0
  100. // CHECK:STDOUT: %a.ref.loc7_11: ref %.3 = name_ref a, file.%import_ref.2
  101. // CHECK:STDOUT: %.loc7_12.1: ref %.2 = struct_access %a.ref.loc7_11, element0
  102. // CHECK:STDOUT: %.loc7_12.2: %.2 = bind_value %.loc7_12.1
  103. // CHECK:STDOUT: %.loc7_10: ref %Cycle = deref %.loc7_12.2
  104. // CHECK:STDOUT: %c.ref: %.6 = name_ref c, file.%import_ref.4 [template = imports.%.1]
  105. // CHECK:STDOUT: %.loc7_15: ref %.3 = class_element_access %.loc7_10, element0
  106. // CHECK:STDOUT: %.loc7_17.1: ref %.2 = struct_access %.loc7_15, element0
  107. // CHECK:STDOUT: %.loc7_17.2: %.2 = bind_value %.loc7_17.1
  108. // CHECK:STDOUT: assign %.loc7_4, %.loc7_17.2
  109. // CHECK:STDOUT: return
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: