Skip to content

Commit a927744

Browse files
authored
Merge pull request swiftlang#30697 from DougGregor/revert-print-as-objc-headers
[PrintAsObjC] Revert emission of header #imports
2 parents 1420b81 + bf99f31 commit a927744

File tree

9 files changed

+3
-107
lines changed

9 files changed

+3
-107
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -319,58 +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-
SmallString<64> Buffer(header.NameAsWritten);
329-
llvm::sys::path::replace_path_prefix(Buffer, "Headers/", StringRef());
330-
llvm::sys::path::replace_path_prefix(Buffer, "PrivateHeaders/", StringRef());
331-
// For framworks, the header import should start from the framework name.
332-
allPaths.append(module->getTopLevelModuleName());
333-
llvm::sys::path::append(allPaths, Buffer.str());
334-
} else {
335-
auto DirPath = header.Entry->getDir()->getName();
336-
auto I = llvm::sys::path::begin(DirPath),
337-
E = llvm::sys::path::end(DirPath);
338-
llvm::SmallVector<StringRef, 4> Comps;
339-
// Check if the path of the header contains `/usr/include/` in it.
340-
// If so, we print the header include path starting from the next component.
341-
// e.g. for .../usr/include/dispatch/dispatch.h, we print
342-
// #include "dispatch/dispatch.h" because we could assume /usr/include/ is
343-
// in the header search paths.
344-
while (true) {
345-
StringRef Parts[2] = {*I, StringRef()};
346-
++ I;
347-
if (I == E)
348-
break;
349-
Parts[1] = *I;
350-
if (Parts[0] == "usr" && Parts[1] == "include") {
351-
++ I;
352-
for (;I != E; ++ I) {
353-
Comps.push_back(*I);
354-
}
355-
break;
356-
}
357-
};
358-
if (!Comps.empty()) {
359-
// The header is in a deeper location inside /usr/include/, add the
360-
// additional path components before adding the header name.
361-
allPaths.append(Comps.front());
362-
for (auto c: llvm::makeArrayRef(Comps).slice(1)) {
363-
llvm::sys::path::append(allPaths, c);
364-
}
365-
llvm::sys::path::append(allPaths,
366-
llvm::sys::path::filename(header.NameAsWritten));
367-
} else {
368-
// Otherwise, import the header directly.
369-
allPaths.append(header.NameAsWritten);
370-
}
371-
}
372-
headerImports.insert(allPaths.str().substr(startIdx));
373-
};
374322
bool includeUnderlying = false;
375323
for (auto import : sortedImports) {
376324
if (auto *swiftModule = import.dyn_cast<ModuleDecl *>()) {
@@ -379,43 +327,17 @@ static void writeImports(raw_ostream &out,
379327
includeUnderlying = true;
380328
continue;
381329
}
382-
if (seenImports.insert(Name).second) {
330+
if (seenImports.insert(Name).second)
383331
out << "@import " << Name.str() << ";\n";
384-
if (auto *clangM = swiftModule->findUnderlyingClangModule()) {
385-
if (auto umbrella = clangM->getUmbrellaHeader()) {
386-
// If an umbrella header is available, use that.
387-
insertHeaderPath(umbrella, clangM);
388-
} else {
389-
// Collect all headers included in the module.
390-
for (auto headers: clangM->Headers) {
391-
for (auto header: headers) {
392-
insertHeaderPath(header, clangM);
393-
}
394-
}
395-
}
396-
}
397-
}
398332
} else {
399333
const auto *clangModule = import.get<const clang::Module *>();
400334
assert(clangModule->isSubModule() &&
401335
"top-level modules should use a normal swift::ModuleDecl");
402336
out << "@import ";
403337
ModuleDecl::ReverseFullNameIterator(clangModule).printForward(out);
404338
out << ";\n";
405-
// Collect all headers included in the submodule
406-
for (auto headers: clangModule->Headers) {
407-
for (auto header: headers) {
408-
insertHeaderPath(header, clangModule);
409-
}
410-
}
411339
}
412340
}
413-
out << "#else\n";
414-
415-
// We cannot use module import, so use header includes instead.
416-
for (auto header: headerImports) {
417-
out << "#import <" << header << ">\n";
418-
}
419341

420342
out << "#endif\n\n";
421343

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/Inputs/clang-importer-sdk/usr/include/CTypesCore/module.modulemap

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/Inputs/clang-importer-sdk/usr/include/CTypesCore/values.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

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 & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,13 @@
1313
// CHECK-NEXT: @import Base.ExplicitSub;
1414
// CHECK-NEXT: @import Base.ExplicitSub.ExSub;
1515
// CHECK-NEXT: @import Base.ImplicitSub.ExSub;
16-
// CHECK-NEXT: @import CTypesCore;
1716
// CHECK-NEXT: @import Foundation;
1817
// CHECK-NEXT: @import MostlyPrivate1;
1918
// CHECK-NEXT: @import MostlyPrivate1_Private;
2019
// CHECK-NEXT: @import MostlyPrivate2_Private;
2120
// CHECK-NEXT: @import ObjectiveC;
2221
// CHECK-NEXT: @import ctypes.bits;
2322

24-
// CHECK-NEXT: #else
25-
// CHECK-NEXT: #import <Base.ExplicitSub.h>
26-
// CHECK-NEXT: #import <Base.ExplicitSub.ExSub.h>
27-
// CHECK-NEXT: #import <Base.ImplicitSub.ExSub.h>
28-
// CHECK-NEXT: #import <CTypesCore/values.h>
29-
// CHECK-NEXT: #import <Foundation.h>
30-
// CHECK-NEXT: #import <MostlyPrivate1/MostlyPrivate1.h>
31-
// CHECK-NEXT: #import <MostlyPrivate1_Private/MostlyPrivate1_Private.h>
32-
// CHECK-NEXT: #import <MostlyPrivate2_Private/MostlyPrivate2_Private.h>
33-
// CHECK-NEXT: #import <ctypes/bits.h>
34-
3523
// NEGATIVE-NOT: ctypes;
3624
// NEGATIVE-NOT: ImSub;
3725
// NEGATIVE-NOT: ImplicitSub;
@@ -40,7 +28,6 @@
4028

4129
// NEGATIVE-NOT: secretMethod
4230

43-
import CTypesCore
4431
import ctypes.bits
4532
import Foundation
4633

@@ -61,7 +48,6 @@ import MostlyPrivate2_Private
6148

6249
@objc class Test {
6350
@objc let word: DWORD = 0
64-
@objc let word_core: DWORD_CORE = 0
6551
@objc let number: TimeInterval = 0.0
6652

6753
@objc let baseI: BaseI = 0

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)