Skip to content

Commit 5348ee9

Browse files
committed
prevent uses of Escapable in general
This protocol appears in the stdlib as scaffolding for the `NonescapableTypes` feature, which is still experimental and not gone through evolution as an approved addition to the stdlib. Rather than delete it from the stdlib, because it needs to still remain to support that feature work, gate references to it behind a feature flag. Additionally, prevent documentation from seeing this declaration. rdar://126705184 (cherry picked from commit 7ffe96a)
1 parent d68a494 commit 5348ee9

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7665,7 +7665,7 @@ NOTE(add_explicit_protocol_for_conformance,none,
76657665
"consider making %kind0 explicitly conform to the '%1' protocol",
76667666
(const ValueDecl *, StringRef))
76677667
ERROR(escapable_requires_feature_flag,none,
7668-
"type '~Escapable' requires -enable-experimental-feature NonescapableTypes",
7668+
"type 'Escapable' requires -enable-experimental-feature NonescapableTypes",
76697669
())
76707670
ERROR(non_bitwise_copyable_type_class,none,
76717671
"class cannot conform to 'BitwiseCopyable'", ())

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ class CheckRepressions {
124124
auto ipk = getInvertibleProtocolKind(*kp);
125125
if (ipk) {
126126
// Gate the '~Escapable' type behind a specific flag for now.
127+
// Uses of 'Escapable' itself are already diagnosed; return ErrorType.
127128
if (*ipk == InvertibleProtocolKind::Escapable &&
128129
!ctx.LangOpts.hasFeature(Feature::NonescapableTypes)) {
129-
diagnoseInvalid(repr, repr.getLoc(),
130-
diag::escapable_requires_feature_flag);
131130
return ErrorType::get(ctx);
132131
}
133132

lib/Sema/TypeCheckType.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,6 +4770,20 @@ TypeResolver::resolveDeclRefTypeRepr(DeclRefTypeRepr *repr,
47704770
auto *dc = getDeclContext();
47714771
auto &ctx = getASTContext();
47724772

4773+
// Gate the 'Escapable' type behind a specific flag for now.
4774+
//
4775+
// NOTE: we do not return an ErrorType, though! We're just artificially
4776+
// preventing people from referring to the type without the feature.
4777+
if (auto proto = result->getAs<ProtocolType>()) {
4778+
if (auto known = proto->getKnownProtocol()) {
4779+
if (*known == KnownProtocolKind::Escapable
4780+
&& !ctx.LangOpts.hasFeature(Feature::NonescapableTypes)) {
4781+
diagnoseInvalid(repr, repr->getLoc(),
4782+
diag::escapable_requires_feature_flag);
4783+
}
4784+
}
4785+
}
4786+
47734787
if (ctx.LangOpts.hasFeature(Feature::ImplicitSome) &&
47744788
options.isConstraintImplicitExistential()) {
47754789
// Check whether this type is an implicit opaque result type.
@@ -5774,10 +5788,9 @@ NeverNullType TypeResolver::resolveInverseType(InverseTypeRepr *repr,
57745788
if (auto kind = getInvertibleProtocolKind(*kp)) {
57755789

57765790
// Gate the '~Escapable' type behind a specific flag for now.
5791+
// Uses of 'Escapable' itself are already diagnosed; return ErrorType.
57775792
if (*kind == InvertibleProtocolKind::Escapable &&
57785793
!getASTContext().LangOpts.hasFeature(Feature::NonescapableTypes)) {
5779-
diagnoseInvalid(repr, repr->getLoc(),
5780-
diag::escapable_requires_feature_flag);
57815794
return wrapInExistential(ErrorType::get(getASTContext()));
57825795
}
57835796

stdlib/public/core/Misc.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func _rethrowsViaClosure(_ fn: () throws -> ()) rethrows {
171171

172172
@_marker public protocol Copyable {}
173173

174+
@_documentation(visibility: internal)
174175
@_marker public protocol Escapable {}
175176

176177
#if $NoncopyableGenerics && $NonescapableTypes

test/Parse/inverse_escapable_feature.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33

44

5-
struct S: ~Escapable {} // expected-error {{type '~Escapable' requires -enable-experimental-feature NonescapableTypes}}
5+
struct S: ~Escapable {} // expected-error {{type 'Escapable' requires -enable-experimental-feature NonescapableTypes}}
6+
7+
func hello(_ t: some Escapable, _ u: any Escapable) {} // expected-error 2{{type 'Escapable' requires -enable-experimental-feature NonescapableTypes}}
8+
9+
protocol Whatever: Escapable {} // expected-error {{type 'Escapable' requires -enable-experimental-feature NonescapableTypes}}

test/Parse/inverses_legacy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
protocol Sando { func make() } // expected-note {{protocol requires function 'make()'}}
66
// expected-note@-1 {{type 'U' does not conform to inherited protocol 'Copyable'}}
77

8-
struct BuggerView: ~Escapable {} // expected-error {{can only suppress 'Copyable'}}
8+
struct BuggerView: ~Escapable {} // expected-error {{can only suppress 'Copyable'}} // expected-error {{type 'Escapable' requires -enable-experimental-feature NonescapableTypes}}
99

1010
struct S: ~U, // expected-error {{can only suppress 'Copyable'}}
1111
// expected-error@-1 {{inheritance from non-protocol type 'U'}}

0 commit comments

Comments
 (0)