Skip to content

Commit 2bb08e3

Browse files
authored
[ModuleInterface] Add mechanism to exclude experimental flags from th… (#66088)
* [ModuleInterface] Add mechanism to exclude experimental flags from the module interface rdar://109722548 * Separate filtered flags from the typical/unfiltered case
1 parent efe6d58 commit 2bb08e3

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

include/swift/Basic/Feature.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ llvm::Optional<Feature> getExperimentalFeature(llvm::StringRef name);
6666
/// \c None if it does not have such a version.
6767
llvm::Optional<unsigned> getFeatureLanguageVersion(Feature feature);
6868

69+
/// Determine whether this feature should be included in the
70+
/// module interface
71+
bool includeInModuleInterface(Feature feature);
72+
6973
}
7074

7175
#endif // SWIFT_BASIC_FEATURES_H

include/swift/Basic/Features.def

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
langOpts.hasFeature(#FeatureName))
6363
#endif
6464

65+
#ifndef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
66+
# define EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(FeatureName, AvailableInProd) \
67+
EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd)
68+
#endif
69+
6570
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
6671
LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties", true)
6772
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
@@ -134,8 +139,8 @@ EXPERIMENTAL_FEATURE(ModuleInterfaceExportAs, true)
134139
EXPERIMENTAL_FEATURE(AccessLevelOnImport, true)
135140

136141
/// Whether to enable experimental layout string value witnesses
137-
EXPERIMENTAL_FEATURE(LayoutStringValueWitnesses, true)
138-
EXPERIMENTAL_FEATURE(LayoutStringValueWitnessesInstantiation, true)
142+
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(LayoutStringValueWitnesses, true)
143+
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(LayoutStringValueWitnessesInstantiation, true)
139144

140145
/// Whether to enable experimental differentiable programming features:
141146
/// `@differentiable` declaration attribute, etc.
@@ -196,6 +201,7 @@ EXPERIMENTAL_FEATURE(ReferenceBindings, false)
196201
/// Enable the explicit 'import Builtin' and allow Builtin usage.
197202
EXPERIMENTAL_FEATURE(BuiltinModule, true)
198203

204+
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
199205
#undef EXPERIMENTAL_FEATURE
200206
#undef UPCOMING_FEATURE
201207
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

lib/Basic/LangOptions.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ bool swift::isFeatureAvailableInProduction(Feature feature) {
461461
switch (feature) {
462462
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option) \
463463
case Feature::FeatureName: return true;
464-
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
464+
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
465465
case Feature::FeatureName: return AvailableInProd;
466466
#include "swift/Basic/Features.def"
467467
}
@@ -480,7 +480,7 @@ llvm::Optional<Feature> swift::getUpcomingFeature(llvm::StringRef name) {
480480
llvm::Optional<Feature> swift::getExperimentalFeature(llvm::StringRef name) {
481481
return llvm::StringSwitch<Optional<Feature>>(name)
482482
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option)
483-
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
483+
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
484484
.Case(#FeatureName, Feature::FeatureName)
485485
#include "swift/Basic/Features.def"
486486
.Default(None);
@@ -496,6 +496,17 @@ llvm::Optional<unsigned> swift::getFeatureLanguageVersion(Feature feature) {
496496
}
497497
}
498498

499+
bool swift::includeInModuleInterface(Feature feature) {
500+
switch (feature) {
501+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option) \
502+
case Feature::FeatureName: return true;
503+
#define EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(FeatureName, AvailableInProd) \
504+
case Feature::FeatureName: return false;
505+
#include "swift/Basic/Features.def"
506+
}
507+
llvm_unreachable("covered switch");
508+
}
509+
499510
DiagnosticBehavior LangOptions::getAccessNoteFailureLimit() const {
500511
switch (AccessNoteBehavior) {
501512
case AccessNoteDiagnosticBehavior::Ignore:

lib/Frontend/CompilerInvocation.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,19 @@ static void ParseModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
417417
}
418418
}
419419

420+
/// Checks if an arg is generally allowed to be included
421+
/// in a module interface
422+
static bool ShouldIncludeModuleInterfaceArg(const Arg *A) {
423+
if (!A->getOption().matches(options::OPT_enable_experimental_feature))
424+
return true;
425+
426+
if (auto feature = getExperimentalFeature(A->getValue())) {
427+
return swift::includeInModuleInterface(*feature);
428+
}
429+
430+
return true;
431+
}
432+
420433
/// Save a copy of any flags marked as ModuleInterfaceOption, if running
421434
/// in a mode that is going to emit a .swiftinterface file.
422435
static void SaveModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
@@ -428,6 +441,9 @@ static void SaveModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
428441
ArgStringList RenderedArgsIgnorable;
429442
ArgStringList RenderedArgsIgnorablePrivate;
430443
for (auto A : Args) {
444+
if (!ShouldIncludeModuleInterfaceArg(A))
445+
continue;
446+
431447
if (A->getOption().hasFlag(options::ModuleInterfaceOptionIgnorablePrivate)) {
432448
A->render(Args, RenderedArgsIgnorablePrivate);
433449
} else if (A->getOption().hasFlag(options::ModuleInterfaceOptionIgnorable)) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -enable-library-evolution -emit-module-interface-path %t.swiftinterface -module-name t %s -target-min-inlining-version 42 -emit-module -o /dev/null -O -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation
4+
// RUN: %FileCheck %s < %t.swiftinterface -check-prefix=CHECK-SWIFTINTERFACE
5+
//
6+
// CHECK-SWIFTINTERFACE: swift-module-flags-ignorable:
7+
// CHECK-SWIFTINTERFACE-NOT: -enable-experimental-feature LayoutStringValueWitnesses
8+
// CHECK-SWIFTINTERFACE-NOT: -enable-experimental-feature LayoutStringValueWitnessesInstantiation
9+
10+
public func foo() { }

0 commit comments

Comments
 (0)