Skip to content

Commit 11752f8

Browse files
authored
Merge pull request #59163 from DougGregor/more-experimental-features
2 parents b9d14cc + 6267513 commit 11752f8

File tree

10 files changed

+51
-39
lines changed

10 files changed

+51
-39
lines changed

include/swift/Basic/Features.def

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ EXPERIMENTAL_FEATURE(MoveOnly)
101101
EXPERIMENTAL_FEATURE(OneWayClosureParameters)
102102
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference)
103103

104+
/// Enable extensions of (sugared) bound generic types
105+
///
106+
/// \code
107+
/// extension [Int] { /**/ }
108+
/// \endcode
109+
EXPERIMENTAL_FEATURE(BoundGenericExtensions)
110+
111+
/// Whether to enable experimental differentiable programming features:
112+
/// `@differentiable` declaration attribute, etc.
113+
EXPERIMENTAL_FEATURE(DifferentiableProgramming)
114+
115+
/// Whether to enable forward mode differentiation.
116+
EXPERIMENTAL_FEATURE(ForwardModeDifferentiation)
117+
118+
/// Whether to enable experimental `AdditiveArithmetic` derived
119+
/// conformances.
120+
EXPERIMENTAL_FEATURE(AdditiveArithmeticDerivedConformances)
121+
104122
#undef EXPERIMENTAL_FEATURE
105123
#undef FUTURE_FEATURE
106124
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ namespace swift {
196196
/// Require public declarations to declare that they are Sendable (or not).
197197
bool RequireExplicitSendable = false;
198198

199-
/// If false, '#file' evaluates to the full path rather than a
200-
/// human-readable string.
201-
bool EnableConcisePoundFile = false;
202-
203199
/// Detect and automatically import modules' cross-import overlays.
204200
bool EnableCrossImportOverlays = false;
205201

@@ -430,17 +426,6 @@ namespace swift {
430426
/// file.
431427
bool EmitFineGrainedDependencySourcefileDotFiles = false;
432428

433-
/// Whether to enable experimental differentiable programming features:
434-
/// `@differentiable` declaration attribute, etc.
435-
bool EnableExperimentalDifferentiableProgramming = false;
436-
437-
/// Whether to enable forward mode differentiation.
438-
bool EnableExperimentalForwardModeDifferentiation = false;
439-
440-
/// Whether to enable experimental `AdditiveArithmetic` derived
441-
/// conformances.
442-
bool EnableExperimentalAdditiveArithmeticDerivedConformances = false;
443-
444429
/// Enable verification when every SubstitutionMap is constructed.
445430
bool VerifyAllSubstitutionMaps = false;
446431

@@ -462,13 +447,6 @@ namespace swift {
462447
// FrontendOptions.
463448
bool AllowModuleWithCompilerErrors = false;
464449

465-
/// Enable extensions of (sugared) bound generic types
466-
///
467-
/// \code
468-
/// extension [Int] { /**/ }
469-
/// \endcode
470-
bool EnableExperimentalBoundGenericExtensions = false;
471-
472450
/// A helper enum to represent whether or not we customized the default
473451
/// ASTVerifier behavior via a frontend flag. By default, we do not
474452
/// customize.

lib/AST/ASTPrinter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,22 @@ static bool usesFeatureTypeWitnessSystemInference(Decl *decl) {
30353035
return false;
30363036
}
30373037

3038+
static bool usesFeatureBoundGenericExtensions(Decl *decl) {
3039+
return false;
3040+
}
3041+
3042+
static bool usesFeatureDifferentiableProgramming(Decl *decl) {
3043+
return false;
3044+
}
3045+
3046+
static bool usesFeatureForwardModeDifferentiation(Decl *decl) {
3047+
return false;
3048+
}
3049+
3050+
static bool usesFeatureAdditiveArithmeticDerivedConformances(Decl *decl) {
3051+
return false;
3052+
}
3053+
30383054
static void
30393055
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
30403056
llvm::function_ref<void()> action) {

lib/AST/AutoDiff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void AutoDiffConfig::print(llvm::raw_ostream &s) const {
112112
bool swift::isDifferentiableProgrammingEnabled(SourceFile &SF) {
113113
auto &ctx = SF.getASTContext();
114114
// Return true if differentiable programming is explicitly enabled.
115-
if (ctx.LangOpts.EnableExperimentalDifferentiableProgramming)
115+
if (ctx.LangOpts.hasFeature(Feature::DifferentiableProgramming))
116116
return true;
117117
// Otherwise, return true iff the `_Differentiation` module is imported in
118118
// the given source file.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
486486
= A->getOption().matches(OPT_enable_deserialization_recovery);
487487
}
488488

489-
Opts.EnableExperimentalBoundGenericExtensions |=
490-
Args.hasArg(OPT_enable_experimental_bound_generic_extensions);
491-
492489
Opts.DisableAvailabilityChecking |=
493490
Args.hasArg(OPT_disable_availability_checking);
494491
Opts.CheckAPIAvailabilityOnly |=
@@ -547,12 +544,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
547544
if (Args.hasArg(OPT_emit_fine_grained_dependency_sourcefile_dot_files))
548545
Opts.EmitFineGrainedDependencySourcefileDotFiles = true;
549546

550-
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))
551-
Opts.EnableExperimentalAdditiveArithmeticDerivedConformances = true;
552-
553-
Opts.EnableExperimentalForwardModeDifferentiation |=
554-
Args.hasArg(OPT_enable_experimental_forward_mode_differentiation);
555-
556547
Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
557548
if (Opts.DebuggerSupport)
558549
Opts.EnableDollarIdentifiers = true;
@@ -666,6 +657,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
666657
Opts.Features.insert(Feature::OneWayClosureParameters);
667658
if (Args.hasArg(OPT_enable_experimental_associated_type_inference))
668659
Opts.Features.insert(Feature::TypeWitnessSystemInference);
660+
if (Args.hasArg(OPT_enable_experimental_bound_generic_extensions))
661+
Opts.Features.insert(Feature::BoundGenericExtensions);
662+
if (Args.hasArg(OPT_enable_experimental_forward_mode_differentiation))
663+
Opts.Features.insert(Feature::ForwardModeDifferentiation);
664+
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))
665+
Opts.Features.insert(Feature::AdditiveArithmeticDerivedConformances);
669666

670667
Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);
671668

lib/SILOptimizer/Mandatory/Differentiation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
898898
// - Functions with no return.
899899
// - Functions with unsupported control flow.
900900
if (context.getASTContext()
901-
.LangOpts.EnableExperimentalForwardModeDifferentiation &&
901+
.LangOpts.hasFeature(Feature::ForwardModeDifferentiation) &&
902902
(diagnoseNoReturn(context, witness->getOriginalFunction(), invoker) ||
903903
diagnoseUnsupportedControlFlow(
904904
context, witness->getOriginalFunction(), invoker)))
@@ -914,7 +914,7 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
914914
// generation because generated JVP may not match semantics of custom VJP.
915915
// Instead, create an empty JVP.
916916
if (context.getASTContext()
917-
.LangOpts.EnableExperimentalForwardModeDifferentiation &&
917+
.LangOpts.hasFeature(Feature::ForwardModeDifferentiation) &&
918918
!witness->getVJP()) {
919919
// JVP and differential generation do not currently support functions with
920920
// multiple basic blocks.

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,8 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
28482848

28492849
// By default, the user cannot extend a bound generic type, unless it's
28502850
// referenced via a non-generic typealias type.
2851-
if (!ext->getASTContext().LangOpts.EnableExperimentalBoundGenericExtensions &&
2851+
if (!ext->getASTContext().LangOpts.hasFeature(
2852+
Feature::BoundGenericExtensions) &&
28522853
extendedType->isSpecialized() &&
28532854
!isNonGenericTypeAliasType(extendedType)) {
28542855
diags.diagnose(ext->getLoc(), diag::extension_specialization,

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ bool swift::isAdditiveArithmeticConformanceDerivationEnabled(SourceFile &SF) {
379379
auto &ctx = SF.getASTContext();
380380
// Return true if `AdditiveArithmetic` derived conformances are explicitly
381381
// enabled.
382-
if (ctx.LangOpts.EnableExperimentalAdditiveArithmeticDerivedConformances)
382+
if (ctx.LangOpts.hasFeature(Feature::AdditiveArithmeticDerivedConformances))
383383
return true;
384384
// Otherwise, return true iff differentiable programming is enabled.
385385
// Differentiable programming depends on `AdditiveArithmetic` derived

lib/TBDGen/TBDGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void TBDGenVisitor::addAutoDiffLinearMapFunction(AbstractFunctionDecl *original,
559559

560560
// Differential functions are emitted only when forward-mode is enabled.
561561
if (kind == AutoDiffLinearMapKind::Differential &&
562-
!ctx.LangOpts.EnableExperimentalForwardModeDifferentiation)
562+
!ctx.LangOpts.hasFeature(Feature::ForwardModeDifferentiation))
563563
return;
564564
auto *loweredParamIndices = autodiff::getLoweredParameterIndices(
565565
config.parameterIndices,

tools/sil-opt/SILOpt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,10 @@ int main(int argc, char **argv) {
576576
if (EnableExperimentalStaticAssert)
577577
Invocation.getLangOptions().Features.insert(Feature::StaticAssert);
578578

579-
Invocation.getLangOptions().EnableExperimentalDifferentiableProgramming =
580-
EnableExperimentalDifferentiableProgramming;
579+
if (EnableExperimentalDifferentiableProgramming) {
580+
Invocation.getLangOptions().Features.insert(
581+
Feature::DifferentiableProgramming);
582+
}
581583

582584
Invocation.getLangOptions().EnableCXXInterop = EnableCxxInterop;
583585

0 commit comments

Comments
 (0)