import.carbon 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. interface Empty {
  9. }
  10. interface Basic {
  11. let T:! type;
  12. fn F();
  13. }
  14. interface ForwardDeclared;
  15. interface ForwardDeclared {
  16. let T:! type;
  17. fn F();
  18. }
  19. var f_ref: {.f: ForwardDeclared};
  20. // --- b.carbon
  21. library "b" api;
  22. import library "a";
  23. fn UseEmpty(e: Empty) {}
  24. fn UseBasic(e: Basic) {}
  25. fn UseForwardDeclared(f: ForwardDeclared) {}
  26. var f: ForwardDeclared* = &f_ref.f;
  27. // CHECK:STDOUT: --- a.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %.1: type = interface_type @Empty [template]
  31. // CHECK:STDOUT: %.2: type = interface_type @Basic [template]
  32. // CHECK:STDOUT: %.3: type = assoc_entity_type @Basic, type [template]
  33. // CHECK:STDOUT: %.4: <associated type in Basic> = assoc_entity element0, @Basic.%T [template]
  34. // CHECK:STDOUT: %.5: type = assoc_entity_type @Basic, <function> [template]
  35. // CHECK:STDOUT: %.6: <associated <function> in Basic> = assoc_entity element1, @Basic.%F [template]
  36. // CHECK:STDOUT: %.7: type = interface_type @ForwardDeclared [template]
  37. // CHECK:STDOUT: %.8: type = assoc_entity_type @ForwardDeclared, type [template]
  38. // CHECK:STDOUT: %.9: <associated type in ForwardDeclared> = assoc_entity element0, @ForwardDeclared.%T [template]
  39. // CHECK:STDOUT: %.10: type = assoc_entity_type @ForwardDeclared, <function> [template]
  40. // CHECK:STDOUT: %.11: <associated <function> in ForwardDeclared> = assoc_entity element1, @ForwardDeclared.%F [template]
  41. // CHECK:STDOUT: %.12: type = struct_type {.f: ForwardDeclared} [template]
  42. // CHECK:STDOUT: %.13: type = tuple_type () [template]
  43. // CHECK:STDOUT: %.14: type = struct_type {.f: ()} [template]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  48. // CHECK:STDOUT: .Empty = %Empty.decl
  49. // CHECK:STDOUT: .Basic = %Basic.decl
  50. // CHECK:STDOUT: .ForwardDeclared = %ForwardDeclared.decl.loc12
  51. // CHECK:STDOUT: .f_ref = %f_ref
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Empty.decl = interface_decl @Empty [template = constants.%.1] {}
  54. // CHECK:STDOUT: %Basic.decl = interface_decl @Basic [template = constants.%.2] {}
  55. // CHECK:STDOUT: %ForwardDeclared.decl.loc12 = interface_decl @ForwardDeclared [template = constants.%.7] {}
  56. // CHECK:STDOUT: %ForwardDeclared.decl.loc14 = interface_decl @ForwardDeclared [template = constants.%.7] {}
  57. // CHECK:STDOUT: %ForwardDeclared.ref: type = name_ref ForwardDeclared, %ForwardDeclared.decl.loc12 [template = constants.%.7]
  58. // CHECK:STDOUT: %.loc19: type = struct_type {.f: ForwardDeclared} [template = constants.%.12]
  59. // CHECK:STDOUT: %f_ref.var: ref {.f: ForwardDeclared} = var f_ref
  60. // CHECK:STDOUT: %f_ref: ref {.f: ForwardDeclared} = bind_name f_ref, %f_ref.var
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: interface @Empty {
  64. // CHECK:STDOUT: !members:
  65. // CHECK:STDOUT: witness = ()
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: interface @Basic {
  69. // CHECK:STDOUT: %T: type = assoc_const_decl T [template]
  70. // CHECK:STDOUT: %.loc8: <associated type in Basic> = assoc_entity element0, %T [template = constants.%.4]
  71. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  72. // CHECK:STDOUT: %.loc9: <associated <function> in Basic> = assoc_entity element1, %F [template = constants.%.6]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .T = %.loc8
  76. // CHECK:STDOUT: .F = %.loc9
  77. // CHECK:STDOUT: witness = (%T, %F)
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: interface @ForwardDeclared {
  81. // CHECK:STDOUT: %T: type = assoc_const_decl T [template]
  82. // CHECK:STDOUT: %.loc15: <associated type in ForwardDeclared> = assoc_entity element0, %T [template = constants.%.9]
  83. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {}
  84. // CHECK:STDOUT: %.loc16: <associated <function> in ForwardDeclared> = assoc_entity element1, %F [template = constants.%.11]
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .T = %.loc15
  88. // CHECK:STDOUT: .F = %.loc16
  89. // CHECK:STDOUT: witness = (%T, %F)
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @F.1();
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @F.2();
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: --- b.carbon
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: constants {
  99. // CHECK:STDOUT: %.1: type = interface_type @Empty [template]
  100. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  101. // CHECK:STDOUT: %.3: type = interface_type @Basic [template]
  102. // CHECK:STDOUT: %.4: type = interface_type @ForwardDeclared [template]
  103. // CHECK:STDOUT: %.5: type = ptr_type ForwardDeclared [template]
  104. // CHECK:STDOUT: %.6: type = struct_type {.f: ForwardDeclared} [template]
  105. // CHECK:STDOUT: %.7: type = struct_type {.f: ()} [template]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: file {
  109. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  110. // CHECK:STDOUT: .Empty = %import_ref.1
  111. // CHECK:STDOUT: .Basic = %import_ref.2
  112. // CHECK:STDOUT: .ForwardDeclared = %import_ref.3
  113. // CHECK:STDOUT: .f_ref = %import_ref.4
  114. // CHECK:STDOUT: .UseEmpty = %UseEmpty
  115. // CHECK:STDOUT: .UseBasic = %UseBasic
  116. // CHECK:STDOUT: .UseForwardDeclared = %UseForwardDeclared
  117. // CHECK:STDOUT: .f = %f.loc10
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, used [template = constants.%.1]
  120. // CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+3, used [template = constants.%.3]
  121. // CHECK:STDOUT: %import_ref.3: type = import_ref ir1, inst+13, used [template = constants.%.4]
  122. // CHECK:STDOUT: %import_ref.4: ref {.f: ForwardDeclared} = import_ref ir1, inst+33, used
  123. // CHECK:STDOUT: %UseEmpty: <function> = fn_decl @UseEmpty [template] {
  124. // CHECK:STDOUT: %Empty.decl = interface_decl @Empty [template = constants.%.1] {}
  125. // CHECK:STDOUT: %Empty.ref: type = name_ref Empty, %import_ref.1 [template = constants.%.1]
  126. // CHECK:STDOUT: %e.loc6_13.1: Empty = param e
  127. // CHECK:STDOUT: @UseEmpty.%e: Empty = bind_name e, %e.loc6_13.1
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %UseBasic: <function> = fn_decl @UseBasic [template] {
  130. // CHECK:STDOUT: %Basic.decl = interface_decl @Basic [template = constants.%.3] {}
  131. // CHECK:STDOUT: %Basic.ref: type = name_ref Basic, %import_ref.2 [template = constants.%.3]
  132. // CHECK:STDOUT: %e.loc7_13.1: Basic = param e
  133. // CHECK:STDOUT: @UseBasic.%e: Basic = bind_name e, %e.loc7_13.1
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: %UseForwardDeclared: <function> = fn_decl @UseForwardDeclared [template] {
  136. // CHECK:STDOUT: %ForwardDeclared.decl = interface_decl @ForwardDeclared [template = constants.%.4] {}
  137. // CHECK:STDOUT: %ForwardDeclared.ref.loc8: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
  138. // CHECK:STDOUT: %f.loc8_23.1: ForwardDeclared = param f
  139. // CHECK:STDOUT: @UseForwardDeclared.%f: ForwardDeclared = bind_name f, %f.loc8_23.1
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %ForwardDeclared.ref.loc10: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
  142. // CHECK:STDOUT: %.loc10: type = ptr_type ForwardDeclared [template = constants.%.5]
  143. // CHECK:STDOUT: %f.var: ref ForwardDeclared* = var f
  144. // CHECK:STDOUT: %f.loc10: ref ForwardDeclared* = bind_name f, %f.var
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: interface @Empty {
  148. // CHECK:STDOUT: !members:
  149. // CHECK:STDOUT: witness = ()
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: interface @Basic {
  153. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+11, unused
  154. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+7, unused
  155. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+5, unused
  156. // CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+9, unused
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: !members:
  159. // CHECK:STDOUT: .F = %import_ref.1
  160. // CHECK:STDOUT: .T = %import_ref.2
  161. // CHECK:STDOUT: witness = (%import_ref.3, %import_ref.4)
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: interface @ForwardDeclared {
  165. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+22, unused
  166. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+18, unused
  167. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+16, unused
  168. // CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+20, unused
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: !members:
  171. // CHECK:STDOUT: .F = %import_ref.1
  172. // CHECK:STDOUT: .T = %import_ref.2
  173. // CHECK:STDOUT: witness = (%import_ref.3, %import_ref.4)
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: fn @UseEmpty(%e: Empty) {
  177. // CHECK:STDOUT: !entry:
  178. // CHECK:STDOUT: return
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: fn @UseBasic(%e: Basic) {
  182. // CHECK:STDOUT: !entry:
  183. // CHECK:STDOUT: return
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: fn @UseForwardDeclared(%f: ForwardDeclared) {
  187. // CHECK:STDOUT: !entry:
  188. // CHECK:STDOUT: return
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: fn @__global_init() {
  192. // CHECK:STDOUT: !entry:
  193. // CHECK:STDOUT: %f_ref.ref: ref {.f: ForwardDeclared} = name_ref f_ref, file.%import_ref.4
  194. // CHECK:STDOUT: %.loc10_33: ref ForwardDeclared = struct_access %f_ref.ref, element0
  195. // CHECK:STDOUT: %.loc10_27: ForwardDeclared* = addr_of %.loc10_33
  196. // CHECK:STDOUT: assign file.%f.var, %.loc10_27
  197. // CHECK:STDOUT: return
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT: