mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:54:47 +01:00
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.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "toolchain/base/value_store.h"
|
||||
#include "toolchain/lex/tokenized_buffer.h"
|
||||
#include "toolchain/parse/context.h"
|
||||
#include "toolchain/parse/node_ids.h"
|
||||
#include "toolchain/parse/node_kind.h"
|
||||
|
||||
namespace Carbon::Parse {
|
||||
@@ -75,7 +76,8 @@ static auto HandleDirectiveContent(Context& context,
|
||||
NodeKind directive,
|
||||
llvm::function_ref<void()> on_parse_error)
|
||||
-> void {
|
||||
Tree::PackagingNames names{.node = NodeId(state.subtree_start)};
|
||||
Tree::PackagingNames names{
|
||||
.node_id = ImportDirectiveId(NodeId(state.subtree_start))};
|
||||
if (directive != NodeKind::LibraryDirective) {
|
||||
if (auto package_name_token =
|
||||
context.ConsumeIf(Lex::TokenKind::Identifier)) {
|
||||
|
||||
@@ -91,6 +91,7 @@ using AnyFunctionDeclId =
|
||||
using AnyImplDeclId = NodeIdOneOf<ImplDeclId, ImplDefinitionStartId>;
|
||||
using AnyInterfaceDeclId =
|
||||
NodeIdOneOf<InterfaceDeclId, InterfaceDefinitionStartId>;
|
||||
using AnyNamespaceId = NodeIdOneOf<NamespaceId, ImportDirectiveId>;
|
||||
|
||||
// NodeId with kind that is anything but T::Kind.
|
||||
template <typename T>
|
||||
|
||||
@@ -57,7 +57,7 @@ class Tree : public Printable<Tree> {
|
||||
// Names in packaging, whether the file's packaging or an import. Links back
|
||||
// to the node for diagnostics.
|
||||
struct PackagingNames {
|
||||
NodeId node;
|
||||
ImportDirectiveId node_id;
|
||||
IdentifierId package_id = IdentifierId::Invalid;
|
||||
StringLiteralValueId library_id = StringLiteralValueId::Invalid;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user