Skip to content

Commit 4bd4fa6

Browse files
committed
[Sema] Use checkGenericArguments
1 parent 34ca702 commit 4bd4fa6

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
16641664
FunctionRefKind functionRefKind,
16651665
ConstraintLocatorBuilder locator,
16661666
DeclContext *useDC) {
1667+
auto &ctx = getASTContext();
1668+
16671669
if (value->getDeclContext()->isTypeContext() && isa<FuncDecl>(value)) {
16681670
// Unqualified lookup can find operator names within nominal types.
16691671
auto func = cast<FuncDecl>(value);
@@ -1709,7 +1711,14 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
17091711
auto funcType = funcDecl->getInterfaceType()->castTo<AnyFunctionType>();
17101712
auto numLabelsToRemove = getNumRemovedArgumentLabels(
17111713
funcDecl, /*isCurriedInstanceReference=*/false, functionRefKind);
1712-
1714+
1715+
if (ctx.LangOpts.hasFeature(Feature::InferSendableMethods)) {
1716+
// All global functions should be @Sendable
1717+
if(funcDecl->getDeclContext()->isLocalContext()) {
1718+
funcType = funcType->withExtInfo(funcType->getExtInfo().withConcurrent())->getAs<AnyFunctionType>();
1719+
}
1720+
}
1721+
17131722
auto openedType = openFunctionType(funcType, locator, replacements,
17141723
funcDecl->getDeclContext())
17151724
->removeArgumentLabels(numLabelsToRemove);
@@ -2625,7 +2634,7 @@ ConstraintSystem::getTypeOfMemberReference(
26252634
functionType, locator);
26262635
auto &ctx = DC->getASTContext();
26272636
auto *parentModule = useDC->getParentModule();
2628-
bool baseSendable = isSendableType(parentModule, baseOpenedTy);
2637+
bool baseTypeSendable = isSendableType(parentModule, baseOpenedTy);
26292638
bool inferredSendable =
26302639
ctx.LangOpts.hasFeature(Feature::InferSendableMethods);
26312640

@@ -2635,20 +2644,24 @@ ConstraintSystem::getTypeOfMemberReference(
26352644
auto baseConformance = TypeChecker::conformsToProtocol(
26362645
baseOpenedTy, sendableProtocol, parentModule);
26372646

2638-
if (baseSendable) {
2647+
if (baseTypeSendable) {
26392648
// Add @Sendable to functions without conditional conformances
2640-
if (baseConformance.getConditionalRequirements().empty())
2649+
if (baseConformance.getConditionalRequirements().empty()){
26412650
functionType = functionType->withExtInfo(functionType->getExtInfo().withConcurrent())->getAs<FunctionType>();
2642-
2643-
// Handle Conditional Conformances
2644-
for (auto req : baseConformance.getConditionalRequirements()) {
2645-
if (!TypeChecker::conformsToProtocol(req.getFirstType(),
2646-
sendableProtocol, parentModule)
2647-
.isInvalid())
2651+
} else {
2652+
// Handle Conditional Conformances
2653+
auto substitutionMap = SubstitutionMap::getProtocolSubstitutions(
2654+
sendableProtocol, baseOpenedTy,
2655+
baseConformance);
2656+
2657+
auto result = TypeChecker::checkGenericArguments(parentModule, baseConformance.getConditionalRequirements(), QuerySubstitutionMap{substitutionMap} );
2658+
2659+
if (result == CheckGenericArgumentsResult::Success) {
26482660
functionType =
2649-
functionType
2650-
->withExtInfo(functionType->getExtInfo().withConcurrent())
2651-
->getAs<FunctionType>();
2661+
functionType
2662+
->withExtInfo(functionType->getExtInfo().withConcurrent())
2663+
->getAs<FunctionType>();
2664+
}
26522665
}
26532666
}
26542667
}
@@ -2659,10 +2672,10 @@ ConstraintSystem::getTypeOfMemberReference(
26592672
FunctionType::get(fullFunctionType->getParams(), functionType, info);
26602673

26612674
// Add @Sendable to openedType if possible
2662-
if (inferredSendable && baseSendable) {
2675+
if (inferredSendable){
26632676
auto origFnType = openedType->castTo<FunctionType>();
26642677
openedType =
2665-
origFnType->withExtInfo(origFnType->getExtInfo().withConcurrent());
2678+
origFnType->withExtInfo(origFnType->getExtInfo().withConcurrent());
26662679
}
26672680
}
26682681

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,19 +5482,6 @@ AnyFunctionType *swift::adjustFunctionTypeForConcurrency(
54825482
dc, getType, isolatedByPreconcurrency);
54835483

54845484
auto &ctx = dc->getASTContext();
5485-
bool inferredSendable =
5486-
ctx.LangOpts.hasFeature(Feature::InferSendableMethods);
5487-
5488-
if (inferredSendable) {
5489-
if (auto func = dyn_cast_or_null<AbstractFunctionDecl>(decl)) {
5490-
auto doesNotCapture = func->getCaptureInfo().getCaptures().empty();
5491-
5492-
if (doesNotCapture) {
5493-
fnType = fnType->withExtInfo(fnType->getExtInfo().withConcurrent());
5494-
return fnType;
5495-
}
5496-
}
5497-
}
54985485

54995486
fnType = applyUnsafeConcurrencyToFunctionType(
55005487
fnType, decl, strictChecking, numApplies, isMainDispatchQueue);

test/Concurrency/sendable_methods.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift-enable -experimental-feature InferSendableMethods
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature InferSendableMethods
22
// REQUIRES: concurrency
33

44
final class C : Sendable {

0 commit comments

Comments
 (0)