mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Sema] Allow the use of SPI in API for SPI modules
When the whole module has an SPI distribution, SPI declarations can be used in API. rdar://75335462
This commit is contained in:
@@ -331,6 +331,13 @@ static void ParseModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
|
||||
Args.hasArg(OPT_experimental_spi_imports);
|
||||
Opts.DebugPrintInvalidSyntax |=
|
||||
Args.hasArg(OPT_debug_emit_invalid_swiftinterface_syntax);
|
||||
|
||||
if (const Arg *A = Args.getLastArg(OPT_library_level)) {
|
||||
StringRef contents = A->getValue();
|
||||
if (contents == "spi") {
|
||||
Opts.PrintSPIs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Save a copy of any flags marked as ModuleInterfaceOption, if running
|
||||
|
||||
@@ -862,7 +862,7 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
|
||||
}
|
||||
|
||||
if (opts.InputsAndOutputs.hasPrivateModuleInterfaceOutputPath()) {
|
||||
// Copy the settings from the module interface
|
||||
// Copy the settings from the module interface to add SPI printing.
|
||||
ModuleInterfaceOptions privOpts = Invocation.getModuleInterfaceOptions();
|
||||
privOpts.PrintSPIs = true;
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ ExportContext ExportContext::forDeclSignature(Decl *D) {
|
||||
(Ctx.LangOpts.DisableAvailabilityChecking
|
||||
? AvailabilityContext::alwaysAvailable()
|
||||
: TypeChecker::overApproximateAvailabilityAtLocation(D->getEndLoc(), DC));
|
||||
bool spi = false;
|
||||
bool spi = Ctx.LangOpts.LibraryLevel == LibraryLevel::SPI;
|
||||
bool implicit = false;
|
||||
bool deprecated = false;
|
||||
Optional<PlatformKind> unavailablePlatformKind;
|
||||
@@ -208,7 +208,7 @@ ExportContext ExportContext::forFunctionBody(DeclContext *DC, SourceLoc loc) {
|
||||
? AvailabilityContext::alwaysAvailable()
|
||||
: TypeChecker::overApproximateAvailabilityAtLocation(loc, DC));
|
||||
|
||||
bool spi = false;
|
||||
bool spi = Ctx.LangOpts.LibraryLevel == LibraryLevel::SPI;
|
||||
bool implicit = false;
|
||||
bool deprecated = false;
|
||||
Optional<PlatformKind> unavailablePlatformKind;
|
||||
|
||||
27
test/SPI/export_spi_from_spi_module.swift
Normal file
27
test/SPI/export_spi_from_spi_module.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
/// Check that SPI declarations can be exported from an SPI module.
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-typecheck-verify-swift -I %t -verify-ignore-unknown -enable-library-evolution -swift-version 5 -library-level spi
|
||||
|
||||
@_spi(S) public func spiFunc() {}
|
||||
@_spi(S) public class SPIClass {
|
||||
public init() {}
|
||||
}
|
||||
@_spi(S) public class SPIStruct {
|
||||
public init() {}
|
||||
}
|
||||
@_spi(S) public protocol SPIProtocol {}
|
||||
|
||||
public func useOfSPITypeOk(_ p0: SPIProtocol, p1: SPIClass) -> SPIClass { fatalError() }
|
||||
|
||||
@inlinable
|
||||
func inlinable() -> SPIClass {
|
||||
spiFunc()
|
||||
_ = SPIClass()
|
||||
}
|
||||
|
||||
@frozen public struct FrozenStruct {
|
||||
public var spiInFrozen = SPIStruct()
|
||||
var spiTypeInFrozen = SPIStruct()
|
||||
private var spiTypeInFrozen1: SPIClass
|
||||
}
|
||||
@@ -42,6 +42,14 @@
|
||||
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Merged.swiftinterface
|
||||
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/Merged.private.swiftinterface -module-name Merged
|
||||
|
||||
/// Both the public and private textual interfaces should have
|
||||
/// SPI information with `-library-level spi`.
|
||||
// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/SPIModule.swiftinterface -emit-private-module-interface-path %t/SPIModule.private.swiftinterface -enable-library-evolution -swift-version 5 -I %t -module-name SPIModule -library-level spi
|
||||
// RUN: %FileCheck -check-prefix=CHECK-PRIVATE %s < %t/SPIModule.swiftinterface
|
||||
// RUN: %FileCheck -check-prefix=CHECK-PRIVATE %s < %t/SPIModule.private.swiftinterface
|
||||
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/SPIModule.swiftinterface
|
||||
// RUN: %target-swift-frontend -typecheck-module-from-interface -I %t %t/SPIModule.private.swiftinterface -module-name SPIModule
|
||||
|
||||
@_spi(HelperSPI) @_spi(OtherSPI) @_spi(OtherSPI) import SPIHelper
|
||||
// CHECK-PUBLIC: import SPIHelper
|
||||
// CHECK-PRIVATE: @_spi(OtherSPI) @_spi(HelperSPI) import SPIHelper
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
// RUN: rm %t/SPIHelper.swiftmodule
|
||||
// RUN: %target-typecheck-verify-swift -I %t -verify-ignore-unknown
|
||||
|
||||
/// Reading from .swiftinterface should still produce the same failures
|
||||
/// Reading from the public .swiftinterface should raise errors on missing
|
||||
/// declarations.
|
||||
// RUN: rm %t/SPIHelper.private.swiftinterface
|
||||
// RUN: not %target-swift-frontend -typecheck -I %t
|
||||
// RUN: not %target-swift-frontend -typecheck -I %t %s
|
||||
|
||||
import SPIHelper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user