Skip to content

Commit 3c00266

Browse files
Merge pull request #34838 from varungandhi-apple/vg-serde-serialize-non-modular-clang-type
[Serialization] Serialize Clang types for non-modular headers.
2 parents c51b10a + 85d4d12 commit 3c00266

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

lib/ClangImporter/Serializability.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ class SerializationPathFinder {
5353
Impl.SwiftContext.getSwiftDeclForExportedClangDecl(decl))
5454
return swiftDecl;
5555

56-
// Otherwise we have no way to find it.
57-
return StableSerializationPath();
56+
// Allow serialization for non-modular headers as well, with the hope that
57+
// we find the same header when doing unqualified lookup during
58+
// deserialization.
59+
return findImportedPath(named);
5860
}
5961

6062
private:

test/ClangImporter/unserializable-clang-function-types.swift

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
typedef struct {
2+
int x;
3+
} PlaceholderType;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -enable-testing -module-name NonModularApp -emit-module -o %t/NonModularApp.swiftmodule -import-objc-header %S/Inputs/non-modular-header.h -DNON_MODULAR_APP -use-clang-function-types
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -typecheck -module-name NonModularAppTest -I %t -DNON_MODULAR_APP_TEST
4+
5+
// CHECK: Clang function type is not serializable
6+
7+
#if NON_MODULAR_APP
8+
import ctypes
9+
struct S {
10+
static func f(_ : @convention(c, cType: "void (*)(PlaceholderType, size_t)") (PlaceholderType, Int) -> ()) {}
11+
}
12+
#endif
13+
14+
#if NON_MODULAR_APP_TEST
15+
@testable import NonModularApp
16+
17+
S.f({ _, _ in })
18+
#endif

0 commit comments

Comments
 (0)