Implement merging of conflicts found during import. (#3819)

Note we only identify conflicts between libraries in the current package
during import.

This restructures the BUILD because of dependency cycles between cpp
files... We're going to need context's name lookup to handle things such
as merging, merging requires function logic, function logic requires
context access. Per discussion, going with a single large cc_library for
now rather than trying to split out small libraries.

I'm envisioning the new merge.* as a hub for cross-declaration merge
logic. Note function.cpp is already pretty sizable, and I think it may
lean a little function-specific even if there are some utilities that
could be split out.
This commit is contained in:
Jon Ross-Perkins
2024-03-27 23:38:10 +00:00
committed by GitHub
parent 1c673041f0
commit 0001f53ec1
12 changed files with 245 additions and 249 deletions
+2 -5
View File
@@ -6,6 +6,7 @@
#include "common/check.h"
#include "toolchain/check/context.h"
#include "toolchain/check/merge.h"
#include "toolchain/parse/node_ids.h"
#include "toolchain/sem_ir/file.h"
#include "toolchain/sem_ir/ids.h"
@@ -242,15 +243,11 @@ auto ImportLibraryFromCurrentPackage(Context& context,
} else {
// Leave a placeholder that the inst comes from the other IR.
auto target_id = context.AddImportRef(ir_id, import_inst_id);
// TODO: When importing from other packages, the scope's names should
// be changed to allow for ambiguous names. When importing from the
// current package, as is currently being done, we should issue a
// diagnostic on conflicts.
auto [it, success] = context.name_scopes()
.Get(enclosing_scope_id)
.names.insert({name_id, target_id});
if (!success) {
context.DiagnoseDuplicateName(target_id, it->second);
MergeImportRef(context, target_id, it->second);
}
}
}