Skip to content

Commit b3348a6

Browse files
crawl underlying clang modules for re-exports
1 parent ea61e6f commit b3348a6

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

lib/AST/Module.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,9 +1467,8 @@ collectExportedImports(const ModuleDecl *topLevelModule,
14671467
ModuleDecl::ImportFilterKind::Exported);
14681468
for (const auto &im : exportedImports) {
14691469
// Skip collecting the underlying clang module as we already have the relevant import.
1470-
if (module->isClangOverlayOf(im.importedModule))
1471-
continue;
1472-
importCollector.collect(im);
1470+
if (!module->isClangOverlayOf(im.importedModule))
1471+
importCollector.collect(im);
14731472
if (!visited.contains(im.importedModule)) {
14741473
visited.insert(im.importedModule);
14751474
stack.push_back(im.importedModule);

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,11 +3653,11 @@ void ClangModuleUnit::getTopLevelDecls(SmallVectorImpl<Decl*> &results) const {
36533653
};
36543654
// Retrieve all of the globals that will be mapped to members.
36553655

3656-
// FIXME: Since we don't represent Clang submodules as Swift
3657-
// modules, we're getting everything.
36583656
llvm::SmallPtrSet<ExtensionDecl *, 8> knownExtensions;
36593657
for (auto entry : lookupTable->allGlobalsAsMembers()) {
36603658
auto decl = entry.get<clang::NamedDecl *>();
3659+
if (decl->getOwningModule() != clangModule) continue;
3660+
36613661
Decl *importedDecl = owner.importDecl(decl, owner.CurrentVersion);
36623662
if (!importedDecl) continue;
36633663

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// REQUIRES: objc_interop
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: split-file %s %t
5+
6+
// RUN: %target-swift-symbolgraph-extract -sdk %clang-importer-sdk -module-name SwiftName -F %t/frameworks -output-dir %t -pretty-print -v
7+
// RUN: %FileCheck %s --input-file %t/SwiftName.symbols.json
8+
9+
//--- frameworks/SwiftName.framework/Modules/module.modulemap
10+
framework module SwiftName {
11+
umbrella header "SwiftName.h"
12+
export *
13+
module * { export * }
14+
}
15+
16+
//--- frameworks/SwiftName.framework/Headers/SwiftName.h
17+
#import "OtherHeader.h"
18+
19+
typedef struct {
20+
double val;
21+
} MyDouble;
22+
23+
// The swift_name attribute below generates extension decls in both header modules, which trips an
24+
// assertion if they are both added in getDisplayDecls. Make sure that this does not crash when a
25+
// symbol graph is generated.
26+
27+
// CHECK-DAG: "precise": "c:SwiftName.h@MyDoubleFixedValue"
28+
__attribute__((swift_name("MyDouble.FixedValue")))
29+
static double MyDoubleFixedValue = 0.0;
30+
31+
//--- frameworks/SwiftName.framework/Headers/OtherHeader.h
32+
// CHECK-DAG: "precise": "c:OtherHeader.h@myVar"
33+
static int myVar = 0;
34+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// REQUIRES: objc_interop
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: mkdir -p %t/frameworks/UmbrellaFramework.framework/Modules/UmbrellaFramework.swiftmodule
5+
// RUN: split-file %s %t
6+
7+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -emit-module -o %t/frameworks/UmbrellaFramework.framework/Modules/UmbrellaFramework.swiftmodule/%target-swiftmodule-name -import-underlying-module -F %t/frameworks -module-name UmbrellaFramework -disable-objc-attr-requires-foundation-module %t/UmbrellaSwift.swift -emit-symbol-graph -emit-symbol-graph-dir %t
8+
// RUN: %target-swift-symbolgraph-extract -sdk %clang-importer-sdk -module-name UmbrellaFramework -F %t/frameworks -output-dir %t -pretty-print -v
9+
// RUN: %FileCheck %s --input-file %t/UmbrellaFramework.symbols.json
10+
11+
// Ensure that Clang modules with umbrella headers and 'module * { export * }' correctly include
12+
// all their headers' symbols when Swift symbols are also present.
13+
14+
//--- UmbrellaSwift.swift
15+
@_exported import UmbrellaFramework
16+
17+
// CHECK-DAG: "precise": "s:17UmbrellaFramework12SomeProtocolP"
18+
public protocol SomeProtocol {}
19+
20+
//--- frameworks/UmbrellaFramework.framework/Modules/module.modulemap
21+
framework module UmbrellaFramework [system] {
22+
umbrella header "UmbrellaFramework.h"
23+
export *
24+
module * { export * }
25+
}
26+
27+
//--- frameworks/UmbrellaFramework.framework/Headers/UmbrellaFramework.h
28+
#include "HeaderOne.h"
29+
#include "HeaderTwo.h"
30+
// CHECK-DAG: "precise": "c:@umbrellaVar"
31+
static int umbrellaVar = 0;
32+
33+
//--- frameworks/UmbrellaFramework.framework/Headers/HeaderOne.h
34+
// CHECK-DAG: "precise": "c:@varOne"
35+
static int varOne = 1;
36+
37+
//--- frameworks/UmbrellaFramework.framework/Headers/HeaderTwo.h
38+
// CHECK-DAG: "precise": "c:@varTwo"
39+
static int varTwo = 2;

0 commit comments

Comments
 (0)