Skip to content

Commit d0961a4

Browse files
authored
Merge pull request #59830 from hborla/5.7-enable-bound-generic-extensions
[5.7][SE-0361] Enable bound generic extensions.
2 parents 3668e00 + e6394cc commit d0961a4

File tree

10 files changed

+7
-35
lines changed

10 files changed

+7
-35
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,6 @@ namespace swift {
482482
// FrontendOptions.
483483
bool AllowModuleWithCompilerErrors = false;
484484

485-
/// Enable extensions of (sugared) bound generic types
486-
///
487-
/// \code
488-
/// extension [Int] { /**/ }
489-
/// \endcode
490-
bool EnableExperimentalBoundGenericExtensions = false;
491-
492485
/// A helper enum to represent whether or not we customized the default
493486
/// ASTVerifier behavior via a frontend flag. By default, we do not
494487
/// customize.

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,6 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
313313
def enable_experimental_async_top_level :
314314
Flag<["-"], "enable-experimental-async-top-level">,
315315
HelpText<"Enable experimental concurrency in top-level code">;
316-
317-
def enable_experimental_bound_generic_extensions :
318-
Flag<["-"], "enable-experimental-bound-generic-extensions">,
319-
HelpText<"Enable experimental support for extensions of bound generic types">;
320316
}
321317

322318
// HIDDEN FLAGS

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
517517
Opts.EnableBareSlashRegexLiterals = false;
518518
}
519519

520-
Opts.EnableExperimentalBoundGenericExtensions |=
521-
Args.hasArg(OPT_enable_experimental_bound_generic_extensions);
522-
523520
Opts.DisableAvailabilityChecking |=
524521
Args.hasArg(OPT_disable_availability_checking);
525522
Opts.CheckAPIAvailabilityOnly |=

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,16 +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.EnableExperimentalBoundGenericExtensions &&
2889-
extendedType->isSpecialized() &&
2890-
!isNonGenericTypeAliasType(extendedType)) {
2891-
diags.diagnose(ext->getLoc(), diag::extension_specialization,
2892-
extendedType->getAnyNominal()->getName())
2893-
.highlight(extendedRepr->getSourceRange());
2894-
return error();
2895-
}
2896-
28972886
return extendedType;
28982887
}

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-frontend -module-name Test -typecheck -emit-module-interface-path - -enable-experimental-bound-generic-extensions %s -requirement-machine-inferred-signatures=on | %FileCheck %s
1+
// RUN: %target-swift-frontend -module-name Test -typecheck -emit-module-interface-path - %s -requirement-machine-inferred-signatures=on | %FileCheck %s
22

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

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)