Skip to content

Commit 82f04e5

Browse files
committed
[Concurrency] Clean-up duplicate code in checkSendableInstanceStorage
(cherry picked from commit e24196e)
1 parent 121aa40 commit 82f04e5

File tree

3 files changed

+16
-49
lines changed

3 files changed

+16
-49
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6783,55 +6783,20 @@ static bool checkSendableInstanceStorage(
67836783
}
67846784
}
67856785

6786-
// Check that the property type is Sendable.
6787-
SendableCheckContext context(dc, check);
6788-
diagnoseNonSendableTypes(
6789-
propertyType, context,
6790-
/*inDerivedConformance*/Type(), property->getLoc(),
6791-
[&](Type type, DiagnosticBehavior behavior) {
6792-
auto preconcurrency = context.preconcurrencyBehavior(type);
6793-
if (isImplicitSendableCheck(check)) {
6794-
// If this is for an externally-visible conformance, fail.
6795-
if (check == SendableCheck::ImplicitForExternallyVisible) {
6796-
invalid = true;
6797-
return true;
6798-
}
6799-
6800-
// If we are to ignore this diagnostic, just continue.
6801-
if (behavior == DiagnosticBehavior::Ignore ||
6802-
preconcurrency == DiagnosticBehavior::Ignore)
6803-
return true;
6804-
6805-
invalid = true;
6806-
return true;
6807-
}
6808-
6809-
if (preconcurrency)
6810-
behavior = preconcurrency.value();
6811-
6812-
property
6813-
->diagnose(diag::non_concurrent_type_member, propertyType,
6814-
false, property->getName(), nominal)
6815-
.limitBehaviorWithPreconcurrency(behavior,
6816-
preconcurrency.has_value());
6817-
return false;
6818-
});
6819-
6820-
if (invalid) {
6821-
// For implicit checks, bail out early if anything failed.
6822-
if (isImplicitSendableCheck(check))
6823-
return true;
6824-
}
6825-
6826-
return false;
6786+
return checkSendabilityOfMemberType(property, propertyType);
68276787
}
68286788

68296789
/// Handle an enum associated value.
68306790
bool operator()(EnumElementDecl *element, Type elementType) override {
6831-
SendableCheckContext context (dc, check);
6791+
return checkSendabilityOfMemberType(element, elementType);
6792+
}
6793+
6794+
private:
6795+
bool checkSendabilityOfMemberType(ValueDecl *member, Type memberType) {
6796+
SendableCheckContext context(dc, check);
68326797
diagnoseNonSendableTypes(
6833-
elementType, context,
6834-
/*inDerivedConformance*/Type(), element->getLoc(),
6798+
memberType, context,
6799+
/*inDerivedConformance*/ Type(), member->getLoc(),
68356800
[&](Type type, DiagnosticBehavior behavior) {
68366801
auto preconcurrency = context.preconcurrencyBehavior(type);
68376802
if (isImplicitSendableCheck(check)) {
@@ -6853,9 +6818,10 @@ static bool checkSendableInstanceStorage(
68536818
if (preconcurrency)
68546819
behavior = preconcurrency.value();
68556820

6856-
element
6857-
->diagnose(diag::non_concurrent_type_member, type, true,
6858-
element->getName(), nominal)
6821+
member
6822+
->diagnose(diag::non_concurrent_type_member, type,
6823+
isa<EnumElementDecl>(member), member->getName(),
6824+
nominal)
68596825
.limitBehaviorWithPreconcurrency(behavior,
68606826
preconcurrency.has_value());
68616827
return false;
@@ -6869,6 +6835,7 @@ static bool checkSendableInstanceStorage(
68696835

68706836
return false;
68716837
}
6838+
68726839
} visitor(nominal, dc, check);
68736840

68746841
return visitor.visit(nominal, dc) || visitor.invalid;

test/Concurrency/concurrent_value_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ enum E2<T> {
339339
extension E2: Sendable where T: Sendable { }
340340

341341
final class C1: Sendable {
342-
let nc: NotConcurrent? = nil // expected-warning{{stored property 'nc' of 'Sendable'-conforming class 'C1' has non-Sendable type 'NotConcurrent?'}}
342+
let nc: NotConcurrent? = nil // expected-warning{{stored property 'nc' of 'Sendable'-conforming class 'C1' has non-Sendable type 'NotConcurrent'}}
343343
var x: Int = 0 // expected-warning{{stored property 'x' of 'Sendable'-conforming class 'C1' is mutable}}
344344
let i: Int = 0
345345
}

test/Concurrency/sendable_metatype_typecheck.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ case q(Q.Type, Int) // expected-warning{{associated value 'q' of 'Sendable'-conf
123123
}
124124

125125
struct S: Sendable {
126-
var tuple: ([Q.Type], Int) // expected-warning{{stored property 'tuple' of 'Sendable'-conforming struct 'S' has non-Sendable type '([any Q.Type], Int)'}}
126+
var tuple: ([Q.Type], Int) // expected-warning{{stored property 'tuple' of 'Sendable'-conforming struct 'S' has non-Sendable type 'any Q.Type'}}
127127
}
128128

129129
extension Q {

0 commit comments

Comments
 (0)