mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 08:45:54 +01:00
This implements a few closely related features: - Starts merging namespaces discovered inside imports. - Stores results of cross-package name lookup as an entry inside the scope. - Note this is particularly visible with `i32`. - Moves more of the imported instructions to the import scope. Note this is primarily for executing the namespace TODO in check.cpp, which is removed here. `testdata/namespace/merging_with_indirections.carbon` tests key behavior. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
82 lines
3.1 KiB
Plaintext
82 lines
3.1 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/namespace/function.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/function.carbon
|
|
|
|
namespace Foo;
|
|
|
|
// Never called, just here to help catch bugs in name lookup.
|
|
fn Baz() {
|
|
}
|
|
|
|
fn Foo.Baz() {
|
|
}
|
|
|
|
fn Bar() {
|
|
Foo.Baz();
|
|
}
|
|
|
|
// CHECK:STDOUT: --- function.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %Baz.type.1: type = fn_type @Baz.1 [template]
|
|
// CHECK:STDOUT: %.1: type = tuple_type () [template]
|
|
// CHECK:STDOUT: %Baz.1: %Baz.type.1 = struct_value () [template]
|
|
// CHECK:STDOUT: %Baz.type.2: type = fn_type @Baz.2 [template]
|
|
// CHECK:STDOUT: %Baz.2: %Baz.type.2 = struct_value () [template]
|
|
// CHECK:STDOUT: %Bar.type: type = fn_type @Bar [template]
|
|
// CHECK:STDOUT: %Bar: %Bar.type = struct_value () [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/operators
|
|
// CHECK:STDOUT: import Core//prelude/types
|
|
// CHECK:STDOUT: import Core//prelude/operators/arithmetic
|
|
// CHECK:STDOUT: import Core//prelude/operators/bitwise
|
|
// CHECK:STDOUT: import Core//prelude/operators/comparison
|
|
// CHECK:STDOUT: import Core//prelude/types/bool
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .Foo = %Foo
|
|
// CHECK:STDOUT: .Baz = %Baz.decl.loc14
|
|
// CHECK:STDOUT: .Bar = %Bar.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %Foo: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Baz = %Baz.decl.loc17
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Baz.decl.loc14: %Baz.type.1 = fn_decl @Baz.1 [template = constants.%Baz.1] {}
|
|
// CHECK:STDOUT: %Baz.decl.loc17: %Baz.type.2 = fn_decl @Baz.2 [template = constants.%Baz.2] {}
|
|
// CHECK:STDOUT: %Bar.decl: %Bar.type = fn_decl @Bar [template = constants.%Bar] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Baz.1() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Baz.2() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Bar() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %Foo.ref: <namespace> = name_ref Foo, file.%Foo [template = file.%Foo]
|
|
// CHECK:STDOUT: %Baz.ref: %Baz.type.2 = name_ref Baz, file.%Baz.decl.loc17 [template = constants.%Baz.2]
|
|
// CHECK:STDOUT: %Baz.call: init %.1 = call %Baz.ref()
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|