mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Gate SPI operator fix behind EnforceSPIOperatorGroup
This new check is source breaking. Let's gate it behind an opt-in flag for now and enable it by default on a new language mode or similar.
This commit is contained in:
@@ -561,6 +561,9 @@ EXPERIMENTAL_FEATURE(CheckImplementationOnly, true)
|
|||||||
/// report references to implementation-only imported modules.
|
/// report references to implementation-only imported modules.
|
||||||
EXPERIMENTAL_FEATURE(CheckImplementationOnlyStrict, false)
|
EXPERIMENTAL_FEATURE(CheckImplementationOnlyStrict, false)
|
||||||
|
|
||||||
|
/// Check that use sites have the required @_spi import for operators.
|
||||||
|
EXPERIMENTAL_FEATURE(EnforceSPIOperatorGroup, true)
|
||||||
|
|
||||||
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
|
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
|
||||||
#undef EXPERIMENTAL_FEATURE
|
#undef EXPERIMENTAL_FEATURE
|
||||||
#undef UPCOMING_FEATURE
|
#undef UPCOMING_FEATURE
|
||||||
|
|||||||
@@ -5537,7 +5537,9 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
|
|||||||
}
|
}
|
||||||
case AccessLevel::Public:
|
case AccessLevel::Public:
|
||||||
case AccessLevel::Open: {
|
case AccessLevel::Open: {
|
||||||
if (VD->isOperator() && VD->isSPI()) {
|
if (VD->getASTContext().LangOpts.hasFeature(
|
||||||
|
Feature::EnforceSPIOperatorGroup) &&
|
||||||
|
VD->isOperator() && VD->isSPI()) {
|
||||||
const DeclContext *useFile = useDC->getModuleScopeContext();
|
const DeclContext *useFile = useDC->getModuleScopeContext();
|
||||||
if (useFile->getParentModule() == sourceDC->getParentModule())
|
if (useFile->getParentModule() == sourceDC->getParentModule())
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ UNINTERESTING_FEATURE(SameElementRequirements)
|
|||||||
UNINTERESTING_FEATURE(SendingArgsAndResults)
|
UNINTERESTING_FEATURE(SendingArgsAndResults)
|
||||||
UNINTERESTING_FEATURE(CheckImplementationOnly)
|
UNINTERESTING_FEATURE(CheckImplementationOnly)
|
||||||
UNINTERESTING_FEATURE(CheckImplementationOnlyStrict)
|
UNINTERESTING_FEATURE(CheckImplementationOnlyStrict)
|
||||||
|
UNINTERESTING_FEATURE(EnforceSPIOperatorGroup)
|
||||||
|
|
||||||
static bool findUnderscoredLifetimeAttr(Decl *decl) {
|
static bool findUnderscoredLifetimeAttr(Decl *decl) {
|
||||||
auto hasUnderscoredLifetimeAttr = [](Decl *decl) {
|
auto hasUnderscoredLifetimeAttr = [](Decl *decl) {
|
||||||
|
|||||||
@@ -6,17 +6,21 @@
|
|||||||
// RUN: %target-swift-frontend -emit-module %S/Inputs/spi_helper.swift -module-name SPIHelper -emit-module-path %t/SPIHelper.swiftmodule -emit-module-interface-path %t/SPIHelper.swiftinterface -emit-private-module-interface-path %t/SPIHelper.private.swiftinterface -enable-library-evolution -swift-version 5 -parse-as-library
|
// RUN: %target-swift-frontend -emit-module %S/Inputs/spi_helper.swift -module-name SPIHelper -emit-module-path %t/SPIHelper.swiftmodule -emit-module-interface-path %t/SPIHelper.swiftinterface -emit-private-module-interface-path %t/SPIHelper.private.swiftinterface -enable-library-evolution -swift-version 5 -parse-as-library
|
||||||
|
|
||||||
/// Reading from swiftmodule
|
/// Reading from swiftmodule
|
||||||
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated -I %t -verify-ignore-unknown
|
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated -I %t -verify-ignore-unknown \
|
||||||
|
// RUN: -enable-experimental-feature EnforceSPIOperatorGroup
|
||||||
|
|
||||||
/// Reading from .private.swiftinterface
|
/// Reading from .private.swiftinterface
|
||||||
// RUN: rm %t/SPIHelper.swiftmodule
|
// RUN: rm %t/SPIHelper.swiftmodule
|
||||||
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated -I %t -verify-ignore-unknown
|
// RUN: %target-typecheck-verify-swift -verify-ignore-unrelated -I %t -verify-ignore-unknown \
|
||||||
|
// RUN: -enable-experimental-feature EnforceSPIOperatorGroup
|
||||||
|
|
||||||
/// Reading from the public .swiftinterface should raise errors on missing
|
/// Reading from the public .swiftinterface should raise errors on missing
|
||||||
/// declarations.
|
/// declarations.
|
||||||
// RUN: rm %t/SPIHelper.private.swiftinterface
|
// RUN: rm %t/SPIHelper.private.swiftinterface
|
||||||
// RUN: not %target-swift-frontend -typecheck -I %t %s
|
// RUN: not %target-swift-frontend -typecheck -I %t %s
|
||||||
|
|
||||||
|
// REQUIRES: swift_feature_EnforceSPIOperatorGroup
|
||||||
|
|
||||||
import SPIHelper
|
import SPIHelper
|
||||||
|
|
||||||
// Use the public API
|
// Use the public API
|
||||||
|
|||||||
Reference in New Issue
Block a user