import.carbon 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/pointer/import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/import.carbon
  10. // --- implicit.carbon
  11. package Implicit;
  12. var a_orig: i32 = 0;
  13. var a_ref: i32* = &a_orig;
  14. // --- implicit.impl.carbon
  15. impl package Implicit;
  16. var a: i32* = a_ref;
  17. // CHECK:STDOUT: --- implicit.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  23. // CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
  24. // CHECK:STDOUT: %.3: type = ptr_type i32 [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  29. // CHECK:STDOUT: .Int32 = %import_ref
  30. // CHECK:STDOUT: import Core//prelude
  31. // CHECK:STDOUT: import Core//prelude/operators
  32. // CHECK:STDOUT: import Core//prelude/types
  33. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  34. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  35. // CHECK:STDOUT: import Core//prelude/operators/comparison
  36. // CHECK:STDOUT: import Core//prelude/types/bool
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .a_orig = %a_orig
  45. // CHECK:STDOUT: .a_ref = %a_ref
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %int.make_type_32.loc4: init type = call constants.%Int32() [template = i32]
  49. // CHECK:STDOUT: %.loc4_13.1: type = value_of_initializer %int.make_type_32.loc4 [template = i32]
  50. // CHECK:STDOUT: %.loc4_13.2: type = converted %int.make_type_32.loc4, %.loc4_13.1 [template = i32]
  51. // CHECK:STDOUT: %a_orig.var: ref i32 = var a_orig
  52. // CHECK:STDOUT: %a_orig: ref i32 = bind_name a_orig, %a_orig.var
  53. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  54. // CHECK:STDOUT: %.loc5_15.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  55. // CHECK:STDOUT: %.loc5_15.2: type = converted %int.make_type_32.loc5, %.loc5_15.1 [template = i32]
  56. // CHECK:STDOUT: %.loc5_15.3: type = ptr_type i32 [template = constants.%.3]
  57. // CHECK:STDOUT: %a_ref.var: ref %.3 = var a_ref
  58. // CHECK:STDOUT: %a_ref: ref %.3 = bind_name a_ref, %a_ref.var
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @__global_init() {
  64. // CHECK:STDOUT: !entry:
  65. // CHECK:STDOUT: %.loc4: i32 = int_literal 0 [template = constants.%.2]
  66. // CHECK:STDOUT: assign file.%a_orig.var, %.loc4
  67. // CHECK:STDOUT: %a_orig.ref: ref i32 = name_ref a_orig, file.%a_orig
  68. // CHECK:STDOUT: %.loc5: %.3 = addr_of %a_orig.ref
  69. // CHECK:STDOUT: assign file.%a_ref.var, %.loc5
  70. // CHECK:STDOUT: return
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: --- implicit.impl.carbon
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: constants {
  76. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  77. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  78. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  79. // CHECK:STDOUT: %.2: type = ptr_type i32 [template]
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: imports {
  83. // CHECK:STDOUT: %import_ref.1 = import_ref Implicit//default, inst+13, unloaded
  84. // CHECK:STDOUT: %import_ref.2: ref %.2 = import_ref Implicit//default, inst+23, loaded
  85. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  86. // CHECK:STDOUT: .Int32 = %import_ref.3
  87. // CHECK:STDOUT: import Core//prelude
  88. // CHECK:STDOUT: import Core//prelude/operators
  89. // CHECK:STDOUT: import Core//prelude/types
  90. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  91. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  92. // CHECK:STDOUT: import Core//prelude/operators/comparison
  93. // CHECK:STDOUT: import Core//prelude/types/bool
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: file {
  99. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  100. // CHECK:STDOUT: .a_orig = imports.%import_ref.1
  101. // CHECK:STDOUT: .a_ref = imports.%import_ref.2
  102. // CHECK:STDOUT: .Core = imports.%Core
  103. // CHECK:STDOUT: .a = %a
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: %Implicit.import = import Implicit
  106. // CHECK:STDOUT: %default.import = import <invalid>
  107. // CHECK:STDOUT: %Core.import = import Core
  108. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  109. // CHECK:STDOUT: %.loc4_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  110. // CHECK:STDOUT: %.loc4_11.2: type = converted %int.make_type_32, %.loc4_11.1 [template = i32]
  111. // CHECK:STDOUT: %.loc4_11.3: type = ptr_type i32 [template = constants.%.2]
  112. // CHECK:STDOUT: %a.var: ref %.2 = var a
  113. // CHECK:STDOUT: %a: ref %.2 = bind_name a, %a.var
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: fn @__global_init() {
  119. // CHECK:STDOUT: !entry:
  120. // CHECK:STDOUT: %a_ref.ref: ref %.2 = name_ref a_ref, imports.%import_ref.2
  121. // CHECK:STDOUT: %.loc4: %.2 = bind_value %a_ref.ref
  122. // CHECK:STDOUT: assign file.%a.var, %.loc4
  123. // CHECK:STDOUT: return
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: