Skip to content

Commit 9bc96d4

Browse files
committed
[AST] Mark parameter declarations as caller isolated
When `nonisolated(nonsending)` parameter specifier is present mark the declaration as caller isolated.
1 parent 7ce06dd commit 9bc96d4

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

include/swift/AST/Decl.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6902,6 +6902,9 @@ class ParamDecl : public VarDecl {
69026902

69036903
/// Whether or not this parameter is 'sending'.
69046904
IsSending = 1 << 4,
6905+
6906+
/// Whether or not this parameter is isolated to a caller.
6907+
IsCallerIsolated = 1 << 5,
69056908
};
69066909

69076910
/// The type repr and 3 bits used for flags.
@@ -7190,6 +7193,18 @@ class ParamDecl : public VarDecl {
71907193
removeFlag(Flag::IsSending);
71917194
}
71927195

7196+
/// Whether or not this parameter is marked with 'nonisolated(nonsending)'.
7197+
bool isCallerIsolated() const {
7198+
return getOptions().contains(Flag::IsCallerIsolated);
7199+
}
7200+
7201+
void setCallerIsolated(bool value = true) {
7202+
if (value)
7203+
addFlag(Flag::IsCallerIsolated);
7204+
else
7205+
removeFlag(Flag::IsCallerIsolated);
7206+
}
7207+
71937208
/// Whether or not this parameter is marked with '@_addressable'.
71947209
bool isAddressable() const {
71957210
return getOptions().contains(Flag::IsAddressable);

lib/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8940,6 +8940,12 @@ void ParamDecl::setTypeRepr(TypeRepr *repr) {
89408940
continue;
89418941
}
89428942

8943+
if (auto *callerIsolated =
8944+
dyn_cast<CallerIsolatedTypeRepr>(unwrappedType)) {
8945+
setCallerIsolated(true);
8946+
unwrappedType = callerIsolated->getBase();
8947+
}
8948+
89438949
break;
89448950
}
89458951
}
@@ -11025,6 +11031,9 @@ AccessorDecl *AccessorDecl::createParsed(
1102511031
if (subscriptParam->isSending())
1102611032
param->setSending();
1102711033

11034+
if (subscriptParam->isCallerIsolated())
11035+
param->setCallerIsolated();
11036+
1102811037
newParams.push_back(param);
1102911038
}
1103011039

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,6 +4110,7 @@ class DeclDeserializer {
41104110
bool isIsolated;
41114111
bool isCompileTimeLiteral, isConstValue;
41124112
bool isSending;
4113+
bool isCallerIsolated;
41134114
uint8_t rawDefaultArg;
41144115
TypeID defaultExprType;
41154116
uint8_t rawDefaultArgIsolation;
@@ -4122,6 +4123,7 @@ class DeclDeserializer {
41224123
isCompileTimeLiteral,
41234124
isConstValue,
41244125
isSending,
4126+
isCallerIsolated,
41254127
rawDefaultArg,
41264128
defaultExprType,
41274129
rawDefaultArgIsolation,
@@ -4167,6 +4169,7 @@ class DeclDeserializer {
41674169
param->setCompileTimeLiteral(isCompileTimeLiteral);
41684170
param->setConstValue(isConstValue);
41694171
param->setSending(isSending);
4172+
param->setCallerIsolated(isCallerIsolated);
41704173

41714174
// Decode the default argument kind.
41724175
// FIXME: Default argument expression, if available.

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 941; // remove @execution attr
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 942; // `isCallerIsolated` parameter flag
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -1728,6 +1728,7 @@ namespace decls_block {
17281728
BCFixed<1>, // isCompileTimeLiteral?
17291729
BCFixed<1>, // isConst?
17301730
BCFixed<1>, // isSending?
1731+
BCFixed<1>, // isCallerIsolated?
17311732
DefaultArgumentField, // default argument kind
17321733
TypeIDField, // default argument type
17331734
ActorIsolationField, // default argument isolation

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,6 +4745,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
47454745
param->isCompileTimeLiteral(),
47464746
param->isConstVal(),
47474747
param->isSending(),
4748+
param->isCallerIsolated(),
47484749
getRawStableDefaultArgumentKind(argKind),
47494750
S.addTypeRef(defaultExprType),
47504751
getRawStableActorIsolationKind(isolation.getKind()),

0 commit comments

Comments
 (0)