Skip to content

Commit 1f521cd

Browse files
committed
Add -experimental-feature NonEscapableTypes
1 parent ca7253a commit 1f521cd

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7536,6 +7536,9 @@ ERROR(noncopyable_cannot_have_read_set_accessor,none,
75367536
"noncopyable %select{variable|subscript}0 cannot provide a read and set accessor",
75377537
(unsigned))
75387538

7539+
ERROR(nonescapable_types_attr_disabled,none,
7540+
"attribute requires '-enable-experimental-feature NonEscapableTypes'", ())
7541+
75397542
//------------------------------------------------------------------------------
75407543
// MARK: Init accessors
75417544
//------------------------------------------------------------------------------

include/swift/Basic/Features.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ EXPERIMENTAL_FEATURE(TypedThrows, true)
252252
/// Allow destructuring stored `let` bindings in structs.
253253
EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
254254

255+
/// Enable non-escapable type attributes and function attributes that support
256+
/// lifetime-dependent results.
257+
EXPERIMENTAL_FEATURE(NonEscapableTypes, false)
258+
255259
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
256260
#undef EXPERIMENTAL_FEATURE
257261
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,6 +3512,11 @@ static bool usesFeatureStructLetDestructuring(Decl *decl) {
35123512
return false;
35133513
}
35143514

3515+
static bool usesFeatureNonEscapableTypes(Decl *decl) {
3516+
return decl->getAttrs().hasAttribute<NonEscapableAttr>()
3517+
|| decl->getAttrs().hasAttribute<UnsafeNonEscapableResultAttr>();
3518+
}
3519+
35153520
static bool hasParameterPacks(Decl *decl) {
35163521
if (auto genericContext = decl->getAsGenericContext()) {
35173522
auto sig = genericContext->getGenericSignature();

lib/Sema/TypeCheckAttr.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
161161
IGNORED_ATTR(BackDeployed)
162162
IGNORED_ATTR(Documentation)
163163
IGNORED_ATTR(LexicalLifetimes)
164-
IGNORED_ATTR(NonEscapable)
165-
IGNORED_ATTR(UnsafeNonEscapableResult)
166164
#undef IGNORED_ATTR
167165

168166
void visitAlignmentAttr(AlignmentAttr *attr) {
@@ -349,6 +347,9 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
349347
void visitMacroRoleAttr(MacroRoleAttr *attr);
350348

351349
void visitRawLayoutAttr(RawLayoutAttr *attr);
350+
351+
void visitNonEscapableAttr(NonEscapableAttr *attr);
352+
void visitUnsafeNonEscapableResultAttr(UnsafeNonEscapableResultAttr *attr);
352353
};
353354

354355
} // end anonymous namespace
@@ -7060,6 +7061,19 @@ void AttributeChecker::visitRawLayoutAttr(RawLayoutAttr *attr) {
70607061
sd->setHasUnreferenceableStorage(true);
70617062
}
70627063

7064+
void AttributeChecker::visitNonEscapableAttr(NonEscapableAttr *attr) {
7065+
if (!Ctx.LangOpts.hasFeature(Feature::NonEscapableTypes)) {
7066+
diagnoseAndRemoveAttr(attr, diag::nonescapable_types_attr_disabled);
7067+
}
7068+
}
7069+
7070+
void AttributeChecker::visitUnsafeNonEscapableResultAttr(
7071+
UnsafeNonEscapableResultAttr *attr) {
7072+
if (!Ctx.LangOpts.hasFeature(Feature::NonEscapableTypes)) {
7073+
diagnoseAndRemoveAttr(attr, diag::nonescapable_types_attr_disabled);
7074+
}
7075+
}
7076+
70637077
namespace {
70647078

70657079
class ClosureAttributeChecker

test/attr/attr_nonEscapable.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-feature NonEscapableTypes
22

33
@_nonEscapable public struct NES {
44
let x: Int

0 commit comments

Comments
 (0)