@@ -755,6 +755,94 @@ Type TypeBase::lookThroughAllOptionalTypes(SmallVectorImpl<Type> &optionals){
755755 return type;
756756}
757757
758+ Type TypeBase::stripConcurrency (bool recurse, bool dropGlobalActor) {
759+ // Look through optionals.
760+ if (Type optionalObject = getOptionalObjectType ()) {
761+ Type newOptionalObject =
762+ optionalObject->stripConcurrency (recurse, dropGlobalActor);
763+ if (optionalObject->isEqual (newOptionalObject))
764+ return Type (this );
765+
766+ return OptionalType::get (newOptionalObject);
767+ }
768+
769+ // Function types.
770+ if (auto fnType = getAs<AnyFunctionType>()) {
771+ // Strip off Sendable and (possibly) the global actor.
772+ ASTExtInfo extInfo =
773+ fnType->hasExtInfo () ? fnType->getExtInfo () : ASTExtInfo ();
774+ extInfo = extInfo.withConcurrent (false );
775+ if (dropGlobalActor)
776+ extInfo = extInfo.withGlobalActor (Type ());
777+
778+ ArrayRef<AnyFunctionType::Param> params = fnType->getParams ();
779+ Type resultType = fnType->getResult ();
780+
781+ SmallVector<AnyFunctionType::Param, 4 > newParams;
782+ if (recurse) {
783+ for (unsigned paramIdx : indices (params)) {
784+ const auto ¶m = params[paramIdx];
785+ Type newParamType = param.getPlainType ()->stripConcurrency (
786+ recurse, dropGlobalActor);
787+
788+ if (!newParams.empty ()) {
789+ newParams.push_back (param.withType (newParamType));
790+ continue ;
791+ }
792+
793+ if (newParamType->isEqual (param.getPlainType ()))
794+ continue ;
795+
796+ newParams.append (params.begin (), params.begin () + paramIdx);
797+ newParams.push_back (param.withType (newParamType));
798+ }
799+
800+ if (!newParams.empty ())
801+ params = newParams;
802+
803+ resultType = resultType->stripConcurrency (recurse, dropGlobalActor);
804+ }
805+
806+ // Drop Sendable requirements.
807+ GenericSignature genericSig;
808+ if (auto genericFnType = dyn_cast<GenericFunctionType>(fnType)) {
809+ auto requirements = genericFnType->getRequirements ();
810+ SmallVector<Requirement, 4 > newRequirements;
811+ for (unsigned reqIdx : indices (requirements)) {
812+ // If it's a Sendable requirement, skip it.
813+ const auto &req = requirements[reqIdx];
814+ if (req.getKind () == RequirementKind::Conformance &&
815+ req.getSecondType ()->castTo <ProtocolType>()->getDecl ()
816+ ->isSpecificProtocol (KnownProtocolKind::Sendable))
817+ continue ;
818+
819+ newRequirements.push_back (req);
820+ }
821+
822+ if (newRequirements.size () == requirements.size ()) {
823+ genericSig = genericFnType->getGenericSignature ();
824+ } else {
825+ genericSig = GenericSignature::get (
826+ genericFnType->getGenericParams (), newRequirements);
827+ }
828+ }
829+
830+ Type newFnType;
831+ if (genericSig) {
832+ newFnType = GenericFunctionType::get (
833+ genericSig, params, resultType, extInfo);
834+ } else {
835+ newFnType = FunctionType::get (params, resultType, extInfo);
836+ }
837+ if (newFnType->isEqual (this ))
838+ return Type (this );
839+
840+ return newFnType;
841+ }
842+
843+ return Type (this );
844+ }
845+
758846bool TypeBase::isAnyObject () {
759847 auto canTy = getCanonicalType ();
760848
0 commit comments