27 "EntityLinker: Corrupted TUSummary or logic bug";
30 "{0} - {1} with {2} already exists in LUSummary";
33 "{0} - {1} missing linkage information in TUSummary";
36 "{0} - Duplicate {1} in EntityResolutionTable";
39 "{0} - {1} not found in EntityResolutionTable";
42 "{0} - Failed to insert data for {1} with {2} against {3} to LUSummary";
45 "failed to link TU summary: duplicate {0}";
61 llvm_unreachable(
"Unhandled EntityLinkage::LinkageType variant");
67 Output.LUNamespace, OldName.Namespace,
Linkage.getLinkage());
69 EntityName NewName(OldName.USR, OldName.Suffix, NewNamespace);
75 EntityId NewId = Output.IdTable.getId(NewName);
77 auto [_, Inserted] = Output.LinkageTable.try_emplace(NewId,
Linkage);
93std::map<EntityId, EntityId>
95 std::map<EntityId, EntityId> EntityResolutionTable;
97 Summary.IdTable.
forEach([&](
const EntityName &OldName,
const EntityId OldId) {
98 auto Iter = Summary.LinkageTable.find(OldId);
99 if (Iter == Summary.LinkageTable.end()) {
104 const EntityLinkage &
Linkage = Iter->second;
106 EntityId NewId = resolveEntity(OldName,
Linkage);
108 auto [_, Inserted] = EntityResolutionTable.insert({OldId, NewId});
115 return EntityResolutionTable;
118std::vector<EntitySummaryEncoding *>
120 const std::map<EntityId, EntityId> &EntityResolutionTable) {
121 std::vector<EntitySummaryEncoding *> PatchTargets;
123 for (
auto &[SN, DataMap] : Summary.Data) {
124 auto &OutputSummaryData = Output.Data[SN];
126 for (
auto &[OldId, ES] : DataMap) {
127 auto Iter = EntityResolutionTable.find(OldId);
128 if (Iter == EntityResolutionTable.end()) {
133 const auto NewId = Iter->second;
135 auto [It, Inserted] = OutputSummaryData.try_emplace(NewId, std::move(ES));
138 PatchTargets.push_back(It->second.get());
142 auto Linkage = Summary.LinkageTable.at(OldId);
164void EntityLinker::patch(
165 const std::vector<EntitySummaryEncoding *> &PatchTargets,
166 const std::map<EntityId, EntityId> &EntityResolutionTable) {
167 for (
auto *PatchTarget : PatchTargets) {
168 assert(PatchTarget &&
"EntityLinker::patch: Patch target cannot be null");
169 PatchTarget->patch(EntityResolutionTable);
174 auto [_, Inserted] = ProcessedTUNamespaces.insert(Summary->TUNamespace);
178 Summary->TUNamespace)
184 auto EntityResolutionTable = resolve(SummaryRef);
185 auto PatchTargets = merge(SummaryRef, EntityResolutionTable);
186 patch(PatchTargets, EntityResolutionTable);
188 return llvm::Error::success();
static NestedBuildNamespace resolveNamespace(const NestedBuildNamespace &LUNamespace, const NestedBuildNamespace &EntityNamespace, EntityLinkage::LinkageType Linkage)
void forEach(llvm::function_ref< void(const EntityName &, EntityId)> Callback) const
Invokes the callback for each entity in the table.
Lightweight opaque handle representing an entity in an EntityIdTable.
Represents the linkage properties of an entity in the program model.
@ None
local variables, function parameters
@ Internal
static functions/variables, anonymous namespace
@ External
globally visible across translation units
llvm::Error link(std::unique_ptr< TUSummaryEncoding > Summary)
Links a TU summary into a LU summary.
Uniquely identifies an entity in a program.
static ErrorBuilder create(std::error_code EC, const char *Fmt, Args &&...ArgVals)
Create an ErrorBuilder with an error code and formatted message.
static void fatal(const char *Fmt, Args &&...ArgVals)
Report a fatal error with formatted message and terminate execution.
llvm::Error build() const
Build and return the final error.
Represents a hierarchical sequence of build namespaces.
NestedBuildNamespace makeQualified(NestedBuildNamespace Namespace) const
Creates a new NestedBuildNamespace by appending additional namespace.
Represents a translation unit summary in its serialized encoding.
static constexpr const char * EntityAlreadyExistsInLinkageTable
static constexpr const char * DuplicateTUNamespace
static constexpr const char * EntityLinkerFatalErrorPrefix
static constexpr const char * DuplicateEntityIdInTUSummary
static constexpr const char * MissingLinkageInformation
static constexpr const char * FailedToInsertEntityIntoOutputSummary
static constexpr const char * EntityNotFoundInResolutionTable
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.