@@ -1166,6 +1166,58 @@ bool AbstractFunctionDecl::isCoroutine() const {
11661166 return false ;
11671167}
11681168
1169+ ArrayRef<AnyFunctionType::Yield>
1170+ AnyFunctionRef::getYieldResultsImpl (SmallVectorImpl<AnyFunctionType::Yield> &buffer,
1171+ bool mapIntoContext) const {
1172+ assert (buffer.empty ());
1173+ if (auto *AFD = getAbstractFunctionDecl ()) {
1174+ if (auto *AD = dyn_cast<AccessorDecl>(AFD)) {
1175+ // FIXME: AccessorDecl case is not necessary
1176+ if (AD->isCoroutine ()) {
1177+ auto valueTy = AD->getStorage ()->getValueInterfaceType ()
1178+ ->getReferenceStorageReferent ();
1179+ if (mapIntoContext)
1180+ valueTy = AFD->mapTypeIntoContext (valueTy);
1181+ YieldTypeFlags flags (isYieldingMutableAccessor (AD->getAccessorKind ())
1182+ ? ParamSpecifier::InOut
1183+ : ParamSpecifier::LegacyShared);
1184+ buffer.push_back (AnyFunctionType::Yield (valueTy, flags));
1185+ return buffer;
1186+ }
1187+ } else if (AFD->isCoroutine ()) {
1188+ auto resType = AFD->getInterfaceType ()->castTo <FunctionType>()->getResult ();
1189+ if (auto *resFnType = resType->getAs <FunctionType>())
1190+ resType = resFnType->getResult ();
1191+
1192+ if (resType->hasError ())
1193+ return {};
1194+
1195+ auto addYieldInfo =
1196+ [&](const YieldResultType *yieldResultTy) {
1197+ Type valueTy = yieldResultTy->getResultType ();
1198+ if (mapIntoContext)
1199+ valueTy = AFD->mapTypeIntoContext (valueTy);
1200+ YieldTypeFlags flags (yieldResultTy->isInOut () ?
1201+ ParamSpecifier::InOut : ParamSpecifier::LegacyShared);
1202+ buffer.push_back (AnyFunctionType::Yield (valueTy, flags));
1203+ };
1204+
1205+ if (auto *tupleResTy = resType->getAs <TupleType>())
1206+ for (const auto &elt : tupleResTy->getElements ()) {
1207+ Type eltTy = elt.getType ();
1208+ if (auto *yieldResTy = eltTy->getAs <YieldResultType>())
1209+ addYieldInfo (yieldResTy);
1210+ }
1211+ else
1212+ addYieldInfo (resType->castTo <YieldResultType>());
1213+
1214+ return buffer;
1215+ }
1216+ }
1217+ return {};
1218+ }
1219+
1220+
11691221bool ParameterList::hasInternalParameter (StringRef Prefix) const {
11701222 for (auto param : *this ) {
11711223 if (param->hasName () && param->getNameStr ().starts_with (Prefix))
0 commit comments