Skip to content

Commit 6811ce8

Browse files
committed
[CSSimplify] Delay binding generic argument type variables to any Sendable
Prevent generic arguments from being assigned `any Sendable` directly, that should only happen through inference. This is required because we allow `any Sendable` -> `Any` conversion in modes without strict concurrency enabled to maintain source compatibility and let the developers annotate existing APIs with `any Sendable` and other concurrency attributes. (cherry picked from commit 17093b3)
1 parent 67bfa61 commit 6811ce8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,6 +4282,20 @@ ConstraintSystem::matchTypesBindTypeVar(
42824282
type = type->getRValueType();
42834283
}
42844284

4285+
// Prevent generic arguments from being assigned `any Sendable`
4286+
// directly, that should only happen through inference. This is
4287+
// required because we allow `any Sendable` -> `Any` conversion
4288+
// in modes without strict concurrency enabled to maintain source
4289+
// compatibility and let the developers annotate existing APIs
4290+
// with `any Sendable` and other concurrency attributes.
4291+
if (typeVar->getImpl().getGenericParameter() &&
4292+
!flags.contains(TMF_BindingTypeVariable) &&
4293+
type->isMarkerExistential()) {
4294+
auto constraintTy = type->castTo<ExistentialType>()->getConstraintType();
4295+
if (constraintTy->getKnownProtocol() == KnownProtocolKind::Sendable)
4296+
return formUnsolvedResult();
4297+
}
4298+
42854299
// Attempt to fix situations where type variable can't be bound
42864300
// to a particular type e.g. `l-value` or `inout`.
42874301
auto fixReferenceMismatch = [&](TypeVariableType *typeVar,

0 commit comments

Comments
 (0)