merging.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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/namespace/merging.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/merging.carbon
  10. // --- a.carbon
  11. package Example library "[[@TEST_NAME]]";
  12. namespace NS;
  13. fn NS.A() {}
  14. // --- b.carbon
  15. package Example library "[[@TEST_NAME]]";
  16. namespace NS;
  17. fn NS.B1() {}
  18. namespace NS;
  19. fn NS.B2() {}
  20. // --- c.carbon
  21. package Example library "[[@TEST_NAME]]";
  22. import library "a";
  23. import library "b";
  24. namespace NS;
  25. fn NS.C() {}
  26. fn Run() {
  27. NS.A();
  28. NS.B1();
  29. NS.B2();
  30. NS.C();
  31. }
  32. // CHECK:STDOUT: --- a.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  36. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  37. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: imports {
  41. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/operators
  44. // CHECK:STDOUT: import Core//prelude/types
  45. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  46. // CHECK:STDOUT: import Core//prelude/operators/as
  47. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  48. // CHECK:STDOUT: import Core//prelude/operators/comparison
  49. // CHECK:STDOUT: import Core//prelude/types/bool
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .NS = %NS
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  60. // CHECK:STDOUT: .A = %A.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {} {}
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @A() {
  66. // CHECK:STDOUT: !entry:
  67. // CHECK:STDOUT: return
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: --- b.carbon
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: constants {
  73. // CHECK:STDOUT: %B1.type: type = fn_type @B1 [template]
  74. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  75. // CHECK:STDOUT: %B1: %B1.type = struct_value () [template]
  76. // CHECK:STDOUT: %B2.type: type = fn_type @B2 [template]
  77. // CHECK:STDOUT: %B2: %B2.type = struct_value () [template]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: imports {
  81. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  82. // CHECK:STDOUT: import Core//prelude
  83. // CHECK:STDOUT: import Core//prelude/operators
  84. // CHECK:STDOUT: import Core//prelude/types
  85. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  86. // CHECK:STDOUT: import Core//prelude/operators/as
  87. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  88. // CHECK:STDOUT: import Core//prelude/operators/comparison
  89. // CHECK:STDOUT: import Core//prelude/types/bool
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: file {
  94. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  95. // CHECK:STDOUT: .Core = imports.%Core
  96. // CHECK:STDOUT: .NS = %NS.loc4
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %Core.import = import Core
  99. // CHECK:STDOUT: %NS.loc4: <namespace> = namespace [template] {
  100. // CHECK:STDOUT: .B1 = %B1.decl
  101. // CHECK:STDOUT: .B2 = %B2.decl
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %B1.decl: %B1.type = fn_decl @B1 [template = constants.%B1] {} {}
  104. // CHECK:STDOUT: %NS.loc8: <namespace> = namespace [template] {
  105. // CHECK:STDOUT: .B1 = %B1.decl
  106. // CHECK:STDOUT: .B2 = %B2.decl
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %B2.decl: %B2.type = fn_decl @B2 [template = constants.%B2] {} {}
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: fn @B1() {
  112. // CHECK:STDOUT: !entry:
  113. // CHECK:STDOUT: return
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn @B2() {
  117. // CHECK:STDOUT: !entry:
  118. // CHECK:STDOUT: return
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: --- c.carbon
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: constants {
  124. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  125. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  126. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  127. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  128. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  129. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  130. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  131. // CHECK:STDOUT: %B1.type: type = fn_type @B1 [template]
  132. // CHECK:STDOUT: %B1: %B1.type = struct_value () [template]
  133. // CHECK:STDOUT: %B2.type: type = fn_type @B2 [template]
  134. // CHECK:STDOUT: %B2: %B2.type = struct_value () [template]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: imports {
  138. // CHECK:STDOUT: %import_ref.1: <namespace> = import_ref Example//a, inst+3, loaded
  139. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.1, [template] {
  140. // CHECK:STDOUT: .A = %import_ref.2
  141. // CHECK:STDOUT: .B1 = %import_ref.3
  142. // CHECK:STDOUT: .B2 = %import_ref.4
  143. // CHECK:STDOUT: .C = file.%C.decl
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT: %import_ref.2: %A.type = import_ref Example//a, inst+4, loaded [template = constants.%A]
  146. // CHECK:STDOUT: %import_ref.3: %B1.type = import_ref Example//b, inst+4, loaded [template = constants.%B1]
  147. // CHECK:STDOUT: %import_ref.4: %B2.type = import_ref Example//b, inst+10, loaded [template = constants.%B2]
  148. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  149. // CHECK:STDOUT: import Core//prelude
  150. // CHECK:STDOUT: import Core//prelude/operators
  151. // CHECK:STDOUT: import Core//prelude/types
  152. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  153. // CHECK:STDOUT: import Core//prelude/operators/as
  154. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  155. // CHECK:STDOUT: import Core//prelude/operators/comparison
  156. // CHECK:STDOUT: import Core//prelude/types/bool
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: file {
  161. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  162. // CHECK:STDOUT: .NS = imports.%NS
  163. // CHECK:STDOUT: .Core = imports.%Core
  164. // CHECK:STDOUT: .Run = %Run.decl
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT: %Core.import = import Core
  167. // CHECK:STDOUT: %default.import = import <invalid>
  168. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  169. // CHECK:STDOUT: .A = imports.%import_ref.2
  170. // CHECK:STDOUT: .B1 = imports.%import_ref.3
  171. // CHECK:STDOUT: .B2 = imports.%import_ref.4
  172. // CHECK:STDOUT: .C = %C.decl
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {} {}
  175. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {} {}
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: fn @C() {
  179. // CHECK:STDOUT: !entry:
  180. // CHECK:STDOUT: return
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: fn @Run() {
  184. // CHECK:STDOUT: !entry:
  185. // CHECK:STDOUT: %NS.ref.loc12: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  186. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, imports.%import_ref.2 [template = constants.%A]
  187. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  188. // CHECK:STDOUT: %NS.ref.loc13: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  189. // CHECK:STDOUT: %B1.ref: %B1.type = name_ref B1, imports.%import_ref.3 [template = constants.%B1]
  190. // CHECK:STDOUT: %B1.call: init %.1 = call %B1.ref()
  191. // CHECK:STDOUT: %NS.ref.loc14: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  192. // CHECK:STDOUT: %B2.ref: %B2.type = name_ref B2, imports.%import_ref.4 [template = constants.%B2]
  193. // CHECK:STDOUT: %B2.call: init %.1 = call %B2.ref()
  194. // CHECK:STDOUT: %NS.ref.loc15: <namespace> = name_ref NS, imports.%NS [template = imports.%NS]
  195. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [template = constants.%C]
  196. // CHECK:STDOUT: %C.call: init %.1 = call %C.ref()
  197. // CHECK:STDOUT: return
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: fn @A();
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: fn @B1();
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: fn @B2();
  205. // CHECK:STDOUT: