Skip to content

Commit 28245ef

Browse files
authored
Merge pull request #60116 from DougGregor/soften-preconcurrency-sendable-5.7
2 parents 50e4d3c + 4389353 commit 28245ef

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2864,13 +2864,18 @@ namespace {
28642864
}
28652865
}
28662866

2867+
// Does the reference originate from a @preconcurrency context?
2868+
bool preconcurrencyContext =
2869+
result.options.contains(ActorReferenceResult::Flags::Preconcurrency);
2870+
28672871
ctx.Diags.diagnose(
28682872
loc, diag::actor_isolated_non_self_reference,
28692873
decl->getDescriptiveKind(),
28702874
decl->getName(),
28712875
useKind,
28722876
refKind + 1, refGlobalActor,
2873-
result.isolation);
2877+
result.isolation)
2878+
.warnUntilSwiftVersionIf(preconcurrencyContext, 6);
28742879

28752880
noteIsolatedActorMember(decl, context);
28762881

@@ -5124,6 +5129,10 @@ ActorReferenceResult ActorReferenceResult::forReference(
51245129
// to perform.
51255130
Options options = None;
51265131

5132+
// Note if the reference originates from a @preconcurrency-isolated context.
5133+
if (contextIsolation.preconcurrency())
5134+
options |= Flags::Preconcurrency;
5135+
51275136
// If the declaration isn't asynchronous, promote to async.
51285137
if (!isAsyncDecl(declRef))
51295138
options |= Flags::AsyncPromotion;

lib/Sema/TypeCheckConcurrency.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ struct ActorReferenceResult {
210210
/// The declaration is being accessed from outside the actor and
211211
/// potentially from a different node, so it must be marked 'distributed'.
212212
Distributed = 1 << 2,
213+
214+
/// The declaration is being accessed from a @preconcurrency context.
215+
Preconcurrency = 1 << 3,
213216
};
214217

215218
using Options = OptionSet<Flags>;

test/ClangImporter/objc_async.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,17 @@ public struct SomeWrapper<T: AuditedNonSendable> {
381381
}
382382

383383
extension SomeWrapper: Sendable where T: Sendable {}
384+
385+
386+
// rdar://96830159
387+
@MainActor class SendableCompletionHandler {
388+
var isolatedThing: [String] = []
389+
// expected-note@-1 {{property declared here}}
390+
391+
func makeCall(slowServer: SlowServer) {
392+
slowServer.doSomethingSlow("churn butter") { (_ : Int) in
393+
let _ = self.isolatedThing
394+
// expected-warning@-1 {{main actor-isolated property 'isolatedThing' can not be referenced from a Sendable closure; this is an error in Swift 6}}
395+
}
396+
}
397+
}

0 commit comments

Comments
 (0)