import_member_cycle.carbon 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: %Cycle.elem = field_decl a, element0 [template]
  49. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [template = constants.%complete_type]
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: !members:
  52. // CHECK:STDOUT: .Self = constants.%Cycle
  53. // CHECK:STDOUT: .a = %.loc5
  54. // CHECK:STDOUT: complete_type_witness = %complete_type
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: --- b.carbon
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: constants {
  60. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  61. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  62. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  63. // CHECK:STDOUT: %ptr: type = ptr_type %Cycle [template]
  64. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %ptr} [template]
  65. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [template]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: imports {
  69. // CHECK:STDOUT: %import_ref.a2c: type = import_ref Main//a, Cycle, loaded [template = constants.%Cycle]
  70. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  71. // CHECK:STDOUT: import Core//prelude
  72. // CHECK:STDOUT: import Core//prelude/...
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %import_ref.72d: <witness> = import_ref Main//a, loc6_1, loaded [template = constants.%complete_type]
  75. // CHECK:STDOUT: %import_ref.3a6 = import_ref Main//a, inst16 [no loc], unloaded
  76. // CHECK:STDOUT: %import_ref.4e0 = import_ref Main//a, loc5_8, unloaded
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: file {
  80. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  81. // CHECK:STDOUT: .Cycle = imports.%import_ref.a2c
  82. // CHECK:STDOUT: .Core = imports.%Core
  83. // CHECK:STDOUT: .Run = %Run.decl
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %Core.import = import Core
  86. // CHECK:STDOUT: %default.import = import <invalid>
  87. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {}
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: class @Cycle [from "a.carbon"] {
  91. // CHECK:STDOUT: !members:
  92. // CHECK:STDOUT: .Self = imports.%import_ref.3a6
  93. // CHECK:STDOUT: .a = imports.%import_ref.4e0
  94. // CHECK:STDOUT: complete_type_witness = imports.%import_ref.72d
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @Run() {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: %a.var: ref %ptr = var a
  100. // CHECK:STDOUT: %a: ref %ptr = bind_name a, %a.var
  101. // CHECK:STDOUT: return
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: