merging.carbon 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 "a";
  12. namespace NS;
  13. fn NS.A() {}
  14. // --- b.carbon
  15. package Example library "b";
  16. namespace NS;
  17. fn NS.B1() {}
  18. namespace NS;
  19. fn NS.B2() {}
  20. // --- c.carbon
  21. package Example library "c";
  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: file {
  41. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  42. // CHECK:STDOUT: .Core = %Core
  43. // CHECK:STDOUT: .NS = %NS
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  46. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .A = %A.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: fn @A() {
  53. // CHECK:STDOUT: !entry:
  54. // CHECK:STDOUT: return
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: --- b.carbon
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: constants {
  60. // CHECK:STDOUT: %B1.type: type = fn_type @B1 [template]
  61. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  62. // CHECK:STDOUT: %B1: %B1.type = struct_value () [template]
  63. // CHECK:STDOUT: %B2.type: type = fn_type @B2 [template]
  64. // CHECK:STDOUT: %B2: %B2.type = struct_value () [template]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: file {
  68. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  69. // CHECK:STDOUT: .Core = %Core
  70. // CHECK:STDOUT: .NS = %NS
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  73. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  74. // CHECK:STDOUT: .B1 = %B1.decl
  75. // CHECK:STDOUT: .B2 = %B2.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %B1.decl: %B1.type = fn_decl @B1 [template = constants.%B1] {}
  78. // CHECK:STDOUT: %.loc8: <namespace> = namespace [template] {}
  79. // CHECK:STDOUT: %B2.decl: %B2.type = fn_decl @B2 [template = constants.%B2] {}
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @B1() {
  83. // CHECK:STDOUT: !entry:
  84. // CHECK:STDOUT: return
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: fn @B2() {
  88. // CHECK:STDOUT: !entry:
  89. // CHECK:STDOUT: return
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: --- c.carbon
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: constants {
  95. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  96. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  97. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  98. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  99. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  100. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  101. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  102. // CHECK:STDOUT: %B1.type: type = fn_type @B1 [template]
  103. // CHECK:STDOUT: %B1: %B1.type = struct_value () [template]
  104. // CHECK:STDOUT: %B2.type: type = fn_type @B2 [template]
  105. // CHECK:STDOUT: %B2: %B2.type = struct_value () [template]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: file {
  109. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  110. // CHECK:STDOUT: .NS = %NS
  111. // CHECK:STDOUT: .Core = %Core
  112. // CHECK:STDOUT: .Run = %Run.decl
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %import_ref.1: <namespace> = import_ref ir1, inst+2, loaded
  115. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.1, [template] {
  116. // CHECK:STDOUT: .A = %import_ref.2
  117. // CHECK:STDOUT: .B1 = %import_ref.3
  118. // CHECK:STDOUT: .B2 = %import_ref.4
  119. // CHECK:STDOUT: .C = %C.decl
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %import_ref.2: %A.type = import_ref ir1, inst+3, loaded [template = constants.%A]
  122. // CHECK:STDOUT: %import_ref.3: %B1.type = import_ref ir2, inst+3, loaded [template = constants.%B1]
  123. // CHECK:STDOUT: %import_ref.4: %B2.type = import_ref ir2, inst+9, loaded [template = constants.%B2]
  124. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  125. // CHECK:STDOUT: %.loc7: <namespace> = namespace [template] {}
  126. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {}
  127. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {}
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: fn @C() {
  131. // CHECK:STDOUT: !entry:
  132. // CHECK:STDOUT: return
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: fn @Run() {
  136. // CHECK:STDOUT: !entry:
  137. // CHECK:STDOUT: %NS.ref.loc12: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  138. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%import_ref.2 [template = constants.%A]
  139. // CHECK:STDOUT: %A.call: init %.1 = call %A.ref()
  140. // CHECK:STDOUT: %NS.ref.loc13: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  141. // CHECK:STDOUT: %B1.ref: %B1.type = name_ref B1, file.%import_ref.3 [template = constants.%B1]
  142. // CHECK:STDOUT: %B1.call: init %.1 = call %B1.ref()
  143. // CHECK:STDOUT: %NS.ref.loc14: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  144. // CHECK:STDOUT: %B2.ref: %B2.type = name_ref B2, file.%import_ref.4 [template = constants.%B2]
  145. // CHECK:STDOUT: %B2.call: init %.1 = call %B2.ref()
  146. // CHECK:STDOUT: %NS.ref.loc15: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  147. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [template = constants.%C]
  148. // CHECK:STDOUT: %C.call: init %.1 = call %C.ref()
  149. // CHECK:STDOUT: return
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: fn @A();
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: fn @B1();
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: fn @B2();
  157. // CHECK:STDOUT: