import_member_cycle.carbon 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_member_cycle.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/import_member_cycle.carbon
  10. // --- a.carbon
  11. library "[[@TEST_NAME]]";
  12. class Cycle {
  13. var a: Cycle*;
  14. }
  15. // --- b.carbon
  16. library "[[@TEST_NAME]]";
  17. import library "a";
  18. fn Run() {
  19. var a: Cycle*;
  20. }
  21. // CHECK:STDOUT: --- a.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  25. // CHECK:STDOUT: %ptr: type = ptr_type %Cycle [template]
  26. // CHECK:STDOUT: %Cycle.elem: type = unbound_element_type %Cycle, %ptr [template]
  27. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %ptr} [template]
  28. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: imports {
  32. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/...
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = imports.%Core
  41. // CHECK:STDOUT: .Cycle = %Cycle.decl
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core.import = import Core
  44. // CHECK:STDOUT: %Cycle.decl: type = class_decl @Cycle [template = constants.%Cycle] {} {}
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: class @Cycle {
  48. // CHECK:STDOUT: %.loc5_8: %Cycle.elem = field_decl a, element0 [template]
  49. // CHECK:STDOUT: name_binding_decl {
  50. // CHECK:STDOUT: %.loc5_3: %Cycle.elem = var_pattern %.loc5_8
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %.var: ref %Cycle.elem = var <none>
  53. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [template = constants.%complete_type]
  54. // CHECK:STDOUT: complete_type_witness = %complete_type
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: !members:
  57. // CHECK:STDOUT: .Self = constants.%Cycle
  58. // CHECK:STDOUT: .a = %.loc5_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: %Run: %Run.type = struct_value () [template]
  66. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  67. // CHECK:STDOUT: %ptr: type = ptr_type %Cycle [template]
  68. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %ptr} [template]
  69. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [template]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: imports {
  73. // CHECK:STDOUT: %Main.Cycle: type = import_ref Main//a, Cycle, loaded [template = constants.%Cycle]
  74. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  75. // CHECK:STDOUT: import Core//prelude
  76. // CHECK:STDOUT: import Core//prelude/...
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %Main.import_ref.72d: <witness> = import_ref Main//a, loc6_1, loaded [template = constants.%complete_type]
  79. // CHECK:STDOUT: %Main.import_ref.3a6 = import_ref Main//a, inst16 [no loc], unloaded
  80. // CHECK:STDOUT: %Main.import_ref.4e0 = import_ref Main//a, loc5_8, unloaded
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: file {
  84. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  85. // CHECK:STDOUT: .Cycle = imports.%Main.Cycle
  86. // CHECK:STDOUT: .Core = imports.%Core
  87. // CHECK:STDOUT: .Run = %Run.decl
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %Core.import = import Core
  90. // CHECK:STDOUT: %default.import = import <none>
  91. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {}
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: class @Cycle [from "a.carbon"] {
  95. // CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.72d
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !members:
  98. // CHECK:STDOUT: .Self = imports.%Main.import_ref.3a6
  99. // CHECK:STDOUT: .a = imports.%Main.import_ref.4e0
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @Run() {
  103. // CHECK:STDOUT: !entry:
  104. // CHECK:STDOUT: name_binding_decl {
  105. // CHECK:STDOUT: %a.patt: %ptr = binding_pattern a
  106. // CHECK:STDOUT: %.loc7_3: %ptr = var_pattern %a.patt
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %a.var: ref %ptr = var a
  109. // CHECK:STDOUT: %.loc7_15: type = splice_block %ptr [template = constants.%ptr] {
  110. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, imports.%Main.Cycle [template = constants.%Cycle]
  111. // CHECK:STDOUT: %ptr: type = ptr_type %Cycle [template = constants.%ptr]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %a: ref %ptr = bind_name a, %a.var
  114. // CHECK:STDOUT: return
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: