@@ -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 isBorrowOrMutateAccessor ;
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- isBorrowOrMutateAccessor(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 () && !isBorrowOrMutateAccessor ) {
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 (isBorrowOrMutateAccessor ) {
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 (isBorrowOrMutateAccessor ) {
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;
@@ -2368,17 +2383,6 @@ getAsCoroutineAccessor(std::optional<SILDeclRef> constant) {
23682383 return accessor;
23692384}
23702385
2371- static bool isBorrowOrMutateAccessor (std::optional<SILDeclRef> constant) {
2372- if (!constant || !constant->hasDecl ())
2373- return false ;
2374-
2375- auto accessor = dyn_cast<AccessorDecl>(constant->getDecl ());
2376- if (!accessor)
2377- return false ;
2378-
2379- return accessor->isBorrowAccessor () || accessor->isMutateAccessor ();
2380- }
2381-
23822386static void destructureYieldsForReadAccessor (TypeConverter &TC,
23832387 TypeExpansionContext expansion,
23842388 AbstractionPattern origType,
@@ -2728,8 +2732,7 @@ static CanSILFunctionType getSILFunctionType(
27282732 SmallVector<SILResultInfo, 8 > results;
27292733 {
27302734 DestructureResults destructurer (expansionContext, TC, conventions, results,
2731- hasSendingResult,
2732- isBorrowOrMutateAccessor (constant));
2735+ hasSendingResult, constant);
27332736 destructurer.destructure (origResultType, substFormalResultType);
27342737 }
27352738
@@ -3277,11 +3280,6 @@ static CanSILFunctionType getNativeSILFunctionType(
32773280 TC, context, origType, substInterfaceType, extInfoBuilder,
32783281 DefaultSetterConventions (), *constant);
32793282 }
3280- if (constant->isBorrowAccessor ()) {
3281- return getSILFunctionTypeForConventions (
3282- DefaultConventions (NormalParameterConvention::Guaranteed,
3283- ResultConvention::Guaranteed));
3284- }
32853283 }
32863284 return getSILFunctionTypeForConventions (
32873285 DefaultConventions (NormalParameterConvention::Guaranteed));
0 commit comments