Skip to content

re-exported synthesized extensions need to go under the base module #59129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/SymbolGraphGen/SymbolGraphASTWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SymbolGraph *SymbolGraphASTWalker::getModuleSymbolGraph(const Decl *D) {
return &MainGraph;
}

if (isFromExportedImportedModule(D)) {
if (isExportedImportedModule(M)) {
return &MainGraph;
}

Expand Down Expand Up @@ -231,9 +231,12 @@ bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
}

bool SymbolGraphASTWalker::isFromExportedImportedModule(const Decl* D) const {
auto *M = D->getModuleContext();

return llvm::any_of(ExportedImportedModules, [&M](const auto *MD) {
return areModulesEqual(M, MD->getModuleContext());
});
auto *M = D->getModuleContext();
return isExportedImportedModule(M);
}

bool SymbolGraphASTWalker::isExportedImportedModule(const ModuleDecl *M) const {
return llvm::any_of(ExportedImportedModules, [&M](const auto *MD) {
return areModulesEqual(M, MD->getModuleContext());
});
}
3 changes: 3 additions & 0 deletions lib/SymbolGraphGen/SymbolGraphASTWalker.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ struct SymbolGraphASTWalker : public SourceEntityWalker {

/// Returns whether the given declaration comes from an `@_exported import` module.
virtual bool isFromExportedImportedModule(const Decl *D) const;

/// Returns whether the given module is an `@_exported import` module.
virtual bool isExportedImportedModule(const ModuleDecl *M) const;
};

} // end namespace symbolgraphgen
Expand Down
1 change: 1 addition & 0 deletions test/SymbolGraph/Module/Inputs/ThirdOrder/A.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public struct SomeStruct {}
5 changes: 5 additions & 0 deletions test/SymbolGraph/Module/Inputs/ThirdOrder/B.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import A

public extension SomeStruct {
struct InnerStruct: Equatable {}
}
15 changes: 15 additions & 0 deletions test/SymbolGraph/Module/ThirdOrder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/Inputs/ThirdOrder/A.swift -module-name A -emit-module -emit-module-path %t/A.swiftmodule
// RUN: %target-swift-frontend %S/Inputs/ThirdOrder/B.swift -module-name B -emit-module -emit-module-path %t/B.swiftmodule -I %t
// RUN: %target-swift-frontend %s -module-name ThirdOrder -emit-module -emit-module-path %t/ThirdOrder.swiftmodule -I %t -emit-symbol-graph -emit-symbol-graph-dir %t
// RUN: %FileCheck %s --input-file %t/ThirdOrder.symbols.json --check-prefix BASE
// RUN: %FileCheck %s --input-file %t/[email protected] --check-prefix EXT

// Module B extends a symbol from module A that includes a synthesized symbol.
// To ensure that we track source modules correctly, we need to make sure that
// the synthesized equality operators don't appear in the ThirdOrder symbol graph.

@_exported import B

// BASE-NOT: "s:SQsE2neoiySbx_xtFZ::SYNTHESIZED::s:1A10SomeStructV1BE05InnerB0V"
// EXT: "s:SQsE2neoiySbx_xtFZ::SYNTHESIZED::s:1A10SomeStructV1BE05InnerB0V"