Skip to content

Commit 21a7a6c

Browse files
committed
Doug twisted my arm and convinced me that noescape was a better match for the semantics we’ll have here. NoCapture would be confusable with "this closure doesn’t have any captures, thus should be compatible with thin function types"
The attribute itself remains __'ized. Swift SVN r24113
1 parent 5cffa73 commit 21a7a6c

File tree

13 files changed

+42
-42
lines changed

13 files changed

+42
-42
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ SIMPLE_DECL_ATTR(requires_stored_property_inits, RequiresStoredPropertyInits,
149149
OnClass, 27)
150150
SIMPLE_DECL_ATTR(autoclosure, AutoClosure,
151151
OnVar|OnParam, 28)
152-
SIMPLE_DECL_ATTR(__nocapture, NoCapture,OnParam, 29)
152+
SIMPLE_DECL_ATTR(__noescape, NoEscape, OnParam, 29)
153153

154154
// Non-serialized attributes.
155155

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,8 @@ ERROR(autoclosure_function_type,attribute_parsing,none,
10661066
())
10671067
ERROR(autoclosure_function_input_nonunit,attribute_parsing,none,
10681068
"autoclosure argument type must be '()'", ())
1069-
ERROR(nocapture_function_type,attribute_parsing,none,
1070-
"'nocapture' attribute may only be applied to parameters of function type",
1069+
ERROR(noescape_function_type,attribute_parsing,none,
1070+
"'noescape' attribute may only be applied to parameters of function type",
10711071
())
10721072

10731073

include/swift/AST/Types.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,14 +1871,14 @@ class AnyFunctionType : public TypeBase {
18711871
// you'll need to adjust both the Bits field below and
18721872
// BaseType::AnyFunctionTypeBits.
18731873

1874-
// | CC |representation|isAutoClosure|noReturn|noCapture|
1875-
// |0 .. 3| 4 .. 5 | 6 | 7 | 8 |
1874+
// | CC |representation|isAutoClosure|noReturn|NoEscape|
1875+
// |0 .. 3| 4 .. 5 | 6 | 7 | 8 |
18761876
//
18771877
enum : uint16_t { CallConvMask = 0x00F };
18781878
enum : uint16_t { RepresentationMask = 0x030, RepresentationShift = 4 };
18791879
enum : uint16_t { AutoClosureMask = 0x040 };
18801880
enum : uint16_t { NoReturnMask = 0x080 };
1881-
enum : uint16_t { NoCaptureMask = 0x100 };
1881+
enum : uint16_t { NoEscapeMask = 0x100 };
18821882

18831883
uint16_t Bits;
18841884

@@ -1902,10 +1902,10 @@ class AnyFunctionType : public TypeBase {
19021902

19031903
// Constructor with no defaults.
19041904
ExtInfo(AbstractCC CC, Representation Rep, bool IsNoReturn,
1905-
bool IsAutoClosure, bool IsNoCapture)
1905+
bool IsAutoClosure, bool IsNoEscape)
19061906
: ExtInfo(CC, Rep, IsNoReturn) {
19071907
Bits |= (IsAutoClosure ? AutoClosureMask : 0);
1908-
Bits |= (IsNoCapture ? NoCaptureMask : 0);
1908+
Bits |= (IsNoEscape ? NoEscapeMask : 0);
19091909
}
19101910

19111911
explicit ExtInfo(AbstractCC CC) : Bits(0) {
@@ -1915,7 +1915,7 @@ class AnyFunctionType : public TypeBase {
19151915
AbstractCC getCC() const { return AbstractCC(Bits & CallConvMask); }
19161916
bool isNoReturn() const { return Bits & NoReturnMask; }
19171917
bool isAutoClosure() const { return Bits & AutoClosureMask; }
1918-
bool isNoCapture() const { return Bits & NoCaptureMask; }
1918+
bool isNoEscape() const { return Bits & NoEscapeMask; }
19191919
Representation getRepresentation() const {
19201920
return Representation((Bits & RepresentationMask) >> RepresentationShift);
19211921
}
@@ -1964,11 +1964,11 @@ class AnyFunctionType : public TypeBase {
19641964
else
19651965
return ExtInfo(Bits & ~AutoClosureMask);
19661966
}
1967-
ExtInfo withNoCapture(bool NoCapture) const {
1968-
if (NoCapture)
1969-
return ExtInfo(Bits | NoCaptureMask);
1967+
ExtInfo withNoEscape(bool NoEscape) const {
1968+
if (NoEscape)
1969+
return ExtInfo(Bits | NoEscapeMask);
19701970
else
1971-
return ExtInfo(Bits & ~NoCaptureMask);
1971+
return ExtInfo(Bits & ~NoEscapeMask);
19721972
}
19731973

19741974
uint16_t getFuncAttrKey() const {
@@ -2022,8 +2022,8 @@ class AnyFunctionType : public TypeBase {
20222022

20232023
/// \brief True if the parameter declaration it is attached to is guaranteed
20242024
/// to not persist the closure for longer than the duration of the call.
2025-
bool isNoCapture() const {
2026-
return getExtInfo().isNoCapture();
2025+
bool isNoEscape() const {
2026+
return getExtInfo().isNoEscape();
20272027
}
20282028

20292029

@@ -2610,8 +2610,8 @@ class SILFunctionType : public TypeBase, public llvm::FoldingSetNode {
26102610
bool isNoReturn() const {
26112611
return getExtInfo().isNoReturn();
26122612
}
2613-
bool isNoCapture() const {
2614-
return getExtInfo().isNoCapture();
2613+
bool isNoEscape() const {
2614+
return getExtInfo().isNoEscape();
26152615
}
26162616

26172617
CanSILFunctionType substGenericArgs(SILModule &silModule,

include/swift/Serialization/ModuleFormat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const uint16_t VERSION_MAJOR = 0;
5151
/// To ensure that two separate changes don't silently get merged into one
5252
/// in source control, you should also update the comment to briefly
5353
/// describe what change you made.
54-
const uint16_t VERSION_MINOR = 163; // Last change: nocapture
54+
const uint16_t VERSION_MINOR = 163; // Last change: noescape
5555

5656
using DeclID = Fixnum<31>;
5757
using DeclIDField = BCFixed<31>;
@@ -487,7 +487,7 @@ namespace decls_block {
487487
BCFixed<1>, // thin?
488488
BCFixed<1>, // noreturn?
489489
BCFixed<1>, // block-compatible?
490-
BCFixed<1> // nocapture?
490+
BCFixed<1> // noescape?
491491
>;
492492

493493
using MetatypeTypeLayout = BCRecordLayout<

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,8 +2230,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
22302230
void printFunctionExtInfo(AnyFunctionType::ExtInfo info) {
22312231
if (info.isAutoClosure())
22322232
Printer << "@autoclosure ";
2233-
if (info.isNoCapture())
2234-
Printer << "@__nocapture ";
2233+
if (info.isNoEscape())
2234+
Printer << "@__noescape ";
22352235
switch (info.getCC()) {
22362236
case AbstractCC::Freestanding: break;
22372237
case AbstractCC::Method:

lib/SIL/SILBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SILType SILBuilder::getPartialApplyResultType(SILType origTy, unsigned argCount,
3333
SILFunctionType::Representation::Thick,
3434
/*noreturn*/ FTI->isNoReturn(),
3535
/*autoclosure*/ false,
36-
/*nocapture*/ FTI->isNoCapture());
36+
/*noescape*/ FTI->isNoEscape());
3737

3838
auto appliedFnType = SILFunctionType::get(nullptr, extInfo,
3939
ParameterConvention::Direct_Owned,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
7777
void visitAutoClosureAttr(AutoClosureAttr *attr) {
7878
TC.checkAutoClosureAttr(cast<VarDecl>(D), attr);
7979
}
80-
void visitNoCaptureAttr(NoCaptureAttr *attr) {
81-
TC.checkNoCaptureAttr(cast<ParamDecl>(D), attr);
80+
void visitNoEscapeAttr(NoEscapeAttr *attr) {
81+
TC.checkNoEscapeAttr(cast<ParamDecl>(D), attr);
8282
}
8383

8484
void visitTransparentAttr(TransparentAttr *attr);
@@ -549,7 +549,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
549549
IGNORED_ATTR(Lazy) // checked early.
550550
IGNORED_ATTR(LLDBDebuggerFunction)
551551
IGNORED_ATTR(Mutating)
552-
IGNORED_ATTR(NoCapture)
552+
IGNORED_ATTR(NoEscape)
553553
IGNORED_ATTR(NonMutating)
554554
IGNORED_ATTR(NoReturn)
555555
IGNORED_ATTR(NSManaged) // checked early.
@@ -1120,9 +1120,9 @@ void TypeChecker::checkTypeModifyingDeclAttributes(VarDecl *var) {
11201120
checkOwnershipAttr(var, attr);
11211121
if (auto *attr = var->getAttrs().getAttribute<AutoClosureAttr>())
11221122
checkAutoClosureAttr(var, attr);
1123-
if (auto *attr = var->getAttrs().getAttribute<NoCaptureAttr>()) {
1123+
if (auto *attr = var->getAttrs().getAttribute<NoEscapeAttr>()) {
11241124
if (auto *pd = dyn_cast<ParamDecl>(var))
1125-
checkNoCaptureAttr(pd, attr);
1125+
checkNoEscapeAttr(pd, attr);
11261126
else {
11271127
AttributeEarlyChecker Checker(*this, var);
11281128
Checker.diagnoseAndRemoveAttr(attr, diag::attr_only_only_one_decl_kind,
@@ -1159,22 +1159,22 @@ void TypeChecker::checkAutoClosureAttr(VarDecl *VD, AutoClosureAttr *attr) {
11591159
FTy->getExtInfo().withIsAutoClosure(true)));
11601160
}
11611161

1162-
void TypeChecker::checkNoCaptureAttr(ParamDecl *PD, NoCaptureAttr *attr) {
1162+
void TypeChecker::checkNoEscapeAttr(ParamDecl *PD, NoEscapeAttr *attr) {
11631163
// The paramdecl should have function type.
11641164
auto *FTy = PD->getType()->getAs<FunctionType>();
11651165
if (FTy == 0) {
1166-
diagnose(attr->getLocation(), diag::nocapture_function_type);
1166+
diagnose(attr->getLocation(), diag::noescape_function_type);
11671167
attr->setInvalid();
11681168
return;
11691169
}
11701170

11711171
// Just stop if we've already applied this attribute.
1172-
if (FTy->isNoCapture())
1172+
if (FTy->isNoEscape())
11731173
return;
11741174

11751175
// Change the type to include the autoclosure bit.
11761176
PD->overwriteType(FunctionType::get(FTy->getInput(), FTy->getResult(),
1177-
FTy->getExtInfo().withNoCapture(true)));
1177+
FTy->getExtInfo().withNoEscape(true)));
11781178
}
11791179

11801180

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4632,9 +4632,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
46324632
TC.diagnose(Base, diag::overridden_here);
46334633
}
46344634
}
4635-
void visitNoCaptureAttr(NoCaptureAttr *attr) {
4636-
if (Base->getAttrs().hasAttribute<NoCaptureAttr>() !=
4637-
Override->getAttrs().hasAttribute<NoCaptureAttr>()) {
4635+
void visitNoEscapeAttr(NoEscapeAttr *attr) {
4636+
if (Base->getAttrs().hasAttribute<NoEscapeAttr>() !=
4637+
Override->getAttrs().hasAttribute<NoEscapeAttr>()) {
46384638
TC.diagnose(Override, diag::inconsistent_attribute_override,
46394639
attr->getAttrName());
46404640
TC.diagnose(Base, diag::overridden_here);

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
12071207
rep,
12081208
attrs.has(TAK_noreturn),
12091209
/*autoclosure is a decl attr*/false,
1210-
/*nocapture is a decl attr*/false);
1210+
/*noescape is a decl attr*/false);
12111211

12121212
auto calleeConvention = ParameterConvention::Direct_Unowned;
12131213
if (attrs.has(TAK_callee_owned)) {

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ class TypeChecker final : public LazyResolver {
560560
void checkTypeModifyingDeclAttributes(VarDecl *var);
561561

562562
void checkAutoClosureAttr(VarDecl *D, AutoClosureAttr *attr);
563-
void checkNoCaptureAttr(ParamDecl *D, NoCaptureAttr *attr);
563+
void checkNoEscapeAttr(ParamDecl *D, NoEscapeAttr *attr);
564564
void checkOwnershipAttr(VarDecl *D, OwnershipAttr *attr);
565565

566566
void computeAccessibility(ValueDecl *D);

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,14 +2988,14 @@ Type ModuleFile::getType(TypeID TID) {
29882988
TypeID inputID;
29892989
TypeID resultID;
29902990
uint8_t rawCallingConvention;
2991-
bool autoClosure, thin, noreturn, blockCompatible, nocapture;
2991+
bool autoClosure, thin, noreturn, blockCompatible, noescape;
29922992

29932993
decls_block::FunctionTypeLayout::readRecord(scratch, inputID, resultID,
29942994
rawCallingConvention,
29952995
autoClosure, thin,
29962996
noreturn,
29972997
blockCompatible,
2998-
nocapture);
2998+
noescape);
29992999
auto callingConvention = getActualCC(rawCallingConvention);
30003000
if (!callingConvention.hasValue()) {
30013001
error();
@@ -3004,7 +3004,7 @@ Type ModuleFile::getType(TypeID TID) {
30043004

30053005
auto Info = FunctionType::ExtInfo(callingConvention.getValue(),
30063006
getFunctionRepresentation(thin, blockCompatible),
3007-
noreturn, autoClosure, nocapture);
3007+
noreturn, autoClosure, noescape);
30083008

30093009
typeOrOffset = FunctionType::get(getType(inputID), getType(resultID),
30103010
Info);

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ void Serializer::writeType(Type ty) {
23812381
fnTy->getRepresentation() == AnyFunctionType::Representation::Thin,
23822382
fnTy->isNoReturn(),
23832383
fnTy->getRepresentation() == AnyFunctionType::Representation::Block,
2384-
fnTy->isNoCapture());
2384+
fnTy->isNoEscape());
23852385
break;
23862386
}
23872387

test/attr/attr_nocapture.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %swift -parse %s -verify
22

3-
@__nocapture var fn : () -> Int = { 4 } // expected-error {{'__nocapture' may only be used on 'parameter' declarations}}
3+
@__noescape var fn : () -> Int = { 4 } // expected-error {{'__noescape' may only be used on 'parameter' declarations}}
44

5-
func f(@__nocapture fn : () -> Int) {
5+
func f(@__noescape fn : () -> Int) {
66
f { 4 } // ok
77
}
88

0 commit comments

Comments
 (0)