Skip to content

Commit d452c40

Browse files
authored
Merge pull request #79549 from gottesmm/pr-1e29cd1e901335aa05ad7b07bbc832c30d7fc250
[rbi] Convert an assert to an if check.
2 parents 11922d2 + f01d275 commit d452c40

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "swift/AST/ASTWalker.h"
1616
#include "swift/AST/Expr.h"
17-
#include "swift/Basic/Assertions.h"
1817
#include "swift/SIL/AddressWalker.h"
1918
#include "swift/SIL/ApplySite.h"
2019
#include "swift/SIL/InstructionUtils.h"
@@ -487,8 +486,8 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
487486
nomDecl)
488487
.withUnsafeNonIsolated(varIsolation.isNonisolatedUnsafe());
489488

490-
if (auto isolation = swift::getActorIsolation(nomDecl)) {
491-
assert(isolation.isGlobalActor());
489+
if (auto isolation = swift::getActorIsolation(nomDecl);
490+
isolation && isolation.isGlobalActor()) {
492491
return SILIsolationInfo::getGlobalActorIsolated(
493492
rei, isolation.getGlobalActor())
494493
.withUnsafeNonIsolated(varIsolation.isNonisolatedUnsafe());

test/Concurrency/transfernonsendable.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class NonSendableKlass { // expected-complete-note 53{{}}
3131
func getSendableGenericStructAsync() async -> SendableGenericStruct { fatalError() }
3232
}
3333

34+
nonisolated final class NonIsolatedFinalKlass {
35+
var ns = NonSendableKlass()
36+
}
37+
3438
class SendableKlass : @unchecked Sendable {}
3539

3640
actor MyActor {
@@ -1955,3 +1959,12 @@ func unsafeNonIsolatedAppliesToAssignToOutParam(ns: NonSendableKlass) -> sending
19551959
return obj
19561960
}
19571961
}
1962+
1963+
extension NonIsolatedFinalKlass {
1964+
// We used to crash while computing the isolation of the ref_element_addr
1965+
// here. Make sure we do not crash.
1966+
func testGetIsolationInfoOfField() async {
1967+
await transferToMain(ns) // expected-tns-warning {{sending 'self.ns' risks causing data races}}
1968+
// expected-tns-note @-1 {{sending task-isolated 'self.ns' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and task-isolated uses}}
1969+
}
1970+
}

0 commit comments

Comments
 (0)