Skip to content

Commit bab9189

Browse files
authored
Merge pull request #39835 from DougGregor/isolated-params-serialization
Properly serialize 'isolated' bit on function parameter declarations.
2 parents 5d0bfee + 8dbfb04 commit bab9189

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3145,12 +3145,14 @@ class DeclDeserializer {
31453145
bool isIUO;
31463146
bool isVariadic;
31473147
bool isAutoClosure;
3148+
bool isIsolated;
31483149
uint8_t rawDefaultArg;
31493150

31503151
decls_block::ParamLayout::readRecord(scratch, argNameID, paramNameID,
31513152
contextID, rawSpecifier,
31523153
interfaceTypeID, isIUO, isVariadic,
3153-
isAutoClosure, rawDefaultArg);
3154+
isAutoClosure, isIsolated,
3155+
rawDefaultArg);
31543156

31553157
auto argName = MF.getIdentifier(argNameID);
31563158
auto paramName = MF.getIdentifier(paramNameID);
@@ -3184,6 +3186,7 @@ class DeclDeserializer {
31843186
param->setImplicitlyUnwrappedOptional(isIUO);
31853187
param->setVariadic(isVariadic);
31863188
param->setAutoClosure(isAutoClosure);
3189+
param->setIsolated(isIsolated);
31873190

31883191
// Decode the default argument kind.
31893192
// FIXME: Default argument expression, if available.

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 635; // @_nonSendable
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 636; // 'isolated' in param decls
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///
@@ -1354,6 +1354,7 @@ namespace decls_block {
13541354
BCFixed<1>, // isIUO?
13551355
BCFixed<1>, // isVariadic?
13561356
BCFixed<1>, // isAutoClosure?
1357+
BCFixed<1>, // isIsolated?
13571358
DefaultArgumentField, // default argument kind
13581359
BCBlob // default argument text
13591360
>;

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,6 +3713,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
37133713
param->isImplicitlyUnwrappedOptional(),
37143714
param->isVariadic(),
37153715
param->isAutoClosure(),
3716+
param->isIsolated(),
37163717
getRawStableDefaultArgumentKind(argKind),
37173718
defaultArgumentText);
37183719

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public actor A {
2+
}
3+
4+
public struct S {
5+
public func f(a: isolated A) {
6+
}
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t-scratch)
3+
// RUN: %target-swift-frontend -emit-module -o %t-scratch/def_isolated~partial.swiftmodule -primary-file %S/Inputs/def_isolated.swift -module-name def_isolated -disable-availability-checking
4+
// RUN: %target-swift-frontend -merge-modules -emit-module -parse-as-library -enable-testing %t-scratch/def_isolated~partial.swiftmodule -module-name def_isolated -o %t/def_isolated.swiftmodule -disable-availability-checking
5+
// RUN: %target-swift-frontend -typecheck -I%t -verify %s -verify-ignore-unknown -disable-availability-checking
6+
7+
// REQUIRES: concurrency
8+
9+
import def_isolated
10+
11+
func test(a: A, a2: isolated A, s: S) async {
12+
await s.f(a: a)
13+
s.f(a: a) // expected-error{{expression is 'async' but is not marked with 'await'}}
14+
// expected-note@-1{{calls to instance method 'f(a:)' from outside of its actor context are implicitly asynchronous}}
15+
16+
s.f(a: a2)
17+
}

0 commit comments

Comments
 (0)