Skip to content

Commit f5c3775

Browse files
authored
Merge pull request #72681 from tshortli/allow-non-production-features-in-module-interface-redux
Frontend: Really allow any experimental feature when compiling a module interface
2 parents 29b8ea3 + 12fccfc commit f5c3775

File tree

6 files changed

+57
-9
lines changed

6 files changed

+57
-9
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,14 @@ namespace swift {
593593
/// type-checking, SIL verification, and IR emission,
594594
bool BypassResilienceChecks = false;
595595

596+
/// Whether or not to allow experimental features that are only available
597+
/// in "production".
598+
#ifdef NDEBUG
599+
bool RestrictNonProductionExperimentalFeatures = true;
600+
#else
601+
bool RestrictNonProductionExperimentalFeatures = false;
602+
#endif
603+
596604
bool isConcurrencyModelTaskToThread() const {
597605
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
598606
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,17 +872,14 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
872872
// If this is a known experimental feature, allow it in +Asserts
873873
// (non-release) builds for testing purposes.
874874
if (auto feature = getExperimentalFeature(value)) {
875-
#ifdef NDEBUG
876-
if (!buildingFromInterface && !isFeatureAvailableInProduction(*feature)) {
875+
if (Opts.RestrictNonProductionExperimentalFeatures &&
876+
!isFeatureAvailableInProduction(*feature)) {
877877
Diags.diagnose(SourceLoc(), diag::experimental_not_supported_in_production,
878878
A->getValue());
879879
HadError = true;
880880
} else {
881881
Opts.enableFeature(*feature);
882882
}
883-
#else
884-
Opts.enableFeature(*feature);
885-
#endif
886883

887884
if (*feature == Feature::NoncopyableGenerics2)
888885
Opts.enableFeature(Feature::NoncopyableGenerics);

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,12 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
20662066
bool StrictImplicitModuleContext =
20672067
subInvocation.getFrontendOptions().StrictImplicitModuleContext;
20682068

2069+
// It isn't appropriate to restrict use of experimental features in another
2070+
// module since it may have been built with a different compiler that allowed
2071+
// the use of the feature.
2072+
subInvocation.getLangOptions().RestrictNonProductionExperimentalFeatures =
2073+
false;
2074+
20692075
// Save the target triple from the original context.
20702076
llvm::Triple originalTargetTriple(subInvocation.getLangOptions().Target);
20712077

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This test verifies that command line parsing allows use of any features with
2+
// an asserts compilers.
3+
4+
// REQUIRES: asserts
5+
6+
// 'AccessLevelOnImport' is allowed in production
7+
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature AccessLevelOnImport -verify
8+
9+
// 'ParserValidation' is NOT allowed in production, but we are building with an asserts compiler.
10+
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature ParserValidation
11+
12+
import Swift
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This test verifies that command line parsing restricts use of features that
2+
// are not allowed non-production compilers.
3+
4+
// REQUIRES: no_asserts
5+
6+
// 'AccessLevelOnImport' is allowed in production
7+
// RUN: %target-swift-frontend -typecheck %s -enable-experimental-feature AccessLevelOnImport -verify
8+
9+
// 'ParserValidation' is NOT allowed in production
10+
// RUN: not %target-swift-frontend -typecheck %s -enable-experimental-feature ParserValidation 2>&1 | %FileCheck %s
11+
12+
// CHECK: <unknown>:0: error: experimental feature 'ParserValidation' cannot be enabled in production compiler
13+
14+
import Swift
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
// swift-interface-format-version: 1.0
2-
// swift-module-flags: -module-name ExperimentalFeatures -enable-experimental-feature ParserRoundTrip
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
33

44
// Building a module from this interface should always succeed, even though
55
// ParserRoundTrip is an experimental feature that is not enabled in production
66
// compilers.
77

8-
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExperimentalFeatures -o /dev/null %s -verify
9-
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name ExperimentalFeatures %s -verify
8+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t
9+
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExperimentalFeatures -o /dev/null %t/ExperimentalFeatures.swiftinterface -verify
10+
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name ExperimentalFeatures %t/ExperimentalFeatures.swiftinterface -verify
11+
12+
//--- ExperimentalFeatures.swiftinterface
13+
// swift-interface-format-version: 1.0
14+
// swift-module-flags: -module-name ExperimentalFeatures -enable-experimental-feature ParserRoundTrip
1015

1116
import Swift
1217
extension Int {
1318
public static var fortytwo: Int = 42
1419
}
20+
21+
//--- Client.swift
22+
23+
import ExperimentalFeatures
24+
25+
_ = Int.fortytwo

0 commit comments

Comments
 (0)