import.carbon 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 [template]
  21. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  22. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template]
  23. // CHECK:STDOUT: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  24. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  25. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  26. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  27. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.925 [template]
  28. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  29. // CHECK:STDOUT: %int_0.f61: %i32 = int_value 0 [template]
  30. // CHECK:STDOUT: %ptr: type = ptr_type %i32 [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  35. // CHECK:STDOUT: .Int = %import_ref.187
  36. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .a_orig = %a_orig
  46. // CHECK:STDOUT: .a_ref = %a_ref
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %a_orig.var: ref %i32 = var a_orig
  50. // CHECK:STDOUT: %a_orig: ref %i32 = bind_name a_orig, %a_orig.var
  51. // CHECK:STDOUT: %a_ref.var: ref %ptr = var a_ref
  52. // CHECK:STDOUT: %a_ref: ref %ptr = bind_name a_ref, %a_ref.var
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @__global_init() {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
  58. // CHECK:STDOUT: %impl.elem0: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  59. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound]
  60. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  61. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.f61]
  62. // CHECK:STDOUT: %.loc4: init %i32 = converted %int_0, %int.convert_checked [template = constants.%int_0.f61]
  63. // CHECK:STDOUT: assign file.%a_orig.var, %.loc4
  64. // CHECK:STDOUT: %a_orig.ref: ref %i32 = name_ref a_orig, file.%a_orig
  65. // CHECK:STDOUT: %addr: %ptr = addr_of %a_orig.ref
  66. // CHECK:STDOUT: assign file.%a_ref.var, %addr
  67. // CHECK:STDOUT: return
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: --- implicit.impl.carbon
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: constants {
  73. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  74. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  75. // CHECK:STDOUT: %ptr: type = ptr_type %i32 [template]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: imports {
  79. // CHECK:STDOUT: %import_ref.ae6 = import_ref Implicit//default, a_orig, unloaded
  80. // CHECK:STDOUT: %import_ref.b22: ref %ptr = import_ref Implicit//default, a_ref, loaded
  81. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  82. // CHECK:STDOUT: .Int = %import_ref.d69
  83. // CHECK:STDOUT: import Core//prelude
  84. // CHECK:STDOUT: import Core//prelude/...
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: file {
  89. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  90. // CHECK:STDOUT: .a_orig = imports.%import_ref.ae6
  91. // CHECK:STDOUT: .a_ref = imports.%import_ref.b22
  92. // CHECK:STDOUT: .Core = imports.%Core
  93. // CHECK:STDOUT: .a = %a
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %Implicit.import = import Implicit
  96. // CHECK:STDOUT: %default.import = import <invalid>
  97. // CHECK:STDOUT: %Core.import = import Core
  98. // CHECK:STDOUT: %a.var: ref %ptr = var a
  99. // CHECK:STDOUT: %a: ref %ptr = bind_name a, %a.var
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @__global_init() {
  103. // CHECK:STDOUT: !entry:
  104. // CHECK:STDOUT: %a_ref.ref: ref %ptr = name_ref a_ref, imports.%import_ref.b22
  105. // CHECK:STDOUT: %.loc4: %ptr = bind_value %a_ref.ref
  106. // CHECK:STDOUT: assign file.%a.var, %.loc4
  107. // CHECK:STDOUT: return
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: