Files
carbon-lang/toolchain/check/import.h
T
Jon Ross-Perkins c82ce8faae Start adding tracking of the complete list of IRs under check. (#3915)
As we talk about how imports should work, we want to start having
indirectly imported IRs in `import_irs`, where it's currently only
directly imported IRs. The tracking of `CheckIRId` is set up to be able
to determine whether an IR being indirectly imported is actually already
tracked (and may be a direct import). Changes here to how ApiForImpl is
handled start using the logic.

Note that indirect imports may be added while processing even the first
import from the current library. As a consequence, it's necessary to
prepare this map before starting imports, in particular, setting
ApiForImpl before any indirect imports may encounter the same import.
Also, prior validation that `num_irs` matches the final size are no
longer relevant.

check_ir_id is tracked on SemIR because I want to be able to figure it
out given an ImportIR, but the mapping is ephemeral after checking and
so I store that in Context.

I'm putting relevant logic into import_ref.cpp because the primary
alternative is import.cpp, and as more logic is added, ImportRefResolver
will be adding import IRs.
2024-04-29 19:08:50 +00:00

39 lines
1.7 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/parse/node_ids.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,
Parse::ImportDirectiveId node_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.
//
// import_irs 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<SemIR::ImportIR> import_irs,
bool has_load_error) -> void;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_IMPORT_H_