Skip to content

Commit 6879961

Browse files
committed
[Sema] Delay lookup for conditional conformances
Remove diagnostics and sendable checks from ActorIsolationChecker
1 parent 68e909f commit 6879961

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9501,9 +9501,10 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
95019501
instanceTy = baseObjMeta->getInstanceType();
95029502
}
95039503

9504+
MemberLookupResult result;
9505+
95049506
if (instanceTy->isTypeVariableOrMember() ||
95059507
instanceTy->is<UnresolvedType>()) {
9506-
MemberLookupResult result;
95079508
result.OverallResult = MemberLookupResult::Unsolved;
95089509
return result;
95099510
}
@@ -9513,14 +9514,24 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
95139514
if (isSingleUnlabeledPackExpansionTuple(instanceTy)) {
95149515
auto elementTy = instanceTy->castTo<TupleType>()->getElementType(0);
95159516
if (elementTy->is<TypeVariableType>()) {
9516-
MemberLookupResult result;
9517+
result.OverallResult = MemberLookupResult::Unsolved;
9518+
return result;
9519+
}
9520+
}
9521+
9522+
// Delay solving member constraint for unapplied methods
9523+
// where the base type has a conditional Sendable conformance
9524+
if (functionRefKind == FunctionRefKind::Unapplied){
9525+
auto sendableProtocol = DC->getParentModule()->getASTContext().getProtocol(KnownProtocolKind::Sendable);
9526+
auto baseSendable = swift::TypeChecker::conformsToProtocol(instanceTy, sendableProtocol, DC->getParentModule());
9527+
9528+
if (!baseSendable.isInvalid() && !baseSendable.getConditionalRequirements().empty() && instanceTy->hasTypeVariable()) {
95179529
result.OverallResult = MemberLookupResult::Unsolved;
95189530
return result;
95199531
}
95209532
}
95219533

95229534
// Okay, start building up the result list.
9523-
MemberLookupResult result;
95249535
result.OverallResult = MemberLookupResult::HasResults;
95259536

95269537
// Add key path result.
@@ -10520,8 +10531,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
1052010531
// If requested, generate a constraint.
1052110532
if (flags.contains(TMF_GenerateConstraints)) {
1052210533
auto *memberRef = Constraint::createMemberOrOuterDisjunction(
10523-
*this, kind, baseTy, memberTy, member, useDC, functionRefKind,
10524-
outerAlternatives, locator);
10534+
*this, kind, baseTy, memberTy, member, useDC, functionRefKind,
10535+
outerAlternatives, locator);
1052510536

1052610537
addUnsolvedConstraint(memberRef);
1052710538

@@ -10576,7 +10587,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
1057610587
// It could either be a hole associated directly with the base
1057710588
// or a hole which came from result type of the chain.
1057810589
if (originatorLoc->isLastElement<
10579-
LocatorPathElt::UnresolvedMemberChainResult>()) {
10590+
LocatorPathElt::UnresolvedMemberChainResult>()) {
1058010591
auto *UMCR = castToExpr<UnresolvedMemberChainResultExpr>(
1058110592
originatorLoc->getAnchor());
1058210593
return UMCR->getChainBase() == getAsExpr(locator->getAnchor());

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,10 +1712,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
17121712
auto numLabelsToRemove = getNumRemovedArgumentLabels(
17131713
funcDecl, /*isCurriedInstanceReference=*/false, functionRefKind);
17141714

1715-
1716-
//check the base ... let's check
17171715
//funcType = funcType->withExtInfo(functy->getExtInfo().withConcurrent())->castTo<AnyFunctionType>();
1718-
1716+
17191717
auto openedType = openFunctionType(funcType, locator, replacements,
17201718
funcDecl->getDeclContext())
17211719
->removeArgumentLabels(numLabelsToRemove);
@@ -2633,8 +2631,15 @@ ConstraintSystem::getTypeOfMemberReference(
26332631
// FIXME: Handle conditional conformances
26342632
auto baseSendable = TypeChecker::conformsToProtocol( baseOpenedTy, sendableProtocol, useDC->getParentModule());
26352633

2636-
if (!baseSendable.isInvalid()) {
2634+
if (isSendableType(useDC->getParentModule(), baseOpenedTy)) {
2635+
if (baseSendable.getConditionalRequirements().empty())
2636+
functionType = functionType->withExtInfo(functionType->getExtInfo().withConcurrent())->getAs<FunctionType>();
2637+
2638+
for (auto req : baseSendable.getConditionalRequirements()){
2639+
if(!TypeChecker::conformsToProtocol( req.getFirstType(), sendableProtocol, useDC->getParentModule()).isInvalid()){
26372640
functionType = functionType->withExtInfo(functionType->getExtInfo().withConcurrent())->getAs<FunctionType>();
2641+
}
2642+
}
26382643
}
26392644

26402645
// FIXME: Verify ExtInfo state is correct, not working by accident.

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,6 @@ bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *dec
19381938
isolationCrossing.value().getDiagnoseIsolation()))
19391939
return true;
19401940
}
1941-
19421941
auto fnType = fnExprType->getAs<FunctionType>();
19431942
if (!fnType)
19441943
return false;
@@ -2468,11 +2467,6 @@ namespace {
24682467
auto valueRef = declRef->getDeclRef();
24692468
auto value = valueRef.getDecl();
24702469
auto loc = declRef->getLoc();
2471-
2472-
// for (auto arg : *declRef->getArgs()) {
2473-
//// if (swift::isSendableType(getDeclContext()->getParentModule(), arg))
2474-
// value->getAttrs().add(new (ctx) SendableAttr(true));
2475-
// }
24762470

24772471
//FIXME: Should this be subsumed in reference checking?
24782472
if (value->isLocalCapture())
@@ -2494,12 +2488,6 @@ namespace {
24942488
partialApply->base, memberRef->first, memberRef->second,
24952489
partialApply);
24962490

2497-
if (diagnosePartialApplySendability(partialApply->fn, partialApply->base, getDeclContext())){
2498-
if(auto funcdecl = dyn_cast<FuncDecl>(memberRef->first.getDecl())){
2499-
// Mark with @Sendable attribute implicitly if type is Sendable
2500-
funcdecl->getAttrs().add(new (ctx) SendableAttr(true));
2501-
}
2502-
}
25032491
partialApply->base->walk(*this);
25042492

25052493
return Action::SkipChildren(expr);

lib/Sema/TypeCheckConcurrency.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,6 @@ bool isPotentiallyIsolatedActor(
548548
VarDecl *var, llvm::function_ref<bool(ParamDecl *)> isIsolated =
549549
[](ParamDecl *P) { return P->isIsolated(); });
550550

551-
/// Check whether the given PartialApplyThunk makes an unsatisfied isolation jump
552-
/// and if so, emit diagnostics for any nonsendable arguments to the apply.
553-
/// Add the Sendable attribute if this is a patial apply of a Sendable Type.
554-
bool diagnosePartialApplySendability(Expr *decl, Expr *base, const DeclContext *declContext);
555-
556551
/// Check whether the given ApplyExpr makes an unsatisfied isolation jump
557552
/// and if so, emit diagnostics for any nonsendable arguments to the apply
558553
bool diagnoseApplyArgSendability(

0 commit comments

Comments
 (0)