import.carbon 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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: type = interface_decl @Empty [template = constants.%.1] {}
  54. // CHECK:STDOUT: %Basic.decl: type = interface_decl @Basic [template = constants.%.2] {}
  55. // CHECK:STDOUT: %ForwardDeclared.decl.loc12: type = interface_decl @ForwardDeclared [template = constants.%.7] {}
  56. // CHECK:STDOUT: %ForwardDeclared.decl.loc14: type = 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: %Self: Empty = bind_symbolic_name Self [symbolic]
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: !members:
  67. // CHECK:STDOUT: .Self = %Self
  68. // CHECK:STDOUT: witness = ()
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: interface @Basic {
  72. // CHECK:STDOUT: %Self: Basic = bind_symbolic_name Self [symbolic]
  73. // CHECK:STDOUT: %T: type = assoc_const_decl T [template]
  74. // CHECK:STDOUT: %.loc8: <associated type in Basic> = assoc_entity element0, %T [template = constants.%.4]
  75. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  76. // CHECK:STDOUT: %.loc9: <associated <function> in Basic> = assoc_entity element1, %F [template = constants.%.6]
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: !members:
  79. // CHECK:STDOUT: .Self = %Self
  80. // CHECK:STDOUT: .T = %.loc8
  81. // CHECK:STDOUT: .F = %.loc9
  82. // CHECK:STDOUT: witness = (%T, %F)
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: interface @ForwardDeclared {
  86. // CHECK:STDOUT: %Self: ForwardDeclared = bind_symbolic_name Self [symbolic]
  87. // CHECK:STDOUT: %T: type = assoc_const_decl T [template]
  88. // CHECK:STDOUT: %.loc15: <associated type in ForwardDeclared> = assoc_entity element0, %T [template = constants.%.9]
  89. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {}
  90. // CHECK:STDOUT: %.loc16: <associated <function> in ForwardDeclared> = assoc_entity element1, %F [template = constants.%.11]
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: !members:
  93. // CHECK:STDOUT: .Self = %Self
  94. // CHECK:STDOUT: .T = %.loc15
  95. // CHECK:STDOUT: .F = %.loc16
  96. // CHECK:STDOUT: witness = (%T, %F)
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @F.1();
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn @F.2();
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: --- b.carbon
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: constants {
  106. // CHECK:STDOUT: %.1: type = interface_type @Empty [template]
  107. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  108. // CHECK:STDOUT: %.3: type = interface_type @Basic [template]
  109. // CHECK:STDOUT: %.4: type = interface_type @ForwardDeclared [template]
  110. // CHECK:STDOUT: %.5: type = ptr_type ForwardDeclared [template]
  111. // CHECK:STDOUT: %.6: type = struct_type {.f: ForwardDeclared} [template]
  112. // CHECK:STDOUT: %.7: type = struct_type {.f: ()} [template]
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: file {
  116. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  117. // CHECK:STDOUT: .Empty = %import_ref.1
  118. // CHECK:STDOUT: .Basic = %import_ref.2
  119. // CHECK:STDOUT: .ForwardDeclared = %import_ref.3
  120. // CHECK:STDOUT: .f_ref = %import_ref.4
  121. // CHECK:STDOUT: .UseEmpty = %UseEmpty
  122. // CHECK:STDOUT: .UseBasic = %UseBasic
  123. // CHECK:STDOUT: .UseForwardDeclared = %UseForwardDeclared
  124. // CHECK:STDOUT: .f = %f.loc10
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, used [template = constants.%.1]
  127. // CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+4, used [template = constants.%.3]
  128. // CHECK:STDOUT: %import_ref.3: type = import_ref ir1, inst+15, used [template = constants.%.4]
  129. // CHECK:STDOUT: %import_ref.4: ref {.f: ForwardDeclared} = import_ref ir1, inst+36, used
  130. // CHECK:STDOUT: %UseEmpty: <function> = fn_decl @UseEmpty [template] {
  131. // CHECK:STDOUT: %Empty.decl: invalid = interface_decl @Empty [template = constants.%.1] {}
  132. // CHECK:STDOUT: %Empty.ref: type = name_ref Empty, %import_ref.1 [template = constants.%.1]
  133. // CHECK:STDOUT: %e.loc6_13.1: Empty = param e
  134. // CHECK:STDOUT: @UseEmpty.%e: Empty = bind_name e, %e.loc6_13.1
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %UseBasic: <function> = fn_decl @UseBasic [template] {
  137. // CHECK:STDOUT: %Basic.decl: invalid = interface_decl @Basic [template = constants.%.3] {}
  138. // CHECK:STDOUT: %Basic.ref: type = name_ref Basic, %import_ref.2 [template = constants.%.3]
  139. // CHECK:STDOUT: %e.loc7_13.1: Basic = param e
  140. // CHECK:STDOUT: @UseBasic.%e: Basic = bind_name e, %e.loc7_13.1
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: %UseForwardDeclared: <function> = fn_decl @UseForwardDeclared [template] {
  143. // CHECK:STDOUT: %ForwardDeclared.decl: invalid = interface_decl @ForwardDeclared [template = constants.%.4] {}
  144. // CHECK:STDOUT: %ForwardDeclared.ref.loc8: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
  145. // CHECK:STDOUT: %f.loc8_23.1: ForwardDeclared = param f
  146. // CHECK:STDOUT: @UseForwardDeclared.%f: ForwardDeclared = bind_name f, %f.loc8_23.1
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: %ForwardDeclared.ref.loc10: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
  149. // CHECK:STDOUT: %.loc10: type = ptr_type ForwardDeclared [template = constants.%.5]
  150. // CHECK:STDOUT: %f.var: ref ForwardDeclared* = var f
  151. // CHECK:STDOUT: %f.loc10: ref ForwardDeclared* = bind_name f, %f.var
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: interface @Empty {
  155. // CHECK:STDOUT: %import_ref = import_ref ir1, inst+3, unused
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: !members:
  158. // CHECK:STDOUT: .Self = %import_ref
  159. // CHECK:STDOUT: witness = ()
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: interface @Basic {
  163. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+6, unused
  164. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+13, unused
  165. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+9, unused
  166. // CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+7, unused
  167. // CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+11, unused
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: !members:
  170. // CHECK:STDOUT: .Self = %import_ref.1
  171. // CHECK:STDOUT: .F = %import_ref.2
  172. // CHECK:STDOUT: .T = %import_ref.3
  173. // CHECK:STDOUT: witness = (%import_ref.4, %import_ref.5)
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: interface @ForwardDeclared {
  177. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+18, unused
  178. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+25, unused
  179. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+21, unused
  180. // CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+19, unused
  181. // CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+23, unused
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: !members:
  184. // CHECK:STDOUT: .Self = %import_ref.1
  185. // CHECK:STDOUT: .F = %import_ref.2
  186. // CHECK:STDOUT: .T = %import_ref.3
  187. // CHECK:STDOUT: witness = (%import_ref.4, %import_ref.5)
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: fn @UseEmpty(%e: Empty) {
  191. // CHECK:STDOUT: !entry:
  192. // CHECK:STDOUT: return
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: fn @UseBasic(%e: Basic) {
  196. // CHECK:STDOUT: !entry:
  197. // CHECK:STDOUT: return
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: fn @UseForwardDeclared(%f: ForwardDeclared) {
  201. // CHECK:STDOUT: !entry:
  202. // CHECK:STDOUT: return
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: fn @__global_init() {
  206. // CHECK:STDOUT: !entry:
  207. // CHECK:STDOUT: %f_ref.ref: ref {.f: ForwardDeclared} = name_ref f_ref, file.%import_ref.4
  208. // CHECK:STDOUT: %.loc10_33: ref ForwardDeclared = struct_access %f_ref.ref, element0
  209. // CHECK:STDOUT: %.loc10_27: ForwardDeclared* = addr_of %.loc10_33
  210. // CHECK:STDOUT: assign file.%f.var, %.loc10_27
  211. // CHECK:STDOUT: return
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT: