import_struct_cyle.carbon 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 [concrete]
  28. // CHECK:STDOUT: %ptr: type = ptr_type %Cycle [concrete]
  29. // CHECK:STDOUT: %struct_type.b: type = struct_type {.b: %ptr} [concrete]
  30. // CHECK:STDOUT: %Cycle.elem: type = unbound_element_type %Cycle, %struct_type.b [concrete]
  31. // CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %struct_type.b} [concrete]
  32. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.c [concrete]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .Cycle = %Cycle.decl.loc4
  46. // CHECK:STDOUT: .a = %a
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %Cycle.decl.loc4: type = class_decl @Cycle [concrete = constants.%Cycle] {} {}
  50. // CHECK:STDOUT: name_binding_decl {
  51. // CHECK:STDOUT: %a.patt: %struct_type.b = binding_pattern a
  52. // CHECK:STDOUT: %.loc6_1: %struct_type.b = var_pattern %a.patt
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %a.var: ref %struct_type.b = var a
  55. // CHECK:STDOUT: %.loc6_19: type = splice_block %struct_type.b [concrete = constants.%struct_type.b] {
  56. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, %Cycle.decl.loc4 [concrete = constants.%Cycle]
  57. // CHECK:STDOUT: %ptr: type = ptr_type %Cycle.ref [concrete = constants.%ptr]
  58. // CHECK:STDOUT: %struct_type.b: type = struct_type {.b: %ptr} [concrete = constants.%struct_type.b]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %a: ref %struct_type.b = bind_name a, %a.var
  61. // CHECK:STDOUT: %Cycle.decl.loc8: type = class_decl @Cycle [concrete = constants.%Cycle] {} {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class @Cycle {
  65. // CHECK:STDOUT: %.loc10_8: %Cycle.elem = field_decl c, element0 [concrete]
  66. // CHECK:STDOUT: name_binding_decl {
  67. // CHECK:STDOUT: %.loc10_3: %Cycle.elem = var_pattern %.loc10_8
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %.var: ref %Cycle.elem = var <none>
  70. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.c [concrete = constants.%complete_type]
  71. // CHECK:STDOUT: complete_type_witness = %complete_type
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: !members:
  74. // CHECK:STDOUT: .Self = constants.%Cycle
  75. // CHECK:STDOUT: .Cycle = <poisoned>
  76. // CHECK:STDOUT: .c = %.loc10_8
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: --- b.carbon
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: constants {
  82. // CHECK:STDOUT: %Run.type: type = fn_type @Run [concrete]
  83. // CHECK:STDOUT: %Run: %Run.type = struct_value () [concrete]
  84. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [concrete]
  85. // CHECK:STDOUT: %ptr.257: type = ptr_type %Cycle [concrete]
  86. // CHECK:STDOUT: %struct_type.b: type = struct_type {.b: %ptr.257} [concrete]
  87. // CHECK:STDOUT: %struct_type.c: type = struct_type {.c: %struct_type.b} [concrete]
  88. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.c [concrete]
  89. // CHECK:STDOUT: %Cycle.elem: type = unbound_element_type %Cycle, %struct_type.b [concrete]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: imports {
  93. // CHECK:STDOUT: %Main.Cycle = import_ref Main//a, Cycle, unloaded
  94. // CHECK:STDOUT: %Main.a: ref %struct_type.b = import_ref Main//a, a, loaded
  95. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  96. // CHECK:STDOUT: import Core//prelude
  97. // CHECK:STDOUT: import Core//prelude/...
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %Main.import_ref.b93: <witness> = import_ref Main//a, loc11_1, loaded [concrete = constants.%complete_type]
  100. // CHECK:STDOUT: %Main.import_ref.3a6 = import_ref Main//a, inst17 [no loc], unloaded
  101. // CHECK:STDOUT: %Main.import_ref.455: %Cycle.elem = import_ref Main//a, loc10_8, loaded [concrete = %.354]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: file {
  105. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  106. // CHECK:STDOUT: .Cycle = imports.%Main.Cycle
  107. // CHECK:STDOUT: .a = imports.%Main.a
  108. // CHECK:STDOUT: .Core = imports.%Core
  109. // CHECK:STDOUT: .Run = %Run.decl
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %Core.import = import Core
  112. // CHECK:STDOUT: %default.import = import <none>
  113. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [concrete = constants.%Run] {} {}
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: class @Cycle [from "a.carbon"] {
  117. // CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.b93
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: !members:
  120. // CHECK:STDOUT: .Self = imports.%Main.import_ref.3a6
  121. // CHECK:STDOUT: .c = imports.%Main.import_ref.455
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @Run() {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: %a.ref.loc7_3: ref %struct_type.b = name_ref a, imports.%Main.a
  127. // CHECK:STDOUT: %.loc7_4: ref %ptr.257 = struct_access %a.ref.loc7_3, element0
  128. // CHECK:STDOUT: %a.ref.loc7_11: ref %struct_type.b = name_ref a, imports.%Main.a
  129. // CHECK:STDOUT: %.loc7_12.1: ref %ptr.257 = struct_access %a.ref.loc7_11, element0
  130. // CHECK:STDOUT: %.loc7_12.2: %ptr.257 = bind_value %.loc7_12.1
  131. // CHECK:STDOUT: %.loc7_10: ref %Cycle = deref %.loc7_12.2
  132. // CHECK:STDOUT: %c.ref: %Cycle.elem = name_ref c, imports.%Main.import_ref.455 [concrete = imports.%.354]
  133. // CHECK:STDOUT: %.loc7_15: ref %struct_type.b = class_element_access %.loc7_10, element0
  134. // CHECK:STDOUT: %.loc7_17.1: ref %ptr.257 = struct_access %.loc7_15, element0
  135. // CHECK:STDOUT: %.loc7_17.2: %ptr.257 = bind_value %.loc7_17.1
  136. // CHECK:STDOUT: assign %.loc7_4, %.loc7_17.2
  137. // CHECK:STDOUT: return
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: