imported.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/imported.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/imported.carbon
  10. // --- implicit.carbon
  11. package Implicit;
  12. namespace NS;
  13. namespace NS.ChildNS;
  14. fn NS.A();
  15. fn NS.ChildNS.B();
  16. // --- implicit.impl.carbon
  17. impl package Implicit;
  18. var a: () = NS.A();
  19. var b: () = NS.ChildNS.B();
  20. var package_a: () = package.NS.A();
  21. var package_b: () = package.NS.ChildNS.B();
  22. // CHECK:STDOUT: --- implicit.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  26. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  27. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  28. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  29. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: file {
  33. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  34. // CHECK:STDOUT: .Core = %Core
  35. // CHECK:STDOUT: .NS = %NS
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  38. // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .ChildNS = %ChildNS
  40. // CHECK:STDOUT: .A = %A.decl
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %ChildNS: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .B = %B.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {}
  46. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {}
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @A();
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @B();
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: --- implicit.impl.carbon
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: constants {
  56. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  57. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  58. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  59. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  60. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: file {
  64. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  65. // CHECK:STDOUT: .NS = %NS
  66. // CHECK:STDOUT: .Core = %Core
  67. // CHECK:STDOUT: .a = %a
  68. // CHECK:STDOUT: .b = %b
  69. // CHECK:STDOUT: .package_a = %package_a
  70. // CHECK:STDOUT: .package_b = %package_b
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %import_ref.1: <namespace> = import_ref ir0, inst+2, loaded
  73. // CHECK:STDOUT: %NS: <namespace> = namespace %import_ref.1, [template] {
  74. // CHECK:STDOUT: .ChildNS = %ChildNS
  75. // CHECK:STDOUT: .A = %import_ref.3
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %import_ref.2: <namespace> = import_ref ir0, inst+3, loaded
  78. // CHECK:STDOUT: %ChildNS: <namespace> = namespace %import_ref.2, [template] {
  79. // CHECK:STDOUT: .B = %import_ref.4
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %import_ref.3: %A.type = import_ref ir0, inst+4, loaded [template = constants.%A]
  82. // CHECK:STDOUT: %import_ref.4: %B.type = import_ref ir0, inst+8, loaded [template = constants.%B]
  83. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  84. // CHECK:STDOUT: %.loc4_9.1: %.1 = tuple_literal ()
  85. // CHECK:STDOUT: %.loc4_9.2: type = converted %.loc4_9.1, constants.%.1 [template = constants.%.1]
  86. // CHECK:STDOUT: %a.var: ref %.1 = var a
  87. // CHECK:STDOUT: %a: ref %.1 = bind_name a, %a.var
  88. // CHECK:STDOUT: %.loc5_9.1: %.1 = tuple_literal ()
  89. // CHECK:STDOUT: %.loc5_9.2: type = converted %.loc5_9.1, constants.%.1 [template = constants.%.1]
  90. // CHECK:STDOUT: %b.var: ref %.1 = var b
  91. // CHECK:STDOUT: %b: ref %.1 = bind_name b, %b.var
  92. // CHECK:STDOUT: %.loc7_17.1: %.1 = tuple_literal ()
  93. // CHECK:STDOUT: %.loc7_17.2: type = converted %.loc7_17.1, constants.%.1 [template = constants.%.1]
  94. // CHECK:STDOUT: %package_a.var: ref %.1 = var package_a
  95. // CHECK:STDOUT: %package_a: ref %.1 = bind_name package_a, %package_a.var
  96. // CHECK:STDOUT: %.loc8_17.1: %.1 = tuple_literal ()
  97. // CHECK:STDOUT: %.loc8_17.2: type = converted %.loc8_17.1, constants.%.1 [template = constants.%.1]
  98. // CHECK:STDOUT: %package_b.var: ref %.1 = var package_b
  99. // CHECK:STDOUT: %package_b: ref %.1 = bind_name package_b, %package_b.var
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @A();
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @B();
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: fn @__global_init() {
  107. // CHECK:STDOUT: !entry:
  108. // CHECK:STDOUT: %NS.ref.loc4: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  109. // CHECK:STDOUT: %A.ref.loc4: %A.type = name_ref A, file.%import_ref.3 [template = constants.%A]
  110. // CHECK:STDOUT: %A.call.loc4: init %.1 = call %A.ref.loc4()
  111. // CHECK:STDOUT: assign file.%a.var, %A.call.loc4
  112. // CHECK:STDOUT: %NS.ref.loc5: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  113. // CHECK:STDOUT: %ChildNS.ref.loc5: <namespace> = name_ref ChildNS, file.%ChildNS [template = file.%ChildNS]
  114. // CHECK:STDOUT: %B.ref.loc5: %B.type = name_ref B, file.%import_ref.4 [template = constants.%B]
  115. // CHECK:STDOUT: %B.call.loc5: init %.1 = call %B.ref.loc5()
  116. // CHECK:STDOUT: assign file.%b.var, %B.call.loc5
  117. // CHECK:STDOUT: %package.ref.loc7: <namespace> = name_ref package, package [template = package]
  118. // CHECK:STDOUT: %NS.ref.loc7: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  119. // CHECK:STDOUT: %A.ref.loc7: %A.type = name_ref A, file.%import_ref.3 [template = constants.%A]
  120. // CHECK:STDOUT: %A.call.loc7: init %.1 = call %A.ref.loc7()
  121. // CHECK:STDOUT: assign file.%package_a.var, %A.call.loc7
  122. // CHECK:STDOUT: %package.ref.loc8: <namespace> = name_ref package, package [template = package]
  123. // CHECK:STDOUT: %NS.ref.loc8: <namespace> = name_ref NS, file.%NS [template = file.%NS]
  124. // CHECK:STDOUT: %ChildNS.ref.loc8: <namespace> = name_ref ChildNS, file.%ChildNS [template = file.%ChildNS]
  125. // CHECK:STDOUT: %B.ref.loc8: %B.type = name_ref B, file.%import_ref.4 [template = constants.%B]
  126. // CHECK:STDOUT: %B.call.loc8: init %.1 = call %B.ref.loc8()
  127. // CHECK:STDOUT: assign file.%package_b.var, %B.call.loc8
  128. // CHECK:STDOUT: return
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: