Skip to content

Commit bf6d893

Browse files
authored
Merge pull request #61844 from xedin/rdar-99884335
[Basic] Make it possible to access some experimental features in production compilers
2 parents e2c6c6c + eb57ad2 commit bf6d893

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

include/swift/Basic/Feature.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ FeatureName,
4040
/// Determine whether the given feature is suppressible.
4141
bool isSuppressibleFeature(Feature feature);
4242

43+
/// Check whether the given feature is available in production compilers.
44+
bool isFeatureAvailableInProduction(Feature feature);
45+
4346
/// Determine the in-source name of the given feature.
4447
llvm::StringRef getFeatureName(Feature feature);
4548

include/swift/Basic/Features.def

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
#endif
5656

5757
#ifndef EXPERIMENTAL_FEATURE
58-
# define EXPERIMENTAL_FEATURE(FeatureName) \
58+
// Warning: setting `AvailableInProd` to `true` on a feature means that the flag
59+
// cannot be dropped in the future.
60+
# define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
5961
LANGUAGE_FEATURE(FeatureName, 0, #FeatureName, \
6062
langOpts.hasFeature(#FeatureName))
6163
#endif
@@ -94,63 +96,63 @@ UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
9496
UPCOMING_FEATURE(BareSlashRegexLiterals, 354, 6)
9597
UPCOMING_FEATURE(ExistentialAny, 335, 6)
9698

97-
EXPERIMENTAL_FEATURE(StaticAssert)
98-
EXPERIMENTAL_FEATURE(VariadicGenerics)
99-
EXPERIMENTAL_FEATURE(NamedOpaqueTypes)
100-
EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures)
101-
EXPERIMENTAL_FEATURE(MoveOnly)
102-
EXPERIMENTAL_FEATURE(OneWayClosureParameters)
103-
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference)
104-
EXPERIMENTAL_FEATURE(ResultBuilderASTTransform)
105-
EXPERIMENTAL_FEATURE(LayoutPrespecialization)
99+
EXPERIMENTAL_FEATURE(StaticAssert, false)
100+
EXPERIMENTAL_FEATURE(VariadicGenerics, false)
101+
EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)
102+
EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures, false)
103+
EXPERIMENTAL_FEATURE(MoveOnly, false)
104+
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
105+
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)
106+
EXPERIMENTAL_FEATURE(ResultBuilderASTTransform, true)
107+
EXPERIMENTAL_FEATURE(LayoutPrespecialization, false)
106108

107109
/// Whether to enable experimental differentiable programming features:
108110
/// `@differentiable` declaration attribute, etc.
109-
EXPERIMENTAL_FEATURE(DifferentiableProgramming)
111+
EXPERIMENTAL_FEATURE(DifferentiableProgramming, false)
110112

111113
/// Whether to enable forward mode differentiation.
112-
EXPERIMENTAL_FEATURE(ForwardModeDifferentiation)
114+
EXPERIMENTAL_FEATURE(ForwardModeDifferentiation, false)
113115

114116
/// Whether to enable experimental `AdditiveArithmetic` derived
115117
/// conformances.
116-
EXPERIMENTAL_FEATURE(AdditiveArithmeticDerivedConformances)
118+
EXPERIMENTAL_FEATURE(AdditiveArithmeticDerivedConformances, false)
117119

118120
/// Whether Objective-C completion handler parameters are imported as
119121
/// @Sendable.
120-
EXPERIMENTAL_FEATURE(SendableCompletionHandlers)
122+
EXPERIMENTAL_FEATURE(SendableCompletionHandlers, false)
121123

122124
/// Enables opaque type erasure without also enabling implict dynamic
123-
EXPERIMENTAL_FEATURE(OpaqueTypeErasure)
125+
EXPERIMENTAL_FEATURE(OpaqueTypeErasure, false)
124126

125127
/// Whether to enable experimental @typeWrapper feature which allows to
126128
/// declare a type that controls access to all stored properties of the
127129
/// wrapped type.
128-
EXPERIMENTAL_FEATURE(TypeWrappers)
130+
EXPERIMENTAL_FEATURE(TypeWrappers, false)
129131

130132
/// Whether to perform round-trip testing of the Swift Swift parser.
131-
EXPERIMENTAL_FEATURE(ParserRoundTrip)
133+
EXPERIMENTAL_FEATURE(ParserRoundTrip, false)
132134

133135
/// Whether to perform validation of the parse tree produced by the Swift
134136
/// Swift parser.
135-
EXPERIMENTAL_FEATURE(ParserValidation)
137+
EXPERIMENTAL_FEATURE(ParserValidation, false)
136138

137139
/// Whether to fold sequence expressions in the syntax tree produced by the
138140
/// Swift Swift parser.
139-
EXPERIMENTAL_FEATURE(ParserSequenceFolding)
141+
EXPERIMENTAL_FEATURE(ParserSequenceFolding, false)
140142

141143
/// Enables implicit some while also enabling existential `any`
142-
EXPERIMENTAL_FEATURE(ImplicitSome)
144+
EXPERIMENTAL_FEATURE(ImplicitSome, false)
143145

144146
/// Parse using the Swift (swift-syntax) parser and use ASTGen to generate the
145147
/// corresponding syntax tree.
146-
EXPERIMENTAL_FEATURE(ParserASTGen)
148+
EXPERIMENTAL_FEATURE(ParserASTGen, false)
147149

148150
/// Enable the experimental macros feature.
149-
EXPERIMENTAL_FEATURE(Macros)
151+
EXPERIMENTAL_FEATURE(Macros, false)
150152

151153
/// Parse using the Swift (swift-syntax) parser and use ASTGen to generate the
152154
/// corresponding syntax tree.
153-
EXPERIMENTAL_FEATURE(BuiltinMacros)
155+
EXPERIMENTAL_FEATURE(BuiltinMacros, false)
154156

155157
#undef EXPERIMENTAL_FEATURE
156158
#undef UPCOMING_FEATURE

lib/Basic/LangOptions.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,17 @@ bool swift::isSuppressibleFeature(Feature feature) {
443443
llvm_unreachable("covered switch");
444444
}
445445

446+
bool swift::isFeatureAvailableInProduction(Feature feature) {
447+
switch (feature) {
448+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option) \
449+
case Feature::FeatureName: return true;
450+
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
451+
case Feature::FeatureName: return AvailableInProd;
452+
#include "swift/Basic/Features.def"
453+
}
454+
llvm_unreachable("covered switch");
455+
}
456+
446457
llvm::Optional<Feature> swift::getUpcomingFeature(llvm::StringRef name) {
447458
return llvm::StringSwitch<Optional<Feature>>(name)
448459
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option)
@@ -455,7 +466,7 @@ llvm::Optional<Feature> swift::getUpcomingFeature(llvm::StringRef name) {
455466
llvm::Optional<Feature> swift::getExperimentalFeature(llvm::StringRef name) {
456467
return llvm::StringSwitch<Optional<Feature>>(name)
457468
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option)
458-
#define EXPERIMENTAL_FEATURE(FeatureName) \
469+
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
459470
.Case(#FeatureName, Feature::FeatureName)
460471
#include "swift/Basic/Features.def"
461472
.Default(None);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
635635
// (non-release) builds for testing purposes.
636636
if (auto feature = getExperimentalFeature(A->getValue())) {
637637
#ifdef NDEBUG
638-
Diags.diagnose(SourceLoc(),
639-
diag::error_experimental_feature_not_available,
640-
A->getValue());
638+
if (!isFeatureAvailableInProduction(*feature)) {
639+
Diags.diagnose(SourceLoc(),
640+
diag::error_experimental_feature_not_available,
641+
A->getValue());
642+
}
641643
#endif
642644

643645
Opts.Features.insert(*feature);

0 commit comments

Comments
 (0)