Skip to content

Commit 0af7032

Browse files
committed
[AST] Mark parameter declarations as caller isolated
When `nonisolated(nonsending)` parameter specifier is present mark the declaration as caller isolated. (cherry picked from commit 9bc96d4)
1 parent 8504b7f commit 0af7032

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
@@ -6911,6 +6911,9 @@ class ParamDecl : public VarDecl {
69116911

69126912
/// Whether or not this parameter is 'sending'.
69136913
IsSending = 1 << 4,
6914+
6915+
/// Whether or not this parameter is isolated to a caller.
6916+
IsCallerIsolated = 1 << 5,
69146917
};
69156918

69166919
/// The type repr and 3 bits used for flags.
@@ -7199,6 +7202,18 @@ class ParamDecl : public VarDecl {
71997202
removeFlag(Flag::IsSending);
72007203
}
72017204

7205+
/// Whether or not this parameter is marked with 'nonisolated(nonsending)'.
7206+
bool isCallerIsolated() const {
7207+
return getOptions().contains(Flag::IsCallerIsolated);
7208+
}
7209+
7210+
void setCallerIsolated(bool value = true) {
7211+
if (value)
7212+
addFlag(Flag::IsCallerIsolated);
7213+
else
7214+
removeFlag(Flag::IsCallerIsolated);
7215+
}
7216+
72027217
/// Whether or not this parameter is marked with '@_addressable'.
72037218
bool isAddressable() const {
72047219
return getOptions().contains(Flag::IsAddressable);

lib/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9010,6 +9010,12 @@ void ParamDecl::setTypeRepr(TypeRepr *repr) {
90109010
continue;
90119011
}
90129012

9013+
if (auto *callerIsolated =
9014+
dyn_cast<CallerIsolatedTypeRepr>(unwrappedType)) {
9015+
setCallerIsolated(true);
9016+
unwrappedType = callerIsolated->getBase();
9017+
}
9018+
90139019
break;
90149020
}
90159021
}
@@ -11095,6 +11101,9 @@ AccessorDecl *AccessorDecl::createParsed(
1109511101
if (subscriptParam->isSending())
1109611102
param->setSending();
1109711103

11104+
if (subscriptParam->isCallerIsolated())
11105+
param->setCallerIsolated();
11106+
1109811107
newParams.push_back(param);
1109911108
}
1110011109

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,7 @@ class DeclDeserializer {
41174117
bool isIsolated;
41184118
bool isCompileTimeLiteral, isConstValue;
41194119
bool isSending;
4120+
bool isCallerIsolated;
41204121
uint8_t rawDefaultArg;
41214122
TypeID defaultExprType;
41224123
uint8_t rawDefaultArgIsolation;
@@ -4129,6 +4130,7 @@ class DeclDeserializer {
41294130
isCompileTimeLiteral,
41304131
isConstValue,
41314132
isSending,
4133+
isCallerIsolated,
41324134
rawDefaultArg,
41334135
defaultExprType,
41344136
rawDefaultArgIsolation,
@@ -4174,6 +4176,7 @@ class DeclDeserializer {
41744176
param->setCompileTimeLiteral(isCompileTimeLiteral);
41754177
param->setConstValue(isConstValue);
41764178
param->setSending(isSending);
4179+
param->setCallerIsolated(isCallerIsolated);
41774180

41784181
// Decode the default argument kind.
41794182
// 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 = 937; // remove @execution attr
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 938; // `isCallerIsolated` parameter flag
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -1733,6 +1733,7 @@ namespace decls_block {
17331733
BCFixed<1>, // isCompileTimeLiteral?
17341734
BCFixed<1>, // isConst?
17351735
BCFixed<1>, // isSending?
1736+
BCFixed<1>, // isCallerIsolated?
17361737
DefaultArgumentField, // default argument kind
17371738
TypeIDField, // default argument type
17381739
ActorIsolationField, // default argument isolation

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4750,6 +4750,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
47504750
param->isCompileTimeLiteral(),
47514751
param->isConstVal(),
47524752
param->isSending(),
4753+
param->isCallerIsolated(),
47534754
getRawStableDefaultArgumentKind(argKind),
47544755
S.addTypeRef(defaultExprType),
47554756
getRawStableActorIsolationKind(isolation.getKind()),

0 commit comments

Comments
 (0)