import.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: %int_32: Core.IntLiteral = int_value 32 [concrete]
  21. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  22. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  23. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  24. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  25. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.4f9(%int_32) [concrete]
  26. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  27. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  28. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%impl_witness.d39) [concrete]
  29. // CHECK:STDOUT: %.be7: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  30. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.956 [concrete]
  31. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  32. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  33. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  34. // CHECK:STDOUT: %ptr: type = ptr_type %i32 [concrete]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: imports {
  38. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  39. // CHECK:STDOUT: .Int = %Core.Int
  40. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  41. // CHECK:STDOUT: import Core//prelude
  42. // CHECK:STDOUT: import Core//prelude/...
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  48. // CHECK:STDOUT: .Core = imports.%Core
  49. // CHECK:STDOUT: .a_orig = %a_orig
  50. // CHECK:STDOUT: .a_ref = %a_ref
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Core.import = import Core
  53. // CHECK:STDOUT: name_binding_decl {
  54. // CHECK:STDOUT: %a_orig.patt: %i32 = binding_pattern a_orig
  55. // CHECK:STDOUT: %.loc4_1: %i32 = var_pattern %a_orig.patt
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %a_orig.var: ref %i32 = var a_orig
  58. // CHECK:STDOUT: %.loc4_13: type = splice_block %i32.loc4 [concrete = constants.%i32] {
  59. // CHECK:STDOUT: %int_32.loc4: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  60. // CHECK:STDOUT: %i32.loc4: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %a_orig: ref %i32 = bind_name a_orig, %a_orig.var
  63. // CHECK:STDOUT: name_binding_decl {
  64. // CHECK:STDOUT: %a_ref.patt: %ptr = binding_pattern a_ref
  65. // CHECK:STDOUT: %.loc5_1: %ptr = var_pattern %a_ref.patt
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %a_ref.var: ref %ptr = var a_ref
  68. // CHECK:STDOUT: %.loc5_15: type = splice_block %ptr [concrete = constants.%ptr] {
  69. // CHECK:STDOUT: %int_32.loc5: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  70. // CHECK:STDOUT: %i32.loc5: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  71. // CHECK:STDOUT: %ptr: type = ptr_type %i32 [concrete = constants.%ptr]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %a_ref: ref %ptr = bind_name a_ref, %a_ref.var
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @__global_init() {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  79. // CHECK:STDOUT: %impl.elem0: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  80. // CHECK:STDOUT: %bound_method.loc4_1.1: <bound method> = bound_method %int_0, %impl.elem0 [concrete = constants.%Convert.bound]
  81. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  82. // CHECK:STDOUT: %bound_method.loc4_1.2: <bound method> = bound_method %int_0, %specific_fn [concrete = constants.%bound_method]
  83. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc4_1.2(%int_0) [concrete = constants.%int_0.6a9]
  84. // CHECK:STDOUT: %.loc4: init %i32 = converted %int_0, %int.convert_checked [concrete = constants.%int_0.6a9]
  85. // CHECK:STDOUT: assign file.%a_orig.var, %.loc4
  86. // CHECK:STDOUT: %a_orig.ref: ref %i32 = name_ref a_orig, file.%a_orig
  87. // CHECK:STDOUT: %addr: %ptr = addr_of %a_orig.ref
  88. // CHECK:STDOUT: assign file.%a_ref.var, %addr
  89. // CHECK:STDOUT: return
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: --- implicit.impl.carbon
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: constants {
  95. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  96. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  97. // CHECK:STDOUT: %ptr: type = ptr_type %i32 [concrete]
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: imports {
  101. // CHECK:STDOUT: %Implicit.a_orig = import_ref Implicit//default, a_orig, unloaded
  102. // CHECK:STDOUT: %Implicit.a_ref: ref %ptr = import_ref Implicit//default, a_ref, loaded
  103. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  104. // CHECK:STDOUT: .Int = %Core.Int
  105. // CHECK:STDOUT: import Core//prelude
  106. // CHECK:STDOUT: import Core//prelude/...
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: file {
  111. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  112. // CHECK:STDOUT: .a_orig = imports.%Implicit.a_orig
  113. // CHECK:STDOUT: .a_ref = imports.%Implicit.a_ref
  114. // CHECK:STDOUT: .Core = imports.%Core
  115. // CHECK:STDOUT: .a = %a
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %Implicit.import = import Implicit
  118. // CHECK:STDOUT: %default.import = import <none>
  119. // CHECK:STDOUT: %Core.import = import Core
  120. // CHECK:STDOUT: name_binding_decl {
  121. // CHECK:STDOUT: %a.patt: %ptr = binding_pattern a
  122. // CHECK:STDOUT: %.loc4_1: %ptr = var_pattern %a.patt
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %a.var: ref %ptr = var a
  125. // CHECK:STDOUT: %.loc4_11: type = splice_block %ptr [concrete = constants.%ptr] {
  126. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  127. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  128. // CHECK:STDOUT: %ptr: type = ptr_type %i32 [concrete = constants.%ptr]
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %a: ref %ptr = bind_name a, %a.var
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: fn @__global_init() {
  134. // CHECK:STDOUT: !entry:
  135. // CHECK:STDOUT: %a_ref.ref: ref %ptr = name_ref a_ref, imports.%Implicit.a_ref
  136. // CHECK:STDOUT: %.loc4: %ptr = bind_value %a_ref.ref
  137. // CHECK:STDOUT: assign file.%a.var, %.loc4
  138. // CHECK:STDOUT: return
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: