Skip to content

Commit 2598aa5

Browse files
committed
Add experimental feature for bound generic extensions
1 parent d6bb2c0 commit 2598aa5

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

include/swift/Basic/Features.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ 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+
104111
#undef EXPERIMENTAL_FEATURE
105112
#undef FUTURE_FEATURE
106113
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,6 @@ namespace swift {
462462
// FrontendOptions.
463463
bool AllowModuleWithCompilerErrors = false;
464464

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

lib/AST/ASTPrinter.cpp

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

3038+
static bool usesFeatureBoundGenericExtensions(Decl *decl) {
3039+
return false;
3040+
}
3041+
30383042
static void
30393043
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
30403044
llvm::function_ref<void()> action) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 3 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 |=
@@ -666,6 +663,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
666663
Opts.Features.insert(Feature::OneWayClosureParameters);
667664
if (Args.hasArg(OPT_enable_experimental_associated_type_inference))
668665
Opts.Features.insert(Feature::TypeWitnessSystemInference);
666+
if (Args.hasArg(OPT_enable_experimental_bound_generic_extensions))
667+
Opts.Features.insert(Feature::BoundGenericExtensions);
669668

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

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,

0 commit comments

Comments
 (0)