[SourceKit/DocSupport] Report the required bystander modules on symbols from cross-import overlays.

Resolves rdar://problem/59446044
This commit is contained in:
Nathan Hawes
2020-03-20 18:58:01 -07:00
parent 7811f531cb
commit 9aafadd090
6 changed files with 274 additions and 2 deletions

View File

@@ -65,6 +65,7 @@ struct TextEntity {
const Decl *Dcl = nullptr;
TypeOrExtensionDecl SynthesizeTarget;
const Decl *DefaultImplementationOf = nullptr;
ModuleDecl *UnderlyingModIfFromOverlay = nullptr;
StringRef Argument;
TextRange Range;
unsigned LocOffset = 0;
@@ -303,7 +304,8 @@ static bool initDocEntityInfo(const Decl *D,
TypeOrExtensionDecl SynthesizedTarget,
const Decl *DefaultImplementationOf, bool IsRef,
bool IsSynthesizedExtension, DocEntityInfo &Info,
StringRef Arg = StringRef()) {
StringRef Arg = StringRef(),
ModuleDecl *ModIfFromOverlay = nullptr){
if (!IsRef && D->isImplicit())
return true;
if (!D || isa<ParamDecl>(D) ||
@@ -409,6 +411,15 @@ static bool initDocEntityInfo(const Decl *D,
SwiftLangSupport::printFullyAnnotatedGenericReq(Sig, OS);
}
}
if (ModIfFromOverlay) {
ModuleDecl *MD = D->getModuleContext();
SmallVector<Identifier, 1> Bystanders;
ModIfFromOverlay->getAllBystandersForCrossImportOverlay(MD, Bystanders);
std::transform(Bystanders.begin(), Bystanders.end(),
std::back_inserter(Info.RequiredBystanders),
[](Identifier Bystander){ return Bystander.str().str(); });
}
}
switch(D->getDeclContext()->getContextKind()) {
@@ -446,7 +457,8 @@ static bool initDocEntityInfo(const TextEntity &Entity,
if (initDocEntityInfo(Entity.Dcl, Entity.SynthesizeTarget,
Entity.DefaultImplementationOf,
/*IsRef=*/false, Entity.IsSynthesizedExtension,
Info, Entity.Argument))
Info, Entity.Argument,
Entity.UnderlyingModIfFromOverlay))
return true;
Info.Offset = Entity.Range.Offset;
Info.Length = Entity.Range.Length;
@@ -962,6 +974,16 @@ static bool getModuleInterfaceInfo(ASTContext &Ctx, StringRef ModuleName,
Info.Text = std::string(OS.str());
Info.TopEntities = std::move(Printer.TopEntities);
Info.References = std::move(Printer.References);
// Add a reference to the main module on any entities from cross-import
// overlay modules (used to determine their bystanders later).
for (auto &Entity: Info.TopEntities) {
auto *EntityMod = Entity.Dcl->getModuleContext();
if (!EntityMod || EntityMod == M)
continue;
if (M->isUnderlyingModuleOfCrossImportOverlay(EntityMod))
Entity.UnderlyingModIfFromOverlay = M;
}
return false;
}