Skip to content

[WIP] Fix https://github.com/swiftlang/swift/issues/80014 #80088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/SIL/IR/SILType.cpp
Original file line number Diff line number Diff line change
@@ -1247,7 +1247,12 @@ SILType SILType::removingAnyMoveOnlyWrapping(const SILFunction *fn) {
}

bool SILType::isSendable(SILFunction *fn) const {
return getASTType()->isSendableType();
switch (getCategory()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to change the behavior of other existing callers in the compiler. I'm also not convinced this is necessary. Whether a type is loadable or address-only is an implementation detail of the type and should not be observable in the language semantics in any way.

case SILValueCategory::Object:
return getASTType()->isSendableType();
case SILValueCategory::Address:
return false;
}
}

Type SILType::getRawLayoutSubstitutedLikeType() const {
4 changes: 3 additions & 1 deletion lib/SILOptimizer/Analysis/RegionAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -2539,11 +2539,13 @@ class PartitionOpTranslator {
auto trackableDest = tryToTrackValue(dest);
if (!trackableDest)
return;
if (requireOperands) {
builder.addRequire(trackableDest->getRepresentative().getValue());
}
for (Operand *op : srcCollection) {
if (auto trackableSrc = tryToTrackValue(op->get())) {
if (requireOperands) {
builder.addRequire(trackableSrc->getRepresentative().getValue());
builder.addRequire(trackableDest->getRepresentative().getValue());
}
builder.addMerge(trackableDest->getRepresentative().getValue(), op);
}
20 changes: 20 additions & 0 deletions test/Concurrency/sending_mutable_captures.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %target-swift-frontend -emit-sil -swift-version 6 %s -o /dev/null -verify

func foo() {
var x: X? = X()
// expected-error@+2{{sending value of non-Sendable type '() -> Void' risks causing data races}}
// expected-note@+1{{Passing value of non-Sendable type '() -> Void' as a 'sending' argument to global function 'user' risks causing races in between local and caller code}}
user {
x?.bar()
x = nil
}
x = nil // expected-note{{access can happen concurrently}}
}

func user(_ block: sending @escaping @isolated(any) () -> Void) {

}

final class X: Sendable {
func bar() {}
}