Skip to content

Commit bf1564c

Browse files
authored
Merge pull request #41605 from xymus/experimental-spi-import-fix-inconsistency
[ASTPrinter] Fix printing inconsistent implementation-only imports
2 parents 96c079a + c22cf03 commit bf1564c

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,22 @@ static void printImports(raw_ostream &out,
197197
// imports and filter them later.
198198
llvm::SmallSet<ImportedModule, 4, ImportedModule::Order> ioiImportSet;
199199
if (Opts.PrintSPIs && Opts.ExperimentalSPIImports) {
200-
allImportFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
201200

202-
SmallVector<ImportedModule, 4> ioiImport;
203-
M->getImportedModules(ioiImport,
201+
SmallVector<ImportedModule, 4> ioiImports, allImports;
202+
M->getImportedModules(ioiImports,
204203
ModuleDecl::ImportFilterKind::ImplementationOnly);
205-
ioiImportSet.insert(ioiImport.begin(), ioiImport.end());
204+
205+
// Only consider modules imported consistently as implementation-only.
206+
M->getImportedModules(allImports,
207+
allImportFilter);
208+
llvm::SmallSet<ImportedModule, 8, ImportedModule::Order> allImportSet;
209+
allImportSet.insert(allImports.begin(), allImports.end());
210+
211+
for (auto import: ioiImports)
212+
if (allImportSet.count(import) == 0)
213+
ioiImportSet.insert(import);
214+
215+
allImportFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
206216
}
207217

208218
SmallVector<ImportedModule, 8> allImports;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@_implementationOnly import InconsistentlyImported

test/SPI/experimental_spi_imports_swiftinterface.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
// RUN: %target-swift-frontend -emit-module %S/Inputs/ioi_helper.swift -module-name ExperimentalImported -emit-module-path %t/ExperimentalImported.swiftmodule -swift-version 5 -enable-library-evolution
88
// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name IOIImported -emit-module-path %t/IOIImported.swiftmodule -swift-version 5 -enable-library-evolution
99
// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name SPIImported -emit-module-path %t/SPIImported.swiftmodule -swift-version 5 -enable-library-evolution
10+
// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name InconsistentlyImported -emit-module-path %t/InconsistentlyImported.swiftmodule -swift-version 5 -enable-library-evolution
1011

1112
/// Test the generated swiftinterface.
12-
// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/main.swiftinterface -emit-private-module-interface-path %t/main.private.swiftinterface -enable-library-evolution -swift-version 5 -I %t -experimental-spi-imports
13+
// RUN: %target-swift-frontend -typecheck %s %S/Inputs/experimental_spi_imports_inconsistent.swift -emit-module-interface-path %t/main.swiftinterface -emit-private-module-interface-path %t/main.private.swiftinterface -enable-library-evolution -swift-version 5 -I %t -experimental-spi-imports
1314
// RUN: %FileCheck -check-prefix=CHECK-PUBLIC %s < %t/main.swiftinterface
1415
// RUN: %FileCheck -check-prefix=CHECK-PRIVATE %s < %t/main.private.swiftinterface
1516

1617
@_spi(dummy) @_implementationOnly import ExperimentalImported
1718
// CHECK-PUBLIC-NOT: import ExperimentalImported
1819
// CHECK-PRIVATE: @_implementationOnly @_spi{{.*}} import ExperimentalImported
1920

21+
// This is also imported as implementation-only via another source file.
22+
import InconsistentlyImported
23+
// CHECK-PUBLIC: {{^}}import InconsistentlyImported
24+
// CHECK-PRIVATE: {{^}}import InconsistentlyImported
25+
2026
@_implementationOnly import IOIImported
2127
// CHECK-PUBLIC-NOT: IOIImported
2228
// CHECK-PRIVATE-NOT: IOIImported

0 commit comments

Comments
 (0)