Skip to content

Commit

Permalink
Merge pull request swiftlang#59163 from DougGregor/more-experimental-…
Browse files Browse the repository at this point in the history
…features
  • Loading branch information
DougGregor authored May 31, 2022
2 parents b9d14cc + 6267513 commit 11752f8
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 39 deletions.
18 changes: 18 additions & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ EXPERIMENTAL_FEATURE(MoveOnly)
EXPERIMENTAL_FEATURE(OneWayClosureParameters)
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference)

/// Enable extensions of (sugared) bound generic types
///
/// \code
/// extension [Int] { /**/ }
/// \endcode
EXPERIMENTAL_FEATURE(BoundGenericExtensions)

/// Whether to enable experimental differentiable programming features:
/// `@differentiable` declaration attribute, etc.
EXPERIMENTAL_FEATURE(DifferentiableProgramming)

/// Whether to enable forward mode differentiation.
EXPERIMENTAL_FEATURE(ForwardModeDifferentiation)

/// Whether to enable experimental `AdditiveArithmetic` derived
/// conformances.
EXPERIMENTAL_FEATURE(AdditiveArithmeticDerivedConformances)

#undef EXPERIMENTAL_FEATURE
#undef FUTURE_FEATURE
#undef SUPPRESSIBLE_LANGUAGE_FEATURE
Expand Down
22 changes: 0 additions & 22 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ namespace swift {
/// Require public declarations to declare that they are Sendable (or not).
bool RequireExplicitSendable = false;

/// If false, '#file' evaluates to the full path rather than a
/// human-readable string.
bool EnableConcisePoundFile = false;

/// Detect and automatically import modules' cross-import overlays.
bool EnableCrossImportOverlays = false;

Expand Down Expand Up @@ -430,17 +426,6 @@ namespace swift {
/// file.
bool EmitFineGrainedDependencySourcefileDotFiles = false;

/// Whether to enable experimental differentiable programming features:
/// `@differentiable` declaration attribute, etc.
bool EnableExperimentalDifferentiableProgramming = false;

/// Whether to enable forward mode differentiation.
bool EnableExperimentalForwardModeDifferentiation = false;

/// Whether to enable experimental `AdditiveArithmetic` derived
/// conformances.
bool EnableExperimentalAdditiveArithmeticDerivedConformances = false;

/// Enable verification when every SubstitutionMap is constructed.
bool VerifyAllSubstitutionMaps = false;

Expand All @@ -462,13 +447,6 @@ namespace swift {
// FrontendOptions.
bool AllowModuleWithCompilerErrors = false;

/// Enable extensions of (sugared) bound generic types
///
/// \code
/// extension [Int] { /**/ }
/// \endcode
bool EnableExperimentalBoundGenericExtensions = false;

/// A helper enum to represent whether or not we customized the default
/// ASTVerifier behavior via a frontend flag. By default, we do not
/// customize.
Expand Down
16 changes: 16 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,22 @@ static bool usesFeatureTypeWitnessSystemInference(Decl *decl) {
return false;
}

static bool usesFeatureBoundGenericExtensions(Decl *decl) {
return false;
}

static bool usesFeatureDifferentiableProgramming(Decl *decl) {
return false;
}

static bool usesFeatureForwardModeDifferentiation(Decl *decl) {
return false;
}

static bool usesFeatureAdditiveArithmeticDerivedConformances(Decl *decl) {
return false;
}

static void
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
llvm::function_ref<void()> action) {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/AutoDiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void AutoDiffConfig::print(llvm::raw_ostream &s) const {
bool swift::isDifferentiableProgrammingEnabled(SourceFile &SF) {
auto &ctx = SF.getASTContext();
// Return true if differentiable programming is explicitly enabled.
if (ctx.LangOpts.EnableExperimentalDifferentiableProgramming)
if (ctx.LangOpts.hasFeature(Feature::DifferentiableProgramming))
return true;
// Otherwise, return true iff the `_Differentiation` module is imported in
// the given source file.
Expand Down
15 changes: 6 additions & 9 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
= A->getOption().matches(OPT_enable_deserialization_recovery);
}

Opts.EnableExperimentalBoundGenericExtensions |=
Args.hasArg(OPT_enable_experimental_bound_generic_extensions);

Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);
Opts.CheckAPIAvailabilityOnly |=
Expand Down Expand Up @@ -547,12 +544,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (Args.hasArg(OPT_emit_fine_grained_dependency_sourcefile_dot_files))
Opts.EmitFineGrainedDependencySourcefileDotFiles = true;

if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))
Opts.EnableExperimentalAdditiveArithmeticDerivedConformances = true;

Opts.EnableExperimentalForwardModeDifferentiation |=
Args.hasArg(OPT_enable_experimental_forward_mode_differentiation);

Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
if (Opts.DebuggerSupport)
Opts.EnableDollarIdentifiers = true;
Expand Down Expand Up @@ -666,6 +657,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.Features.insert(Feature::OneWayClosureParameters);
if (Args.hasArg(OPT_enable_experimental_associated_type_inference))
Opts.Features.insert(Feature::TypeWitnessSystemInference);
if (Args.hasArg(OPT_enable_experimental_bound_generic_extensions))
Opts.Features.insert(Feature::BoundGenericExtensions);
if (Args.hasArg(OPT_enable_experimental_forward_mode_differentiation))
Opts.Features.insert(Feature::ForwardModeDifferentiation);
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))
Opts.Features.insert(Feature::AdditiveArithmeticDerivedConformances);

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

Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Mandatory/Differentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
// - Functions with no return.
// - Functions with unsupported control flow.
if (context.getASTContext()
.LangOpts.EnableExperimentalForwardModeDifferentiation &&
.LangOpts.hasFeature(Feature::ForwardModeDifferentiation) &&
(diagnoseNoReturn(context, witness->getOriginalFunction(), invoker) ||
diagnoseUnsupportedControlFlow(
context, witness->getOriginalFunction(), invoker)))
Expand All @@ -914,7 +914,7 @@ bool DifferentiationTransformer::canonicalizeDifferentiabilityWitness(
// generation because generated JVP may not match semantics of custom VJP.
// Instead, create an empty JVP.
if (context.getASTContext()
.LangOpts.EnableExperimentalForwardModeDifferentiation &&
.LangOpts.hasFeature(Feature::ForwardModeDifferentiation) &&
!witness->getVJP()) {
// JVP and differential generation do not currently support functions with
// multiple basic blocks.
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2848,7 +2848,8 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {

// By default, the user cannot extend a bound generic type, unless it's
// referenced via a non-generic typealias type.
if (!ext->getASTContext().LangOpts.EnableExperimentalBoundGenericExtensions &&
if (!ext->getASTContext().LangOpts.hasFeature(
Feature::BoundGenericExtensions) &&
extendedType->isSpecialized() &&
!isNonGenericTypeAliasType(extendedType)) {
diags.diagnose(ext->getLoc(), diag::extension_specialization,
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ bool swift::isAdditiveArithmeticConformanceDerivationEnabled(SourceFile &SF) {
auto &ctx = SF.getASTContext();
// Return true if `AdditiveArithmetic` derived conformances are explicitly
// enabled.
if (ctx.LangOpts.EnableExperimentalAdditiveArithmeticDerivedConformances)
if (ctx.LangOpts.hasFeature(Feature::AdditiveArithmeticDerivedConformances))
return true;
// Otherwise, return true iff differentiable programming is enabled.
// Differentiable programming depends on `AdditiveArithmetic` derived
Expand Down
2 changes: 1 addition & 1 deletion lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void TBDGenVisitor::addAutoDiffLinearMapFunction(AbstractFunctionDecl *original,

// Differential functions are emitted only when forward-mode is enabled.
if (kind == AutoDiffLinearMapKind::Differential &&
!ctx.LangOpts.EnableExperimentalForwardModeDifferentiation)
!ctx.LangOpts.hasFeature(Feature::ForwardModeDifferentiation))
return;
auto *loweredParamIndices = autodiff::getLoweredParameterIndices(
config.parameterIndices,
Expand Down
6 changes: 4 additions & 2 deletions tools/sil-opt/SILOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,10 @@ int main(int argc, char **argv) {
if (EnableExperimentalStaticAssert)
Invocation.getLangOptions().Features.insert(Feature::StaticAssert);

Invocation.getLangOptions().EnableExperimentalDifferentiableProgramming =
EnableExperimentalDifferentiableProgramming;
if (EnableExperimentalDifferentiableProgramming) {
Invocation.getLangOptions().Features.insert(
Feature::DifferentiableProgramming);
}

Invocation.getLangOptions().EnableCXXInterop = EnableCxxInterop;

Expand Down

0 comments on commit 11752f8

Please sign in to comment.