Skip to content

Commit 31aafc7

Browse files
authored
Merge pull request #41131 from hborla/5.6-disable-se-0309
[5.6][SE-0309] Disable SE-0309 in Swift 5.6.
2 parents e744f41 + 0d2d249 commit 31aafc7

18 files changed

+71
-42
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4647,6 +4647,9 @@ ERROR(unchecked_not_inheritance_clause,none,
46474647
ERROR(unchecked_not_existential,none,
46484648
"'unchecked' attribute cannot apply to non-protocol type %0", (Type))
46494649

4650+
ERROR(unsupported_existential_type,none,
4651+
"protocol %0 can only be used as a generic constraint because it has "
4652+
"Self or associated type requirements", (Identifier))
46504653
ERROR(any_not_existential,none,
46514654
"'any' has no effect on %select{concrete type|type parameter}0 %1",
46524655
(bool, Type))

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ namespace swift {
317317
/// keyword.
318318
bool EnableExplicitExistentialTypes = true;
319319

320+
/// Enable experimental support for universal existential types
321+
/// as proposed in SE-0309.
322+
bool EnableExperimentalUniversalExistentials = false;
323+
320324
/// Enable experimental flow-sensitive concurrent captures.
321325
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;
322326

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ def enable_explicit_existential_types :
486486
Flag<["-"], "enable-explicit-existential-types">,
487487
HelpText<"Enable experimental support for explicit existential types">;
488488

489+
def enable_experimental_universal_existentials :
490+
Flag<["-"], "enable-experimental-universal-existentials">,
491+
HelpText<"Enable experimental support for universal existential types">;
492+
489493
def enable_deserialization_recovery :
490494
Flag<["-"], "enable-deserialization-recovery">,
491495
HelpText<"Attempt to recover from missing xrefs (etc) in swiftmodules">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
441441
Opts.EnableExplicitExistentialTypes |=
442442
Args.hasArg(OPT_enable_explicit_existential_types);
443443

444+
Opts.EnableExperimentalUniversalExistentials |=
445+
Args.hasArg(OPT_enable_experimental_universal_existentials);
446+
444447
Opts.EnableExperimentalDistributed |=
445448
Args.hasArg(OPT_enable_experimental_distributed);
446449

lib/Sema/TypeCheckType.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3966,7 +3966,8 @@ class ExistentialTypeVisitor
39663966
return false;
39673967

39683968
// Arbitrary protocol constraints are okay for 'any' types.
3969-
if (isa<ExistentialTypeRepr>(T))
3969+
if (Ctx.LangOpts.EnableExperimentalUniversalExistentials &&
3970+
isa<ExistentialTypeRepr>(T))
39703971
return false;
39713972

39723973
visit(T);
@@ -3991,16 +3992,23 @@ class ExistentialTypeVisitor
39913992
}
39923993

39933994
void visitIdentTypeRepr(IdentTypeRepr *T) {
3994-
if (T->isInvalid() || !Ctx.LangOpts.EnableExplicitExistentialTypes)
3995+
if (T->isInvalid())
39953996
return;
39963997

39973998
auto comp = T->getComponentRange().back();
39983999
if (auto *proto = dyn_cast_or_null<ProtocolDecl>(comp->getBoundDecl())) {
39994000
if (proto->existentialRequiresAny()) {
4000-
Ctx.Diags.diagnose(comp->getNameLoc(),
4001-
diag::existential_requires_any,
4002-
proto->getName())
4003-
.limitBehavior(DiagnosticBehavior::Warning);
4001+
if (!Ctx.LangOpts.EnableExperimentalUniversalExistentials) {
4002+
Ctx.Diags.diagnose(comp->getNameLoc(),
4003+
diag::unsupported_existential_type,
4004+
proto->getName());
4005+
T->setInvalid();
4006+
} else if (Ctx.LangOpts.EnableExplicitExistentialTypes) {
4007+
Ctx.Diags.diagnose(comp->getNameLoc(),
4008+
diag::existential_requires_any,
4009+
proto->getName())
4010+
.limitBehavior(DiagnosticBehavior::Warning);
4011+
}
40044012
}
40054013
} else if (auto *alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl())) {
40064014
auto type = Type(alias->getDeclaredInterfaceType()->getDesugaredType());
@@ -4014,10 +4022,17 @@ class ExistentialTypeVisitor
40144022
if (!protoDecl->existentialRequiresAny())
40154023
continue;
40164024

4017-
Ctx.Diags.diagnose(comp->getNameLoc(),
4018-
diag::existential_requires_any,
4019-
protoDecl->getName())
4020-
.limitBehavior(DiagnosticBehavior::Warning);
4025+
if (!Ctx.LangOpts.EnableExperimentalUniversalExistentials) {
4026+
Ctx.Diags.diagnose(comp->getNameLoc(),
4027+
diag::unsupported_existential_type,
4028+
protoDecl->getName());
4029+
T->setInvalid();
4030+
} else if (Ctx.LangOpts.EnableExplicitExistentialTypes) {
4031+
Ctx.Diags.diagnose(comp->getNameLoc(),
4032+
diag::existential_requires_any,
4033+
protoDecl->getName())
4034+
.limitBehavior(DiagnosticBehavior::Warning);
4035+
}
40214036
}
40224037
}
40234038
return false;

test/Generics/function_defs.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
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-universal-existentials
22

33
//===----------------------------------------------------------------------===//
44
// Type-check function definitions

test/decl/nested/protocol.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 -parse-as-library
1+
// RUN: %target-typecheck-verify-swift -parse-as-library -enable-experimental-universal-existentials
22

33
// Protocols cannot be nested inside other types, and types cannot
44
// be nested inside protocols

test/decl/protocol/conforms/inherited.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
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-universal-existentials
22

33
// Inheritable: method with 'Self' in contravariant position.
44
protocol P1 {

test/decl/protocol/protocols.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-objc-interop
1+
// RUN: %target-typecheck-verify-swift -enable-objc-interop -enable-experimental-universal-existentials
22
protocol EmptyProtocol { }
33

44
protocol DefinitionsInProtocols {

test/decl/protocol/protocols_with_self_or_assoc_reqs.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 -disable-availability-checking
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-universal-existentials
22

33
//===----------------------------------------------------------------------===//
44
// Use of protocols with Self or associated type requirements

test/decl/protocol/recursive_requirement.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
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-universal-existentials
22

33
// -----
44

test/stmt/foreach.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
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-universal-existentials
22

33
// Bad containers and ranges
44
struct BadContainer1 {

test/type/explicit_existential.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
protocol HasSelfRequirements {
44
func foo(_ x: Self)
55

6-
func returnsOwnProtocol() -> any HasSelfRequirements
6+
func returnsOwnProtocol() -> HasSelfRequirements // expected-error {{protocol 'HasSelfRequirements' can only be used as a generic constraint because it has Self or associated type requirements}}
77
}
88
protocol Bar {
99
init()
@@ -35,10 +35,10 @@ func useCompoAsWhereRequirement<T>(_ x: T) where T: HasSelfRequirements & Bar {}
3535
func useCompoAliasAsWhereRequirement<T>(_ x: T) where T: Compo {}
3636
func useNestedCompoAliasAsWhereRequirement<T>(_ x: T) where T: CompoAssocType.Compo {}
3737

38-
func useAsType(_: any HasSelfRequirements,
39-
_: any HasSelfRequirements & Bar,
40-
_: any Compo,
41-
_: any CompoAssocType.Compo) { }
38+
func useAsType(_: any HasSelfRequirements, // expected-error {{protocol 'HasSelfRequirements' can only be used as a generic constraint because it has Self or associated type requirements}}
39+
_: any HasSelfRequirements & Bar, // expected-error {{protocol 'HasSelfRequirements' can only be used as a generic constraint because it has Self or associated type requirements}}
40+
_: any Compo, // expected-error {{protocol 'HasSelfRequirements' can only be used as a generic constraint because it has Self or associated type requirements}}
41+
_: any CompoAssocType.Compo) { } // expected-error {{protocol 'HasSelfRequirements' can only be used as a generic constraint because it has Self or associated type requirements}}
4242

4343
struct TypeRequirement<T: HasSelfRequirements> {}
4444
struct CompoTypeRequirement<T: HasSelfRequirements & Bar> {}
@@ -66,7 +66,7 @@ do {
6666

6767
func checkIt(_ js: Any) throws {
6868
switch js {
69-
case let dbl as any HasAssoc:
69+
case let dbl as any HasAssoc: // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
7070
throw MyError.bad(dbl)
7171

7272
default:
@@ -75,25 +75,25 @@ do {
7575
}
7676
}
7777

78-
func testHasAssoc(_ x: Any, _: any HasAssoc) {
79-
if let p = x as? any HasAssoc {
78+
func testHasAssoc(_ x: Any, _: any HasAssoc) { // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
79+
if let p = x as? any HasAssoc { // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
8080
p.foo()
8181
}
8282

8383
struct ConformingType : HasAssoc {
8484
typealias Assoc = Int
8585
func foo() {}
8686

87-
func method() -> any HasAssoc {}
87+
func method() -> any HasAssoc {} // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
8888
}
8989
}
9090

91-
var b: any HasAssoc
91+
var b: any HasAssoc // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
9292

9393
protocol P {}
9494
typealias MoreHasAssoc = HasAssoc & P
9595
func testHasMoreAssoc(_ x: Any) {
96-
if let p = x as? any MoreHasAssoc {
96+
if let p = x as? any MoreHasAssoc { // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
9797
p.foo()
9898
}
9999
}
@@ -102,36 +102,36 @@ typealias X = Struct1<any Pub & Bar>
102102
_ = Struct1<any Pub & Bar>.self
103103

104104
typealias AliasWhere<T> = T
105-
where T: HasAssoc, T.Assoc == any HasAssoc
105+
where T: HasAssoc, T.Assoc == any HasAssoc // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
106106

107107
struct StructWhere<T>
108108
where T: HasAssoc,
109-
T.Assoc == any HasAssoc {}
109+
T.Assoc == any HasAssoc {} // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
110110

111-
protocol ProtocolWhere where T == any HasAssoc {
111+
protocol ProtocolWhere where T == any HasAssoc { // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
112112
associatedtype T
113113

114114
associatedtype U: HasAssoc
115-
where U.Assoc == any HasAssoc
115+
where U.Assoc == any HasAssoc // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
116116
}
117117

118-
extension HasAssoc where Assoc == any HasAssoc {}
118+
extension HasAssoc where Assoc == any HasAssoc {} // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
119119

120120
func FunctionWhere<T>(_: T)
121121
where T : HasAssoc,
122-
T.Assoc == any HasAssoc {}
122+
T.Assoc == HasAssoc {} // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
123123

124124
struct SubscriptWhere {
125125
subscript<T>(_: T) -> Int
126126
where T : HasAssoc,
127-
T.Assoc == any HasAssoc {
127+
T.Assoc == HasAssoc { // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
128128
get {}
129129
set {}
130130
}
131131
}
132132

133133
struct OuterGeneric<T> {
134-
func contextuallyGenericMethod() where T == any HasAssoc {}
134+
func contextuallyGenericMethod() where T == HasAssoc {} // expected-error {{protocol 'HasAssoc' can only be used as a generic constraint because it has Self or associated type requirements}}
135135
}
136136

137137
func testInvalidAny() {

test/type/protocol_types.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
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-universal-existentials
22

33
protocol HasSelfRequirements {
44
func foo(_ x: Self)

utils/build-windows-toolchain.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ cmake ^
192192
-D LLVM_VERSION_SUFFIX="" ^
193193

194194
-D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=YES ^
195-
-D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=YES ^
195+
-D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=NO ^
196196
-D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=YES ^
197197
-D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=YES ^
198198

@@ -229,7 +229,7 @@ cmake ^
229229
-D SWIFT_PATH_TO_LIBDISPATCH_SOURCE=%SourceRoot%\swift-corelibs-libdispatch ^
230230

231231
-D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=YES ^
232-
-D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=YES ^
232+
-D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=NO ^
233233
-D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=YES ^
234234
-D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=YES ^
235235

utils/build-windows.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ cmake^
265265
-DSWIFT_BUILD_SOURCEKIT:BOOL=YES^
266266
-DSWIFT_ENABLE_SOURCEKIT_TESTS:BOOL=YES^
267267
-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=YES^
268-
-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=YES^
268+
-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=NO^
269269
-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=YES^
270270
-DSWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=YES^
271271
-DSWIFT_INSTALL_COMPONENTS="autolink-driver;compiler;clang-resource-dir-symlink;stdlib;sdk-overlay;editor-integration;tools;testsuite-tools;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers"^

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ def create_argument_parser():
11881188
help='Enable experimental Swift concurrency model.')
11891189

11901190
option('--enable-experimental-distributed', toggle_true,
1191-
default=True,
1191+
default=False,
11921192
help='Enable experimental Swift distributed actors.')
11931193

11941194
option('--enable-experimental-string-processing', toggle_true,

utils/build_swift/tests/expected_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
'enable_asan': False,
145145
'enable_experimental_differentiable_programming': True,
146146
'enable_experimental_concurrency': True,
147-
'enable_experimental_distributed': True,
147+
'enable_experimental_distributed': False,
148148
'enable_experimental_string_processing': True,
149149
'enable_lsan': False,
150150
'enable_sanitize_coverage': False,

0 commit comments

Comments
 (0)