import_struct_cyle.carbon 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // --- a.carbon
  7. library "a" api;
  8. class Cycle;
  9. var a: {.b: Cycle*};
  10. class Cycle {
  11. // The type here is equivalent to the `a` above, but on import can be resolved first.
  12. var c: {.b: Cycle*};
  13. }
  14. // --- b.carbon
  15. library "b" api;
  16. import library "a";
  17. fn Run() {
  18. a.b = (*a.b).c.b;
  19. }
  20. // CHECK:STDOUT: --- a.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  24. // CHECK:STDOUT: %.1: type = ptr_type Cycle [template]
  25. // CHECK:STDOUT: %.2: type = struct_type {.b: Cycle*} [template]
  26. // CHECK:STDOUT: %.3: type = unbound_element_type Cycle, {.b: Cycle*} [template]
  27. // CHECK:STDOUT: %.4: type = struct_type {.c: {.b: Cycle*}} [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: file {
  31. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  32. // CHECK:STDOUT: .Core = %Core
  33. // CHECK:STDOUT: .Cycle = %Cycle.decl.loc4
  34. // CHECK:STDOUT: .a = %a
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  37. // CHECK:STDOUT: %Cycle.decl.loc4: type = class_decl @Cycle [template = constants.%Cycle] {}
  38. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, %Cycle.decl.loc4 [template = constants.%Cycle]
  39. // CHECK:STDOUT: %.loc6_18: type = ptr_type Cycle [template = constants.%.1]
  40. // CHECK:STDOUT: %.loc6_19: type = struct_type {.b: Cycle*} [template = constants.%.2]
  41. // CHECK:STDOUT: %a.var: ref {.b: Cycle*} = var a
  42. // CHECK:STDOUT: %a: ref {.b: Cycle*} = bind_name a, %a.var
  43. // CHECK:STDOUT: %Cycle.decl.loc8: type = class_decl @Cycle [template = constants.%Cycle] {}
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: class @Cycle {
  47. // CHECK:STDOUT: %Cycle.ref: type = name_ref Cycle, file.%Cycle.decl.loc4 [template = constants.%Cycle]
  48. // CHECK:STDOUT: %.loc10_20: type = ptr_type Cycle [template = constants.%.1]
  49. // CHECK:STDOUT: %.loc10_21: type = struct_type {.b: Cycle*} [template = constants.%.2]
  50. // CHECK:STDOUT: %.loc10_8: <unbound element of class Cycle> = field_decl c, element0 [template]
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: !members:
  53. // CHECK:STDOUT: .Self = constants.%Cycle
  54. // CHECK:STDOUT: .c = %.loc10_8
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: --- b.carbon
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: constants {
  60. // CHECK:STDOUT: %Cycle: type = class_type @Cycle [template]
  61. // CHECK:STDOUT: %.1: type = ptr_type Cycle [template]
  62. // CHECK:STDOUT: %.2: type = struct_type {.b: Cycle*} [template]
  63. // CHECK:STDOUT: %.3: type = struct_type {.c: {.b: Cycle*}} [template]
  64. // CHECK:STDOUT: %.4: type = ptr_type {.c: {.b: Cycle*}} [template]
  65. // CHECK:STDOUT: %.5: type = unbound_element_type Cycle, {.b: Cycle*} [template]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: file {
  69. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  70. // CHECK:STDOUT: .Cycle = %import_ref.1
  71. // CHECK:STDOUT: .a = %import_ref.2
  72. // CHECK:STDOUT: .Core = %Core
  73. // CHECK:STDOUT: .Run = %Run
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %import_ref.1 = import_ref ir2, inst+2, unloaded
  76. // CHECK:STDOUT: %import_ref.2: ref {.b: Cycle*} = import_ref ir2, inst+12, loc_14
  77. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  78. // CHECK:STDOUT: %Run: <function> = fn_decl @Run [template] {}
  79. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+3, unloaded
  80. // CHECK:STDOUT: %import_ref.4: <unbound element of class Cycle> = import_ref ir2, inst+19, loc_24 [template = imports.%.1]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: class @Cycle {
  84. // CHECK:STDOUT: !members:
  85. // CHECK:STDOUT: .Self = file.%import_ref.3
  86. // CHECK:STDOUT: .c = file.%import_ref.4
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @Run() {
  90. // CHECK:STDOUT: !entry:
  91. // CHECK:STDOUT: %Cycle.decl: invalid = class_decl @Cycle [template = constants.%Cycle] {}
  92. // CHECK:STDOUT: %a.ref.loc7_3: ref {.b: Cycle*} = name_ref a, file.%import_ref.2
  93. // CHECK:STDOUT: %.loc7_4: ref Cycle* = struct_access %a.ref.loc7_3, element0
  94. // CHECK:STDOUT: %a.ref.loc7_11: ref {.b: Cycle*} = name_ref a, file.%import_ref.2
  95. // CHECK:STDOUT: %.loc7_12.1: ref Cycle* = struct_access %a.ref.loc7_11, element0
  96. // CHECK:STDOUT: %.loc7_12.2: Cycle* = bind_value %.loc7_12.1
  97. // CHECK:STDOUT: %.loc7_10: ref Cycle = deref %.loc7_12.2
  98. // CHECK:STDOUT: %c.ref: <unbound element of class Cycle> = name_ref c, file.%import_ref.4 [template = imports.%.1]
  99. // CHECK:STDOUT: %.loc7_15: ref {.b: Cycle*} = class_element_access %.loc7_10, element0
  100. // CHECK:STDOUT: %.loc7_17.1: ref Cycle* = struct_access %.loc7_15, element0
  101. // CHECK:STDOUT: %.loc7_17.2: Cycle* = bind_value %.loc7_17.1
  102. // CHECK:STDOUT: assign %.loc7_4, %.loc7_17.2
  103. // CHECK:STDOUT: return
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: