Skip to content

[cxx-interop] Print decls in the __ObjC module. #39431

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
Oct 8, 2021
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
5 changes: 4 additions & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,10 @@ class FilteringDeclaredDeclConsumer : public swift::VisibleDeclConsumer {

void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason,
DynamicLookupInfo dynamicLookupInfo) override {
if (isDeclaredInModule(ModuleFilter, VD))
if (isDeclaredInModule(ModuleFilter, VD) ||
// Sometimes imported decls get put into the clang header module. If we
// found one of these decls, don't filter it out.
VD->getModuleContext()->getName().str() == CLANG_HEADER_MODULE_NAME)
NextConsumer.foundDecl(VD, Reason, dynamicLookupInfo);
}
};
Expand Down
23 changes: 22 additions & 1 deletion lib/IDE/ModuleInterfacePrinting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,28 @@ void swift::ide::printModuleInterface(
};

if (auto clangNode = getEffectiveClangNode(D)) {
addToClangDecls(D, clangNode);
if (auto namespaceDecl =
dyn_cast_or_null<clang::NamespaceDecl>(clangNode.getAsDecl())) {
// An imported namespace decl will contain members from all redecls, so
// make sure we add all the redecls.
for (auto redecl : namespaceDecl->redecls()) {
// Namespace redecls may exist across mutliple modules. We want to
// add the decl "D" to every module that has a redecl. But we only
// want to add "D" once to prevent duplicate printing.
clang::SourceLocation loc = redecl->getLocation();
auto *owningModule = Importer.getClangOwningModule(redecl);
auto found = ClangDecls.find(owningModule);
if (found != ClangDecls.end() &&
// Don't re-add this decl if it already exists for "OwningModule".
llvm::find_if(found->second, [D](auto p) {
return p.first == D;
}) == found->second.end()) {
found->second.push_back({D, loc});
}
}
} else {
addToClangDecls(D, clangNode);
}
continue;
}

Expand Down
49 changes: 22 additions & 27 deletions test/Interop/Cxx/namespace/submodules-module-interface.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
// RUN: %target-swift-ide-test -print-module -module-to-print=Submodules.SubmoduleA -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s -check-prefix=CHECK-A
// RUN: %target-swift-ide-test -print-module -module-to-print=Submodules.SubmoduleB -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s -check-prefix=CHECK-B
// RUN: %target-swift-ide-test -print-module -module-to-print=Submodules.SubmoduleA -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
// RUN: %target-swift-ide-test -print-module -module-to-print=Submodules.SubmoduleB -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to investigate this change. I'm not sure it's what we want. I think this was one of @egorzhdan's comments on the other PR.


// CHECK-A-NOT: extension
// CHECK-A: extension NS1 {
// CHECK-A: struct BasicA {
// CHECK-A: }
// CHECK-A: }
// CHECK-A-NOT: extension

// CHECK-A: extension NS1.NS2 {
// CHECK-A: struct BasicDeepA {
// CHECK-A: }
// CHECK-A: }
// CHECK-A-NOT: extension

// CHECK-B-NOT: extension
// CHECK-B: extension NS1 {
// CHECK-B: struct BasicB {
// CHECK-B: }
// CHECK-B: }
// CHECK-B-NOT: extension

// CHECK-B: extension NS1.NS2 {
// CHECK-B: struct BasicDeepB {
// CHECK-B: }
// CHECK-B: }
// CHECK-B-NOT: extension
// CHECK: extension NS1 {
// CHECK-NEXT: struct BasicA {
// CHECK-NEXT: init()
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: extension NS1 {
// CHECK-NEXT: struct BasicB {
// CHECK-NEXT: init()
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: extension NS1.NS2 {
// CHECK-NEXT: struct BasicDeepA {
// CHECK-NEXT: init()
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: extension NS1.NS2 {
// CHECK-NEXT: struct BasicDeepB {
// CHECK-NEXT: init()
// CHECK-NEXT: }
// CHECK-NEXT: }
71 changes: 71 additions & 0 deletions test/api-digester/Outputs/clang-module-dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,77 @@
"usr": "c:objc(pl)NSObject"
}
]
},
{
"kind": "TypeAlias",
"name": "__NSConstantString",
"printedName": "__NSConstantString",
"children": [
{
"kind": "TypeNominal",
"name": "__NSConstantString_tag",
"printedName": "__ObjC.__NSConstantString_tag",
"usr": "c:@S@__NSConstantString_tag"
}
],
"declKind": "TypeAlias",
"usr": "c:@T@__NSConstantString",
"moduleName": "__ObjC"
},
{
"kind": "TypeAlias",
"name": "__builtin_ms_va_list",
"printedName": "__builtin_ms_va_list",
"children": [
{
"kind": "TypeNominal",
"name": "UnsafeMutablePointer",
"printedName": "Swift.UnsafeMutablePointer<Swift.CChar>",
"children": [
{
"kind": "TypeNameAlias",
"name": "CChar",
"printedName": "Swift.CChar",
"children": [
{
"kind": "TypeNominal",
"name": "Int8",
"printedName": "Swift.Int8",
"usr": "s:s4Int8V"
}
]
}
],
"usr": "s:Sp"
}
],
"declKind": "TypeAlias",
"usr": "c:@T@__builtin_ms_va_list",
"moduleName": "__ObjC"
},
{
"kind": "TypeAlias",
"name": "__builtin_va_list",
"printedName": "__builtin_va_list",
"children": [
{
"kind": "TypeNominal",
"name": "Paren",
"printedName": "(__ObjC.__va_list_tag)",
"children": [
{
"kind": "TypeNominal",
"name": "__va_list_tag",
"printedName": "__ObjC.__va_list_tag",
"usr": "c:@S@__va_list_tag"
}
],
"usr": "c:@S@__va_list_tag"
}
],
"declKind": "TypeAlias",
"usr": "c:@T@__builtin_va_list",
"moduleName": "__ObjC"
}
],
"json_format_version": 6
Expand Down