Skip to content

Commit dbc8307

Browse files
authored
Merge pull request #59829 from hborla/enable-bound-generic-extensions
[SE-0361] Enable bound generic extensions.
2 parents 715c9ad + 609733b commit dbc8307

File tree

12 files changed

+7
-42
lines changed

12 files changed

+7
-42
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,9 +1907,6 @@ ERROR(extension_access_with_conformances,none,
19071907
"protocol conformances", (DeclAttribute))
19081908
ERROR(extension_metatype,none,
19091909
"cannot extend a metatype %0", (Type))
1910-
ERROR(extension_specialization,none,
1911-
"constrained extension must be declared on the unspecialized generic "
1912-
"type %0 with constraints specified by a 'where' clause", (Identifier))
19131910
ERROR(extension_placeholder,none,
19141911
"cannot extend a type that contains placeholders", ())
19151912
ERROR(extension_stored_property,none,

include/swift/Basic/Features.def

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ 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-
111104
/// Whether to enable experimental differentiable programming features:
112105
/// `@differentiable` declaration attribute, etc.
113106
EXPERIMENTAL_FEATURE(DifferentiableProgramming)

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,6 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
317317
def enable_experimental_async_top_level :
318318
Flag<["-"], "enable-experimental-async-top-level">,
319319
HelpText<"Enable experimental concurrency in top-level code">;
320-
321-
def enable_experimental_bound_generic_extensions :
322-
Flag<["-"], "enable-experimental-bound-generic-extensions">,
323-
HelpText<"Enable experimental support for extensions of bound generic types">;
324320
}
325321

326322
// HIDDEN FLAGS

lib/AST/ASTPrinter.cpp

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

3038-
static bool usesFeatureBoundGenericExtensions(Decl *decl) {
3039-
return false;
3040-
}
3041-
30423038
static bool usesFeatureDifferentiableProgramming(Decl *decl) {
30433039
return false;
30443040
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
653653
Opts.Features.insert(Feature::OneWayClosureParameters);
654654
if (Args.hasArg(OPT_enable_experimental_associated_type_inference))
655655
Opts.Features.insert(Feature::TypeWitnessSystemInference);
656-
if (Args.hasArg(OPT_enable_experimental_bound_generic_extensions))
657-
Opts.Features.insert(Feature::BoundGenericExtensions);
658656
if (Args.hasArg(OPT_enable_experimental_forward_mode_differentiation))
659657
Opts.Features.insert(Feature::ForwardModeDifferentiation);
660658
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,17 +2883,5 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
28832883
return error();
28842884
}
28852885

2886-
// By default, the user cannot extend a bound generic type, unless it's
2887-
// referenced via a non-generic typealias type.
2888-
if (!ext->getASTContext().LangOpts.hasFeature(
2889-
Feature::BoundGenericExtensions) &&
2890-
extendedType->isSpecialized() &&
2891-
!isNonGenericTypeAliasType(extendedType)) {
2892-
diags.diagnose(ext->getLoc(), diag::extension_specialization,
2893-
extendedType->getAnyNominal()->getName())
2894-
.highlight(extendedRepr->getSourceRange());
2895-
return error();
2896-
}
2897-
28982886
return extendedType;
28992887
}

test/ModuleInterface/specialized-extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test -enable-experimental-bound-generic-extensions
1+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test
22
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name Test
33
// RUN: %FileCheck %s < %t.swiftinterface
44

test/SILGen/mangling_specialized_extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-silgen -enable-experimental-bound-generic-extensions %s | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
22

33
struct Tree<T> {
44
struct Branch<B> {

test/decl/ext/extensions.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ func nestingTest6() {
4040
extension Array {
4141
func foo() {
4242
extension Array { // expected-error {{declaration is only valid at file scope}}
43-
// FIXME: Confusing error
44-
// expected-error@-2 {{constrained extension must be declared on the unspecialized generic type 'Array' with constraints specified by a 'where' clause}}
4543
}
4644
}
4745
}
@@ -347,7 +345,8 @@ extension Tree.LimbContent.Contents {
347345
}
348346

349347
extension Tree.BoughPayload.Contents {
350-
// expected-error@-1 {{constrained extension must be declared on the unspecialized generic type 'Nest'}}
348+
// expected-error@-1 {{extension of type 'Tree.BoughPayload.Contents' (aka 'Nest<Int>') must be declared as an extension of 'Nest<Int>'}}
349+
// expected-note@-2 {{did you mean to extend 'Nest<Int>' instead?}}
351350
}
352351

353352
// SR-10466 Check 'where' clause when referencing type defined inside extension

test/decl/ext/generic.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ extension Double : P2 {
1919
}
2020

2121
extension X<Int, Double, String> {
22-
// expected-error@-1{{constrained extension must be declared on the unspecialized generic type 'X' with constraints specified by a 'where' clause}}
2322
let x = 0
2423
// expected-error@-1 {{extensions must not contain stored properties}}
2524
static let x = 0
26-
// expected-error@-1 {{static stored properties not supported in generic types}}
2725
func f() -> Int {}
2826
class C<T> {}
2927
}

test/decl/ext/specialize.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-bound-generic-extensions
1+
// RUN: %target-typecheck-verify-swift
22

33
extension Array<Int> {
44
func someIntFuncOnArray() {}

test/decl/typealias/generic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ func takesSugaredType2(m: GenericClass<Int>.TA<Float>) {
307307
extension A {}
308308

309309
extension A<T> {} // expected-error {{generic type 'A' specialized with too few type parameters (got 1, but expected 2)}}
310-
extension A<Float,Int> {} // expected-error {{constrained extension must be declared on the unspecialized generic type 'MyType' with constraints specified by a 'where' clause}}
310+
extension A<Float,Int> {}
311311
extension C<T> {} // expected-error {{cannot find type 'T' in scope}}
312-
extension C<Int> {} // expected-error {{constrained extension must be declared on the unspecialized generic type 'MyType' with constraints specified by a 'where' clause}}
312+
extension C<Int> {}
313313

314314

315315
protocol ErrorQ {

0 commit comments

Comments
 (0)