Skip to content

Commit c688a36

Browse files
committed
[Serialization] Mark SPI only dependencies as required in swiftmodules
rdar://108326858
1 parent 434fb4b commit c688a36

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,9 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
12141214
// distinguish them.
12151215
ImportSet publicImportSet =
12161216
getImportsAsSet(M, ModuleDecl::ImportFilterKind::Exported);
1217-
ImportSet privateImportSet =
1218-
getImportsAsSet(M, ModuleDecl::ImportFilterKind::Default);
1217+
ImportSet defaultImportSet =
1218+
getImportsAsSet(M, {ModuleDecl::ImportFilterKind::Default,
1219+
ModuleDecl::ImportFilterKind::SPIOnly});
12191220
ImportSet packageOnlyImportSet =
12201221
getImportsAsSet(M, ModuleDecl::ImportFilterKind::PackageOnly);
12211222
ImportSet internalOrBelowImportSet =
@@ -1265,7 +1266,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
12651266
// form here.
12661267
if (publicImportSet.count(import))
12671268
stableImportControl = ImportControl::Exported;
1268-
else if (privateImportSet.count(import))
1269+
else if (defaultImportSet.count(import))
12691270
stableImportControl = ImportControl::Normal;
12701271
else if (packageOnlyImportSet.count(import))
12711272
stableImportControl = ImportControl::PackageOnly;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
//--- SPIDependency.swift
5+
6+
// RUN: %target-swift-frontend -emit-module %t/SPIDependency.swift -o %t \
7+
// RUN: -enable-library-evolution -swift-version 5
8+
9+
//--- Lib.swift
10+
11+
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -o %t -I %t \
12+
// RUN: -enable-library-evolution -swift-version 5 \
13+
// RUN: -emit-module-path %t/Lib.swiftmodule \
14+
// RUN: -emit-module-interface-path %t/Lib.swiftinterface \
15+
// RUN: -emit-private-module-interface-path %t/Lib.private.swiftinterface \
16+
// RUN: -experimental-spi-only-imports
17+
18+
@_spiOnly import SPIDependency
19+
20+
//--- Client.swift
21+
22+
/// SPIDependency is visible when using the swiftmodule or private interface.
23+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
24+
// RUN: -experimental-spi-only-imports \
25+
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
26+
// VISIBLE-DEP: loaded module 'SPIDependency'
27+
28+
// RUN: rm %t/Lib.swiftmodule
29+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
30+
// RUN: -experimental-spi-only-imports \
31+
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
32+
33+
/// SPIDependency is not visible when using the public swiftinterface.
34+
// RUN: rm %t/Lib.private.swiftinterface
35+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
36+
// RUN: -experimental-spi-only-imports \
37+
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP-NOT %s
38+
// VISIBLE-DEP-NOT-NOT: loaded module 'SPIDependency'
39+
40+
import Lib

0 commit comments

Comments
 (0)