Skip to content

Commit e24196e

Browse files
committed
[Concurrency] Clean-up duplicate code in checkSendableInstanceStorage
1 parent 68524a8 commit e24196e

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
@@ -6763,55 +6763,20 @@ static bool checkSendableInstanceStorage(
67636763
}
67646764
}
67656765

6766-
// Check that the property type is Sendable.
6767-
SendableCheckContext context(dc, check);
6768-
diagnoseNonSendableTypes(
6769-
propertyType, context,
6770-
/*inDerivedConformance*/Type(), property->getLoc(),
6771-
[&](Type type, DiagnosticBehavior behavior) {
6772-
auto preconcurrency = context.preconcurrencyBehavior(type);
6773-
if (isImplicitSendableCheck(check)) {
6774-
// If this is for an externally-visible conformance, fail.
6775-
if (check == SendableCheck::ImplicitForExternallyVisible) {
6776-
invalid = true;
6777-
return true;
6778-
}
6779-
6780-
// If we are to ignore this diagnostic, just continue.
6781-
if (behavior == DiagnosticBehavior::Ignore ||
6782-
preconcurrency == DiagnosticBehavior::Ignore)
6783-
return true;
6784-
6785-
invalid = true;
6786-
return true;
6787-
}
6788-
6789-
if (preconcurrency)
6790-
behavior = preconcurrency.value();
6791-
6792-
property
6793-
->diagnose(diag::non_concurrent_type_member, propertyType,
6794-
false, property->getName(), nominal)
6795-
.limitBehaviorWithPreconcurrency(behavior,
6796-
preconcurrency.has_value());
6797-
return false;
6798-
});
6799-
6800-
if (invalid) {
6801-
// For implicit checks, bail out early if anything failed.
6802-
if (isImplicitSendableCheck(check))
6803-
return true;
6804-
}
6805-
6806-
return false;
6766+
return checkSendabilityOfMemberType(property, propertyType);
68076767
}
68086768

68096769
/// Handle an enum associated value.
68106770
bool operator()(EnumElementDecl *element, Type elementType) override {
6811-
SendableCheckContext context (dc, check);
6771+
return checkSendabilityOfMemberType(element, elementType);
6772+
}
6773+
6774+
private:
6775+
bool checkSendabilityOfMemberType(ValueDecl *member, Type memberType) {
6776+
SendableCheckContext context(dc, check);
68126777
diagnoseNonSendableTypes(
6813-
elementType, context,
6814-
/*inDerivedConformance*/Type(), element->getLoc(),
6778+
memberType, context,
6779+
/*inDerivedConformance*/ Type(), member->getLoc(),
68156780
[&](Type type, DiagnosticBehavior behavior) {
68166781
auto preconcurrency = context.preconcurrencyBehavior(type);
68176782
if (isImplicitSendableCheck(check)) {
@@ -6833,9 +6798,10 @@ static bool checkSendableInstanceStorage(
68336798
if (preconcurrency)
68346799
behavior = preconcurrency.value();
68356800

6836-
element
6837-
->diagnose(diag::non_concurrent_type_member, type, true,
6838-
element->getName(), nominal)
6801+
member
6802+
->diagnose(diag::non_concurrent_type_member, type,
6803+
isa<EnumElementDecl>(member), member->getName(),
6804+
nominal)
68396805
.limitBehaviorWithPreconcurrency(behavior,
68406806
preconcurrency.has_value());
68416807
return false;
@@ -6849,6 +6815,7 @@ static bool checkSendableInstanceStorage(
68496815

68506816
return false;
68516817
}
6818+
68526819
} visitor(nominal, dc, check);
68536820

68546821
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
@@ -337,7 +337,7 @@ enum E2<T> {
337337
extension E2: Sendable where T: Sendable { }
338338

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

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)