@@ -1386,6 +1386,58 @@ bool AbstractFunctionDecl::isCoroutine() const {
13861386 return false ;
13871387}
13881388
1389+ ArrayRef<AnyFunctionType::Yield>
1390+ AnyFunctionRef::getYieldResultsImpl (SmallVectorImpl<AnyFunctionType::Yield> &buffer,
1391+ bool mapIntoContext) const {
1392+ assert (buffer.empty ());
1393+ if (auto *AFD = getAbstractFunctionDecl ()) {
1394+ if (auto *AD = dyn_cast<AccessorDecl>(AFD)) {
1395+ // FIXME: AccessorDecl case is not necessary
1396+ if (AD->isCoroutine ()) {
1397+ auto valueTy = AD->getStorage ()->getValueInterfaceType ()
1398+ ->getReferenceStorageReferent ();
1399+ if (mapIntoContext)
1400+ valueTy = AFD->mapTypeIntoContext (valueTy);
1401+ YieldTypeFlags flags (isYieldingMutableAccessor (AD->getAccessorKind ())
1402+ ? ParamSpecifier::InOut
1403+ : ParamSpecifier::LegacyShared);
1404+ buffer.push_back (AnyFunctionType::Yield (valueTy, flags));
1405+ return buffer;
1406+ }
1407+ } else if (AFD->isCoroutine ()) {
1408+ auto resType = AFD->getInterfaceType ()->castTo <FunctionType>()->getResult ();
1409+ if (auto *resFnType = resType->getAs <FunctionType>())
1410+ resType = resFnType->getResult ();
1411+
1412+ if (resType->hasError ())
1413+ return {};
1414+
1415+ auto addYieldInfo =
1416+ [&](const YieldResultType *yieldResultTy) {
1417+ Type valueTy = yieldResultTy->getResultType ();
1418+ if (mapIntoContext)
1419+ valueTy = AFD->mapTypeIntoContext (valueTy);
1420+ YieldTypeFlags flags (yieldResultTy->isInOut () ?
1421+ ParamSpecifier::InOut : ParamSpecifier::LegacyShared);
1422+ buffer.push_back (AnyFunctionType::Yield (valueTy, flags));
1423+ };
1424+
1425+ if (auto *tupleResTy = resType->getAs <TupleType>())
1426+ for (const auto &elt : tupleResTy->getElements ()) {
1427+ Type eltTy = elt.getType ();
1428+ if (auto *yieldResTy = eltTy->getAs <YieldResultType>())
1429+ addYieldInfo (yieldResTy);
1430+ }
1431+ else
1432+ addYieldInfo (resType->castTo <YieldResultType>());
1433+
1434+ return buffer;
1435+ }
1436+ }
1437+ return {};
1438+ }
1439+
1440+
13891441bool ParameterList::hasInternalParameter (StringRef Prefix) const {
13901442 for (auto param : *this ) {
13911443 if (param->hasName () && param->getNameStr ().starts_with (Prefix))
0 commit comments