Merge pull request #59829 from hborla/enable-bound-generic-extensions

[SE-0361] Enable bound generic extensions.
This commit is contained in:
Holly Borla
2022-07-05 17:38:59 -07:00
committed by GitHub
12 changed files with 7 additions and 42 deletions

View File

@@ -1907,9 +1907,6 @@ ERROR(extension_access_with_conformances,none,
"protocol conformances", (DeclAttribute)) "protocol conformances", (DeclAttribute))
ERROR(extension_metatype,none, ERROR(extension_metatype,none,
"cannot extend a metatype %0", (Type)) "cannot extend a metatype %0", (Type))
ERROR(extension_specialization,none,
"constrained extension must be declared on the unspecialized generic "
"type %0 with constraints specified by a 'where' clause", (Identifier))
ERROR(extension_placeholder,none, ERROR(extension_placeholder,none,
"cannot extend a type that contains placeholders", ()) "cannot extend a type that contains placeholders", ())
ERROR(extension_stored_property,none, ERROR(extension_stored_property,none,

View File

@@ -101,13 +101,6 @@ EXPERIMENTAL_FEATURE(MoveOnly)
EXPERIMENTAL_FEATURE(OneWayClosureParameters) EXPERIMENTAL_FEATURE(OneWayClosureParameters)
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference) EXPERIMENTAL_FEATURE(TypeWitnessSystemInference)
/// Enable extensions of (sugared) bound generic types
///
/// \code
/// extension [Int] { /**/ }
/// \endcode
EXPERIMENTAL_FEATURE(BoundGenericExtensions)
/// Whether to enable experimental differentiable programming features: /// Whether to enable experimental differentiable programming features:
/// `@differentiable` declaration attribute, etc. /// `@differentiable` declaration attribute, etc.
EXPERIMENTAL_FEATURE(DifferentiableProgramming) EXPERIMENTAL_FEATURE(DifferentiableProgramming)

View File

@@ -317,10 +317,6 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
def enable_experimental_async_top_level : def enable_experimental_async_top_level :
Flag<["-"], "enable-experimental-async-top-level">, Flag<["-"], "enable-experimental-async-top-level">,
HelpText<"Enable experimental concurrency in top-level code">; HelpText<"Enable experimental concurrency in top-level code">;
def enable_experimental_bound_generic_extensions :
Flag<["-"], "enable-experimental-bound-generic-extensions">,
HelpText<"Enable experimental support for extensions of bound generic types">;
} }
// HIDDEN FLAGS // HIDDEN FLAGS

View File

@@ -3035,10 +3035,6 @@ static bool usesFeatureTypeWitnessSystemInference(Decl *decl) {
return false; return false;
} }
static bool usesFeatureBoundGenericExtensions(Decl *decl) {
return false;
}
static bool usesFeatureDifferentiableProgramming(Decl *decl) { static bool usesFeatureDifferentiableProgramming(Decl *decl) {
return false; return false;
} }

View File

@@ -653,8 +653,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.Features.insert(Feature::OneWayClosureParameters); Opts.Features.insert(Feature::OneWayClosureParameters);
if (Args.hasArg(OPT_enable_experimental_associated_type_inference)) if (Args.hasArg(OPT_enable_experimental_associated_type_inference))
Opts.Features.insert(Feature::TypeWitnessSystemInference); 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)) if (Args.hasArg(OPT_enable_experimental_forward_mode_differentiation))
Opts.Features.insert(Feature::ForwardModeDifferentiation); Opts.Features.insert(Feature::ForwardModeDifferentiation);
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation)) if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))

View File

@@ -2883,17 +2883,5 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
return error(); return error();
} }
// By default, the user cannot extend a bound generic type, unless it's
// referenced via a non-generic typealias type.
if (!ext->getASTContext().LangOpts.hasFeature(
Feature::BoundGenericExtensions) &&
extendedType->isSpecialized() &&
!isNonGenericTypeAliasType(extendedType)) {
diags.diagnose(ext->getLoc(), diag::extension_specialization,
extendedType->getAnyNominal()->getName())
.highlight(extendedRepr->getSourceRange());
return error();
}
return extendedType; return extendedType;
} }

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test -enable-experimental-bound-generic-extensions // RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name Test // RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name Test
// RUN: %FileCheck %s < %t.swiftinterface // RUN: %FileCheck %s < %t.swiftinterface

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-silgen -enable-experimental-bound-generic-extensions %s | %FileCheck %s // RUN: %target-swift-emit-silgen %s | %FileCheck %s
struct Tree<T> { struct Tree<T> {
struct Branch<B> { struct Branch<B> {

View File

@@ -40,8 +40,6 @@ func nestingTest6() {
extension Array { extension Array {
func foo() { func foo() {
extension Array { // expected-error {{declaration is only valid at file scope}} extension Array { // expected-error {{declaration is only valid at file scope}}
// FIXME: Confusing error
// expected-error@-2 {{constrained extension must be declared on the unspecialized generic type 'Array' with constraints specified by a 'where' clause}}
} }
} }
} }
@@ -347,7 +345,8 @@ extension Tree.LimbContent.Contents {
} }
extension Tree.BoughPayload.Contents { extension Tree.BoughPayload.Contents {
// expected-error@-1 {{constrained extension must be declared on the unspecialized generic type 'Nest'}} // expected-error@-1 {{extension of type 'Tree.BoughPayload.Contents' (aka 'Nest<Int>') must be declared as an extension of 'Nest<Int>'}}
// expected-note@-2 {{did you mean to extend 'Nest<Int>' instead?}}
} }
// SR-10466 Check 'where' clause when referencing type defined inside extension // SR-10466 Check 'where' clause when referencing type defined inside extension

View File

@@ -19,11 +19,9 @@ extension Double : P2 {
} }
extension X<Int, Double, String> { extension X<Int, Double, String> {
// expected-error@-1{{constrained extension must be declared on the unspecialized generic type 'X' with constraints specified by a 'where' clause}}
let x = 0 let x = 0
// expected-error@-1 {{extensions must not contain stored properties}} // expected-error@-1 {{extensions must not contain stored properties}}
static let x = 0 static let x = 0
// expected-error@-1 {{static stored properties not supported in generic types}}
func f() -> Int {} func f() -> Int {}
class C<T> {} class C<T> {}
} }

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-bound-generic-extensions // RUN: %target-typecheck-verify-swift
extension Array<Int> { extension Array<Int> {
func someIntFuncOnArray() {} func someIntFuncOnArray() {}

View File

@@ -307,9 +307,9 @@ func takesSugaredType2(m: GenericClass<Int>.TA<Float>) {
extension A {} extension A {}
extension A<T> {} // expected-error {{generic type 'A' specialized with too few type parameters (got 1, but expected 2)}} extension A<T> {} // expected-error {{generic type 'A' specialized with too few type parameters (got 1, but expected 2)}}
extension A<Float,Int> {} // expected-error {{constrained extension must be declared on the unspecialized generic type 'MyType' with constraints specified by a 'where' clause}} extension A<Float,Int> {}
extension C<T> {} // expected-error {{cannot find type 'T' in scope}} extension C<T> {} // expected-error {{cannot find type 'T' in scope}}
extension C<Int> {} // expected-error {{constrained extension must be declared on the unspecialized generic type 'MyType' with constraints specified by a 'where' clause}} extension C<Int> {}
protocol ErrorQ { protocol ErrorQ {