Files
carbon-lang/toolchain/check/import.h
T
Jon Ross-Perkins 8567e02aa7 Refactor handling of cross-package imports. (#3783)
This revamps the support for cross-package imports, making them look
more like a namespace. The planned model is mentioned on
[#toolchain](https://discord.com/channels/655572317891461132/655578254970716160/1217586076022210670).
This does not implement name lookup into the new namespace structure.

A few key changes in this PR (it's a little sprawling) are:

- Moves logic for adding package imports from context.* to import.*
- Remove SemIR::Import, which was the prior model. This is instead now a
SemIR::Namespace with the NameScope getting a new import_ir_scopes
field.
- Allow SemIR::Namespace to use Parse::ImportDirectiveId in addition to
the prior Parse::NamespaceId
- The import_ir_scopes field includes a NameScopeId so that as we
traverse to child namespaces, we can directly perform name lookup in the
other IR.
- is_closed_import now tracks whether a namespace comes from a different
package. This has a diagnostic implemented in decl_name_stack.
2024-03-14 22:03:30 +00:00

37 lines
1.6 KiB
C++

// 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
#ifndef CARBON_TOOLCHAIN_CHECK_IMPORT_H_
#define CARBON_TOOLCHAIN_CHECK_IMPORT_H_
#include "toolchain/check/context.h"
#include "toolchain/sem_ir/file.h"
namespace Carbon::Check {
// Add imports from a single library in the current package. This pulls in all
// names; conflicts for things such as `package.a.b.c` will be flagged even
// though they are several layers deep.
auto ImportLibraryFromCurrentPackage(Context& context,
SemIR::TypeId namespace_type_id,
const SemIR::File& import_sem_ir) -> void;
// Adds another package's imports to name lookup, with all libraries together.
// This only adds the package name to lookup, so that `package.ImportedPackage`
// will resolve, and will provide a name scope that can be used for further
// qualified name lookups.
//
// sem_irs will all be non-null, and may be empty. has_load_error is used to
// indicate if any library in the package failed to import correctly.
auto ImportLibrariesFromOtherPackage(Context& context,
SemIR::TypeId namespace_type_id,
Parse::ImportDirectiveId node_id,
IdentifierId package_id,
llvm::ArrayRef<const SemIR::File*> sem_irs,
bool has_load_error) -> void;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_IMPORT_H_