mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Frontend: Really allow any experimental feature when compiling a module interface.
The fix for https://github.com/apple/swift/pull/72632 was not sufficient because when modules are built from textual interface that happens in a sub-invocation which does not have typecheck-from-interface or compile-from-interface requested action. Instead of checking a requested action, set a language option to control whether non-production experimental features are allowed. Resolves rdar://125561443
This commit is contained in:
@@ -593,6 +593,14 @@ namespace swift {
|
||||
/// type-checking, SIL verification, and IR emission,
|
||||
bool BypassResilienceChecks = false;
|
||||
|
||||
/// Whether or not to allow experimental features that are only available
|
||||
/// in "production".
|
||||
#ifdef NDEBUG
|
||||
bool RestrictNonProductionExperimentalFeatures = true;
|
||||
#else
|
||||
bool RestrictNonProductionExperimentalFeatures = false;
|
||||
#endif
|
||||
|
||||
bool isConcurrencyModelTaskToThread() const {
|
||||
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
|
||||
}
|
||||
|
||||
@@ -872,17 +872,14 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
// If this is a known experimental feature, allow it in +Asserts
|
||||
// (non-release) builds for testing purposes.
|
||||
if (auto feature = getExperimentalFeature(value)) {
|
||||
#ifdef NDEBUG
|
||||
if (!buildingFromInterface && !isFeatureAvailableInProduction(*feature)) {
|
||||
if (Opts.RestrictNonProductionExperimentalFeatures &&
|
||||
!isFeatureAvailableInProduction(*feature)) {
|
||||
Diags.diagnose(SourceLoc(), diag::experimental_not_supported_in_production,
|
||||
A->getValue());
|
||||
HadError = true;
|
||||
} else {
|
||||
Opts.enableFeature(*feature);
|
||||
}
|
||||
#else
|
||||
Opts.enableFeature(*feature);
|
||||
#endif
|
||||
|
||||
if (*feature == Feature::NoncopyableGenerics2)
|
||||
Opts.enableFeature(Feature::NoncopyableGenerics);
|
||||
|
||||
@@ -2066,6 +2066,12 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
|
||||
bool StrictImplicitModuleContext =
|
||||
subInvocation.getFrontendOptions().StrictImplicitModuleContext;
|
||||
|
||||
// It isn't appropriate to restrict use of experimental features in another
|
||||
// module since it may have been built with a different compiler that allowed
|
||||
// the use of the feature.
|
||||
subInvocation.getLangOptions().RestrictNonProductionExperimentalFeatures =
|
||||
false;
|
||||
|
||||
// Save the target triple from the original context.
|
||||
llvm::Triple originalTargetTriple(subInvocation.getLangOptions().Target);
|
||||
|
||||
|
||||
12
test/Frontend/experimental-features-asserts.swift
Normal file
12
test/Frontend/experimental-features-asserts.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
// This test verifies that command line parsing allows use of any features with
|
||||
// an asserts compilers.
|
||||
|
||||
// REQUIRES: asserts
|
||||
|
||||
// 'AccessLevelOnImport' is allowed in production
|
||||
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature AccessLevelOnImport -verify
|
||||
|
||||
// 'ParserValidation' is NOT allowed in production, but we are building with an asserts compiler.
|
||||
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature ParserValidation
|
||||
|
||||
import Swift
|
||||
14
test/Frontend/experimental-features-no-asserts.swift
Normal file
14
test/Frontend/experimental-features-no-asserts.swift
Normal file
@@ -0,0 +1,14 @@
|
||||
// This test verifies that command line parsing restricts use of features that
|
||||
// are not allowed non-production compilers.
|
||||
|
||||
// REQUIRES: no_asserts
|
||||
|
||||
// 'AccessLevelOnImport' is allowed in production
|
||||
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature AccessLevelOnImport -verify
|
||||
|
||||
// 'ParserValidation' is NOT allowed in production
|
||||
// RUN: not %target-swift-frontend -typecheck %s -enable-experimental-feature ParserValidation 2>&1 | %FileCheck %s
|
||||
|
||||
// CHECK: <unknown>:0: error: experimental feature 'ParserValidation' cannot be enabled in production compiler
|
||||
|
||||
import Swift
|
||||
@@ -1,14 +1,25 @@
|
||||
// swift-interface-format-version: 1.0
|
||||
// swift-module-flags: -module-name ExperimentalFeatures -enable-experimental-feature ParserRoundTrip
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: split-file %s %t
|
||||
|
||||
// Building a module from this interface should always succeed, even though
|
||||
// ParserRoundTrip is an experimental feature that is not enabled in production
|
||||
// compilers.
|
||||
|
||||
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExperimentalFeatures -o /dev/null %s -verify
|
||||
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name ExperimentalFeatures %s -verify
|
||||
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t
|
||||
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExperimentalFeatures -o /dev/null %t/ExperimentalFeatures.swiftinterface -verify
|
||||
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name ExperimentalFeatures %t/ExperimentalFeatures.swiftinterface -verify
|
||||
|
||||
//--- ExperimentalFeatures.swiftinterface
|
||||
// swift-interface-format-version: 1.0
|
||||
// swift-module-flags: -module-name ExperimentalFeatures -enable-experimental-feature ParserRoundTrip
|
||||
|
||||
import Swift
|
||||
extension Int {
|
||||
public static var fortytwo: Int = 42
|
||||
}
|
||||
|
||||
//--- Client.swift
|
||||
|
||||
import ExperimentalFeatures
|
||||
|
||||
_ = Int.fortytwo
|
||||
Reference in New Issue
Block a user