Skip to content

Commit 32d4eda

Browse files
committed
[ModuleInterface] Don't alias @_spiOnly imports in public swiftinterfaces
1 parent 0609dfc commit 32d4eda

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,16 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
6969
out << " -module-alias " << MODULE_DISAMBIGUATING_PREFIX <<
7070
moduleName << "=" << moduleName;
7171

72-
SmallVector<ImportedModule> imports;
73-
M->getImportedModules(imports,
74-
{ModuleDecl::ImportFilterKind::Default,
72+
ModuleDecl::ImportFilter filter = {ModuleDecl::ImportFilterKind::Default,
7573
ModuleDecl::ImportFilterKind::Exported,
76-
ModuleDecl::ImportFilterKind::SPIOnly,
77-
ModuleDecl::ImportFilterKind::SPIAccessControl});
74+
ModuleDecl::ImportFilterKind::SPIAccessControl};
75+
if (Opts.PrintPrivateInterfaceContent)
76+
filter |= ModuleDecl::ImportFilterKind::SPIOnly;
77+
78+
SmallVector<ImportedModule> imports;
79+
M->getImportedModules(imports, filter);
7880
M->getMissingImportedModules(imports);
81+
7982
for (ImportedModule import: imports) {
8083
StringRef importedName = import.importedModule->getNameStr();
8184
if (AliasModuleNamesTargets.insert(importedName).second) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/// Test the generated swiftinterface with -alias-module-names-in-module-interface.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: split-file %s %t
5+
6+
// RUN: %target-swift-frontend -emit-module \
7+
// RUN: -swift-version 5 -enable-library-evolution \
8+
// RUN: -o %t/PublicLib.swiftmodule %t/EmptyLib.swift
9+
// RUN: %target-swift-frontend -emit-module \
10+
// RUN: -swift-version 5 -enable-library-evolution \
11+
// RUN: -o %t/SPILib.swiftmodule %t/EmptyLib.swift
12+
// RUN: %target-swift-frontend -emit-module \
13+
// RUN: -swift-version 5 -enable-library-evolution \
14+
// RUN: -o %t/IOILib.swiftmodule %t/EmptyLib.swift
15+
16+
// RUN: %target-swift-frontend -emit-module \
17+
// RUN: -swift-version 5 -enable-library-evolution \
18+
// RUN: -o %t/Client.swiftmodule \
19+
// RUN: -emit-module-interface-path %t/Client.swiftinterface \
20+
// RUN: -emit-private-module-interface-path %t/Client.private.swiftinterface \
21+
// RUN: %t/Client.swift -I %t -experimental-spi-only-imports \
22+
// RUN: -alias-module-names-in-module-interface
23+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface) -I%t
24+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) -module-name Client -I%t
25+
26+
// RUN: cat %t/Client.swiftinterface | %FileCheck %s -check-prefix=PUBLIC
27+
// RUN: cat %t/Client.private.swiftinterface | %FileCheck %s -check-prefix=PRIVATE
28+
29+
//--- EmptyLib.swift
30+
31+
public struct SomeType {}
32+
33+
//--- Client.swift
34+
35+
@_implementationOnly import IOILib
36+
@_spiOnly import SPILib
37+
import PublicLib
38+
39+
/// Check alias declarations.
40+
// PUBLIC-NOT: IOILib
41+
// PUBLIC-NOT: SPILib
42+
// PUBLIC: -module-alias Module___PublicLib
43+
// PRIVATE-NOT: IOILib
44+
// PRIVATE: -module-alias Module___SPILib
45+
// PRIVATE: -module-alias Module___PublicLib
46+
47+
/// Check imports.
48+
// PUBLIC: import Module___PublicLib
49+
// PRIVATE: import Module___PublicLib
50+
// PRIVATE: import Module___SPILib

0 commit comments

Comments
 (0)