Skip to content

Commit cbeb702

Browse files
authored
Merge pull request #65344 from xymus/spi-only-dep-5.9
[5.9][Serialization] Write down SPI-only dependencies as required in swiftmodules
2 parents 62adf1f + c688a36 commit cbeb702

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
@@ -1219,8 +1219,9 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
12191219
// distinguish them.
12201220
ImportSet publicImportSet =
12211221
getImportsAsSet(M, ModuleDecl::ImportFilterKind::Exported);
1222-
ImportSet privateImportSet =
1223-
getImportsAsSet(M, ModuleDecl::ImportFilterKind::Default);
1222+
ImportSet defaultImportSet =
1223+
getImportsAsSet(M, {ModuleDecl::ImportFilterKind::Default,
1224+
ModuleDecl::ImportFilterKind::SPIOnly});
12241225
ImportSet packageOnlyImportSet =
12251226
getImportsAsSet(M, ModuleDecl::ImportFilterKind::PackageOnly);
12261227
ImportSet internalOrBelowImportSet =
@@ -1270,7 +1271,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
12701271
// form here.
12711272
if (publicImportSet.count(import))
12721273
stableImportControl = ImportControl::Exported;
1273-
else if (privateImportSet.count(import))
1274+
else if (defaultImportSet.count(import))
12741275
stableImportControl = ImportControl::Normal;
12751276
else if (packageOnlyImportSet.count(import))
12761277
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)