@@ -1377,6 +1377,22 @@ class Conventions {
13771377 }
13781378};
13791379
1380+ static bool isBorrowAccessor (std::optional<SILDeclRef> constant) {
1381+ if (!constant || !constant->hasDecl ())
1382+ return false ;
1383+
1384+ auto accessor = dyn_cast<AccessorDecl>(constant->getDecl ());
1385+ return accessor && accessor->isBorrowAccessor ();
1386+ }
1387+
1388+ static bool isMutateAccessor (std::optional<SILDeclRef> constant) {
1389+ if (!constant || !constant->hasDecl ())
1390+ return false ;
1391+
1392+ auto accessor = dyn_cast<AccessorDecl>(constant->getDecl ());
1393+ return accessor && accessor->isMutateAccessor ();
1394+ }
1395+
13801396// / A visitor for breaking down formal result types into a SILResultInfo
13811397// / and possibly some number of indirect-out SILParameterInfos,
13821398// / matching the abstraction patterns of the original type.
@@ -1386,22 +1402,21 @@ class DestructureResults {
13861402 SmallVectorImpl<SILResultInfo> &Results;
13871403 TypeExpansionContext context;
13881404 bool hasSendingResult;
1389- bool isBorrowAccessor ;
1405+ std::optional<SILDeclRef> constant ;
13901406
13911407public:
13921408 DestructureResults (TypeExpansionContext context, TypeConverter &TC,
13931409 const Conventions &conventions,
13941410 SmallVectorImpl<SILResultInfo> &results,
1395- bool hasSendingResult, bool isBorrowOrMutateAccessor )
1411+ bool hasSendingResult, std::optional<SILDeclRef> constant )
13961412 : TC(TC), Convs(conventions), Results(results), context(context),
1397- hasSendingResult (hasSendingResult),
1398- isBorrowAccessor(isBorrowOrMutateAccessor) {}
1413+ hasSendingResult (hasSendingResult), constant(constant) {}
13991414
14001415 void destructure (AbstractionPattern origType, CanType substType) {
14011416 // Recur into tuples.
14021417 // Do not explode tuples for borrow and mutate accessors since we cannot
14031418 // explode and reconstruct addresses.
1404- if (origType.isTuple () && !isBorrowAccessor) {
1419+ if (origType.isTuple () && !isBorrowAccessor (constant) ) {
14051420 origType.forEachTupleElement (substType,
14061421 [&](TupleElementGenerator &elt) {
14071422 // If the original element type is not a pack expansion, just
@@ -1411,7 +1426,7 @@ class DestructureResults {
14111426 return ;
14121427 }
14131428
1414- if (isBorrowAccessor) {
1429+ if (isBorrowAccessor (constant) ) {
14151430 llvm_unreachable (
14161431 " Returning packs from borrow/mutate accessor is not implemented" );
14171432 }
@@ -1448,17 +1463,17 @@ class DestructureResults {
14481463 // Determine the result convention.
14491464 ResultConvention convention;
14501465
1451- if (isBorrowAccessor) {
1466+ if (isBorrowAccessor (constant) ) {
14521467 if (substResultTL.isTrivial ()) {
14531468 convention = ResultConvention::Unowned;
14541469 } else if (isFormallyReturnedIndirectly (origType, substType,
14551470 substResultTLForConvention)) {
1456- assert (Convs.getResult (substResultTLForConvention) ==
1457- ResultConvention::Guaranteed);
14581471 convention = ResultConvention::GuaranteedAddress;
14591472 } else {
14601473 convention = ResultConvention::Guaranteed;
14611474 }
1475+ } else if (isMutateAccessor (constant)) {
1476+ convention = ResultConvention::GuaranteedAddress;
14621477 } else if (isFormallyReturnedIndirectly (origType, substType,
14631478 substResultTLForConvention)) {
14641479 convention = ResultConvention::Indirect;
@@ -2717,8 +2732,7 @@ static CanSILFunctionType getSILFunctionType(
27172732 SmallVector<SILResultInfo, 8 > results;
27182733 {
27192734 DestructureResults destructurer (expansionContext, TC, conventions, results,
2720- hasSendingResult,
2721- constant->isBorrowAccessor ());
2735+ hasSendingResult, constant);
27222736 destructurer.destructure (origResultType, substFormalResultType);
27232737 }
27242738
@@ -3266,11 +3280,6 @@ static CanSILFunctionType getNativeSILFunctionType(
32663280 TC, context, origType, substInterfaceType, extInfoBuilder,
32673281 DefaultSetterConventions (), *constant);
32683282 }
3269- if (constant->isBorrowAccessor ()) {
3270- return getSILFunctionTypeForConventions (
3271- DefaultConventions (NormalParameterConvention::Guaranteed,
3272- ResultConvention::Guaranteed));
3273- }
32743283 }
32753284 return getSILFunctionTypeForConventions (
32763285 DefaultConventions (NormalParameterConvention::Guaranteed));
0 commit comments