From 6be76a503fbd21d0476c6267199a856953245ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 20 Apr 2023 17:57:18 -0700 Subject: [PATCH] [Serialization] Mark SPI only dependencies as required in swiftmodules rdar://108326858 --- lib/Serialization/Serialization.cpp | 7 ++-- test/Serialization/spi-only-dependency.swift | 40 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 test/Serialization/spi-only-dependency.swift diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 42837bffa64..8e6205c167c 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -1214,8 +1214,9 @@ void Serializer::writeInputBlock(const SerializationOptions &options) { // distinguish them. ImportSet publicImportSet = getImportsAsSet(M, ModuleDecl::ImportFilterKind::Exported); - ImportSet privateImportSet = - getImportsAsSet(M, ModuleDecl::ImportFilterKind::Default); + ImportSet defaultImportSet = + getImportsAsSet(M, {ModuleDecl::ImportFilterKind::Default, + ModuleDecl::ImportFilterKind::SPIOnly}); ImportSet packageOnlyImportSet = getImportsAsSet(M, ModuleDecl::ImportFilterKind::PackageOnly); ImportSet internalOrBelowImportSet = @@ -1265,7 +1266,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) { // form here. if (publicImportSet.count(import)) stableImportControl = ImportControl::Exported; - else if (privateImportSet.count(import)) + else if (defaultImportSet.count(import)) stableImportControl = ImportControl::Normal; else if (packageOnlyImportSet.count(import)) stableImportControl = ImportControl::PackageOnly; diff --git a/test/Serialization/spi-only-dependency.swift b/test/Serialization/spi-only-dependency.swift new file mode 100644 index 00000000000..9d57f4c2af8 --- /dev/null +++ b/test/Serialization/spi-only-dependency.swift @@ -0,0 +1,40 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +//--- SPIDependency.swift + +// RUN: %target-swift-frontend -emit-module %t/SPIDependency.swift -o %t \ +// RUN: -enable-library-evolution -swift-version 5 + +//--- Lib.swift + +// RUN: %target-swift-frontend -emit-module %t/Lib.swift -o %t -I %t \ +// RUN: -enable-library-evolution -swift-version 5 \ +// RUN: -emit-module-path %t/Lib.swiftmodule \ +// RUN: -emit-module-interface-path %t/Lib.swiftinterface \ +// RUN: -emit-private-module-interface-path %t/Lib.private.swiftinterface \ +// RUN: -experimental-spi-only-imports + +@_spiOnly import SPIDependency + +//--- Client.swift + +/// SPIDependency is visible when using the swiftmodule or private interface. +// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \ +// RUN: -experimental-spi-only-imports \ +// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s +// VISIBLE-DEP: loaded module 'SPIDependency' + +// RUN: rm %t/Lib.swiftmodule +// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \ +// RUN: -experimental-spi-only-imports \ +// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s + +/// SPIDependency is not visible when using the public swiftinterface. +// RUN: rm %t/Lib.private.swiftinterface +// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \ +// RUN: -experimental-spi-only-imports \ +// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP-NOT %s +// VISIBLE-DEP-NOT-NOT: loaded module 'SPIDependency' + +import Lib