Skip to content

Commit bf99f31

Browse files
committed
Revert "PrintAsObjc: expand module @imports to header #imports if modules are not supported"
This reverts commit a2534fa.
1 parent 6a7a7ff commit bf99f31

File tree

7 files changed

+3
-59
lines changed

7 files changed

+3
-59
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,6 @@ static void writeImports(raw_ostream &out,
319319

320320
// Track printed names to handle overlay modules.
321321
llvm::SmallPtrSet<Identifier, 8> seenImports;
322-
llvm::SmallString<256> allPaths;
323-
llvm::SmallSetVector<StringRef, 8> headerImports;
324-
auto insertHeaderPath = [&](clang::Module::Header header,
325-
const clang::Module *module) {
326-
auto startIdx = allPaths.size();
327-
if (module->IsFramework) {
328-
// For framworks, the header import should start from the framework name.
329-
allPaths.append(module->getTopLevelModuleName());
330-
llvm::sys::path::append(allPaths, header.NameAsWritten);
331-
} else {
332-
// Otherwise, import the header directly.
333-
allPaths.append(header.NameAsWritten);
334-
}
335-
headerImports.insert(allPaths.str().substr(startIdx));
336-
};
337322
bool includeUnderlying = false;
338323
for (auto import : sortedImports) {
339324
if (auto *swiftModule = import.dyn_cast<ModuleDecl *>()) {
@@ -342,43 +327,17 @@ static void writeImports(raw_ostream &out,
342327
includeUnderlying = true;
343328
continue;
344329
}
345-
if (seenImports.insert(Name).second) {
330+
if (seenImports.insert(Name).second)
346331
out << "@import " << Name.str() << ";\n";
347-
if (auto *clangM = swiftModule->findUnderlyingClangModule()) {
348-
if (auto umbrella = clangM->getUmbrellaHeader()) {
349-
// If an umbrella header is available, use that.
350-
insertHeaderPath(umbrella, clangM);
351-
} else {
352-
// Collect all headers included in the module.
353-
for (auto headers: clangM->Headers) {
354-
for (auto header: headers) {
355-
insertHeaderPath(header, clangM);
356-
}
357-
}
358-
}
359-
}
360-
}
361332
} else {
362333
const auto *clangModule = import.get<const clang::Module *>();
363334
assert(clangModule->isSubModule() &&
364335
"top-level modules should use a normal swift::ModuleDecl");
365336
out << "@import ";
366337
ModuleDecl::ReverseFullNameIterator(clangModule).printForward(out);
367338
out << ";\n";
368-
// Collect all headers included in the submodule
369-
for (auto headers: clangModule->Headers) {
370-
for (auto header: headers) {
371-
insertHeaderPath(header, clangModule);
372-
}
373-
}
374339
}
375340
}
376-
out << "#else\n";
377-
378-
// We cannot use module import, so use header includes instead.
379-
for (auto header: headerImports) {
380-
out << "#import <" << header << ">\n";
381-
}
382341

383342
out << "#endif\n\n";
384343

test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public func _convertNSErrorToError(_ error: NSError?) -> Error {
238238
}
239239

240240
public func _convertErrorToNSError(_ x: Error) -> NSError {
241-
return unsafeDowncast(_bridgeErrorToNSError(x), to: NSError.self)
241+
return x as NSError
242242
}
243243

244244
extension _SwiftNewtypeWrapper where Self.RawValue == Error {

test/PrintAsObjC/classes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// RUN: %FileCheck %s < %t/classes.h
1818
// RUN: %FileCheck --check-prefix=NEGATIVE %s < %t/classes.h
1919
// RUN: %check-in-clang -I %S/Inputs/custom-modules/ %t/classes.h
20-
// RUN: %check-in-clang -I %S/Inputs/custom-modules/ -fno-modules -Qunused-arguments %t/classes.h
20+
// RUN: not %check-in-clang -I %S/Inputs/custom-modules/ -fno-modules -Qunused-arguments %t/classes.h
2121
// RUN: %check-in-clang -I %S/Inputs/custom-modules/ -fno-modules -Qunused-arguments %t/classes.h -include CoreFoundation.h -include objc_generics.h -include SingleGenericClass.h -include CompatibilityAlias.h
2222

2323
// CHECK-NOT: AppKit;

test/PrintAsObjC/empty.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
// CHECK-NEXT: #if __has_warning
3939
// CHECK-NEXT: #pragma clang diagnostic
4040
// CHECK-NEXT: #endif
41-
// CHECK-NEXT: #else
4241
// CHECK-NEXT: #endif
4342

4443

test/PrintAsObjC/imports.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@
2020
// CHECK-NEXT: @import ObjectiveC;
2121
// CHECK-NEXT: @import ctypes.bits;
2222

23-
// CHECK-NEXT: #else
24-
// CHECK-NEXT: #import <Base.ExplicitSub.h>
25-
// CHECK-NEXT: #import <Base.ExplicitSub.ExSub.h>
26-
// CHECK-NEXT: #import <Base.ImplicitSub.ExSub.h>
27-
// CHECK-NEXT: #import <Foundation.h>
28-
// CHECK-NEXT: #import <MostlyPrivate1/MostlyPrivate1.h>
29-
// CHECK-NEXT: #import <MostlyPrivate1_Private/MostlyPrivate1_Private.h>
30-
// CHECK-NEXT: #import <MostlyPrivate2_Private/MostlyPrivate2_Private.h>
31-
// CHECK-NEXT: #import <ctypes/bits.h>
32-
3323
// NEGATIVE-NOT: ctypes;
3424
// NEGATIVE-NOT: ImSub;
3525
// NEGATIVE-NOT: ImplicitSub;

test/PrintAsObjC/mixed-framework-fwd.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
// CHECK-NEXT: #pragma clang diagnostic
2323
// CHECK-NEXT: #endif
2424
// CHECK-NEXT: @import Foundation;
25-
// CHECK-NEXT: #else
26-
// CHECK-NEXT: #import <Foundation.h>
2725
// CHECK-NEXT: #endif
2826

2927
// NO-IMPORT-NOT: #import

test/PrintAsObjC/mixed-framework.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
1818
// CHECK-NEXT: #endif
1919
// CHECK-NEXT: @import Foundation;
20-
// CHECK-NEXT: #else
21-
// CHECK-NEXT: #import <Foundation.h>
2220
// CHECK-NEXT: #endif
2321

2422
// FRAMEWORK-LABEL: #import <Mixed/Mixed.h>

0 commit comments

Comments
 (0)