Skip to content

Commit 0a3e134

Browse files
authored
Merge pull request #81498 from nickolas-pohilets/mpokhylets/fix-80992-6.2
6.2: Fixed no copying IsIsolated flag when cloning subscript params
2 parents 34f22c6 + 07aedc4 commit 0a3e134

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7003,6 +7003,10 @@ class ParamDecl : public VarDecl {
70037003
/// Create a an identical copy of this ParamDecl.
70047004
static ParamDecl *clone(const ASTContext &Ctx, ParamDecl *PD);
70057005

7006+
static ParamDecl *cloneAccessor(const ASTContext &Ctx,
7007+
ParamDecl const *subscriptParam,
7008+
DeclContext *Parent);
7009+
70067010
static ParamDecl *
70077011
createImplicit(ASTContext &Context, SourceLoc specifierLoc,
70087012
SourceLoc argumentNameLoc, Identifier argumentName,

lib/AST/Decl.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8918,6 +8918,21 @@ ParamDecl *ParamDecl::clone(const ASTContext &Ctx, ParamDecl *PD) {
89188918
return Clone;
89198919
}
89208920

8921+
ParamDecl *ParamDecl::cloneAccessor(const ASTContext &Ctx,
8922+
ParamDecl const *subscriptParam,
8923+
DeclContext *Parent) {
8924+
auto *param = new (Ctx) ParamDecl(
8925+
subscriptParam->getSpecifierLoc(), subscriptParam->getArgumentNameLoc(),
8926+
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
8927+
subscriptParam->getName(), /*declContext*/ Parent);
8928+
param->setOptions(subscriptParam->getOptions());
8929+
8930+
// The cloned parameter is implicit.
8931+
param->setImplicit();
8932+
8933+
return param;
8934+
}
8935+
89218936
ParamDecl *
89228937
ParamDecl::createImplicit(ASTContext &Context, SourceLoc specifierLoc,
89238938
SourceLoc argumentNameLoc, Identifier argumentName,
@@ -11128,23 +11143,7 @@ AccessorDecl *AccessorDecl::createParsed(
1112811143
paramsEnd = indices->getEndLoc();
1112911144
}
1113011145
for (auto *subscriptParam : *indices) {
11131-
// Clone the parameter.
11132-
auto *param = new (ctx) ParamDecl(
11133-
subscriptParam->getSpecifierLoc(),
11134-
subscriptParam->getArgumentNameLoc(),
11135-
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
11136-
subscriptParam->getName(), /*declContext*/ accessor);
11137-
param->setAutoClosure(subscriptParam->isAutoClosure());
11138-
11139-
// The cloned parameter is implicit.
11140-
param->setImplicit();
11141-
11142-
if (subscriptParam->isSending())
11143-
param->setSending();
11144-
11145-
if (subscriptParam->isCallerIsolated())
11146-
param->setCallerIsolated();
11147-
11146+
auto param = ParamDecl::cloneAccessor(ctx, subscriptParam, accessor);
1114811147
newParams.push_back(param);
1114911148
}
1115011149

test/Concurrency/isolated_parameters.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@available(SwiftStdlib 5.1, *)
1010
actor A {
11-
func f() { } // expected-typechecker-note 5{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
11+
func f() { } // expected-typechecker-note 3{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
1212
}
1313

1414
@available(SwiftStdlib 5.1, *)
@@ -362,11 +362,8 @@ func isolatedClosures() {
362362
// expected-typechecker-warning@+2 {{cannot have more than one 'isolated' parameter; this is an error in the Swift 6 language mode}}
363363
// expected-typechecker-warning@+1 {{subscript with 'isolated' parameter cannot be 'nonisolated'; this is an error in the Swift 6 language mode}}{{3-15=}}
364364
nonisolated subscript(_ a: isolated A, _ b: isolated A) -> Int {
365-
// FIXME: wrong isolation. should be isolated to `a`.
366-
#if ALLOW_TYPECHECKER_ERRORS
367-
a.f() // expected-typechecker-error {{call to actor-isolated instance method 'f()' in a synchronous actor-isolated context}}
368-
b.f() // expected-typechecker-error {{call to actor-isolated instance method 'f()' in a synchronous actor-isolated context}}
369-
#endif
365+
a.f()
366+
b.f()
370367
return 0
371368
}
372369

@@ -587,3 +584,14 @@ public actor MyActorIsolatedParameterMerge {
587584
class ClassWithIsolatedAsyncInitializer {
588585
init(isolation: isolated (any Actor)? = #isolation) async {}
589586
}
587+
588+
// https://github.com/swiftlang/swift/issues/80992
589+
struct WritableActorKeyPath<Root: Actor, Value>: Sendable {
590+
var getter: @Sendable (isolated Root) -> Value
591+
var setter: @Sendable (isolated Root, Value) -> Void
592+
593+
subscript(_ root: isolated Root) -> Value {
594+
get { getter(root) }
595+
nonmutating set { setter(root, newValue) }
596+
}
597+
}

0 commit comments

Comments
 (0)