implicit_imports_prelude.carbon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // This is just checking an implicit import behavior with the prelude present.
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/packages/implicit_imports_prelude.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/packages/implicit_imports_prelude.carbon
  12. // --- lib.carbon
  13. library "[[@TEST_NAME]]";
  14. var a: i32 = 0;
  15. // --- lib.impl.carbon
  16. impl library "[[@TEST_NAME]]";
  17. var b: i32 = a;
  18. // CHECK:STDOUT: --- lib.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  22. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  23. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  24. // CHECK:STDOUT: %.2: i32 = int_literal 0 [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/...
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: file {
  37. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  38. // CHECK:STDOUT: .Core = imports.%Core
  39. // CHECK:STDOUT: .a = %a
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core.import = import Core
  42. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  43. // CHECK:STDOUT: %.loc4_8.1: type = value_of_initializer %int.make_type_32 [template = i32]
  44. // CHECK:STDOUT: %.loc4_8.2: type = converted %int.make_type_32, %.loc4_8.1 [template = i32]
  45. // CHECK:STDOUT: %a.var: ref i32 = var a
  46. // CHECK:STDOUT: %a: ref i32 = bind_name a, %a.var
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @__global_init() {
  52. // CHECK:STDOUT: !entry:
  53. // CHECK:STDOUT: %.loc4: i32 = int_literal 0 [template = constants.%.2]
  54. // CHECK:STDOUT: assign file.%a.var, %.loc4
  55. // CHECK:STDOUT: return
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: --- lib.impl.carbon
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: constants {
  61. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  62. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  63. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: imports {
  67. // CHECK:STDOUT: %import_ref.1: ref i32 = import_ref Main//lib, inst+15, loaded
  68. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  69. // CHECK:STDOUT: .Int32 = %import_ref.2
  70. // CHECK:STDOUT: import Core//prelude
  71. // CHECK:STDOUT: import Core//prelude/...
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: file {
  77. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  78. // CHECK:STDOUT: .a = imports.%import_ref.1
  79. // CHECK:STDOUT: .Core = imports.%Core
  80. // CHECK:STDOUT: .b = %b
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %default.import.loc2_6.1 = import <invalid>
  83. // CHECK:STDOUT: %default.import.loc2_6.2 = import <invalid>
  84. // CHECK:STDOUT: %Core.import = import Core
  85. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  86. // CHECK:STDOUT: %.loc4_8.1: type = value_of_initializer %int.make_type_32 [template = i32]
  87. // CHECK:STDOUT: %.loc4_8.2: type = converted %int.make_type_32, %.loc4_8.1 [template = i32]
  88. // CHECK:STDOUT: %b.var: ref i32 = var b
  89. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @__global_init() {
  95. // CHECK:STDOUT: !entry:
  96. // CHECK:STDOUT: %a.ref: ref i32 = name_ref a, imports.%import_ref.1
  97. // CHECK:STDOUT: %.loc4: i32 = bind_value %a.ref
  98. // CHECK:STDOUT: assign file.%b.var, %.loc4
  99. // CHECK:STDOUT: return
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: