@@ -1377,6 +1377,22 @@ class Conventions {
1377
1377
}
1378
1378
};
1379
1379
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
+
1380
1396
// / A visitor for breaking down formal result types into a SILResultInfo
1381
1397
// / and possibly some number of indirect-out SILParameterInfos,
1382
1398
// / matching the abstraction patterns of the original type.
@@ -1386,22 +1402,21 @@ class DestructureResults {
1386
1402
SmallVectorImpl<SILResultInfo> &Results;
1387
1403
TypeExpansionContext context;
1388
1404
bool hasSendingResult;
1389
- bool isBorrowOrMutateAccessor ;
1405
+ std::optional<SILDeclRef> constant ;
1390
1406
1391
1407
public:
1392
1408
DestructureResults (TypeExpansionContext context, TypeConverter &TC,
1393
1409
const Conventions &conventions,
1394
1410
SmallVectorImpl<SILResultInfo> &results,
1395
- bool hasSendingResult, bool isBorrowOrMutateAccessor )
1411
+ bool hasSendingResult, std::optional<SILDeclRef> constant )
1396
1412
: TC(TC), Convs(conventions), Results(results), context(context),
1397
- hasSendingResult (hasSendingResult),
1398
- isBorrowOrMutateAccessor(isBorrowOrMutateAccessor) {}
1413
+ hasSendingResult (hasSendingResult), constant(constant) {}
1399
1414
1400
1415
void destructure (AbstractionPattern origType, CanType substType) {
1401
1416
// Recur into tuples.
1402
1417
// Do not explode tuples for borrow and mutate accessors since we cannot
1403
1418
// explode and reconstruct addresses.
1404
- if (origType.isTuple () && !isBorrowOrMutateAccessor ) {
1419
+ if (origType.isTuple () && !isBorrowAccessor (constant) ) {
1405
1420
origType.forEachTupleElement (substType,
1406
1421
[&](TupleElementGenerator &elt) {
1407
1422
// If the original element type is not a pack expansion, just
@@ -1411,7 +1426,7 @@ class DestructureResults {
1411
1426
return ;
1412
1427
}
1413
1428
1414
- if (isBorrowOrMutateAccessor ) {
1429
+ if (isBorrowAccessor (constant) ) {
1415
1430
llvm_unreachable (
1416
1431
" Returning packs from borrow/mutate accessor is not implemented" );
1417
1432
}
@@ -1448,17 +1463,17 @@ class DestructureResults {
1448
1463
// Determine the result convention.
1449
1464
ResultConvention convention;
1450
1465
1451
- if (isBorrowOrMutateAccessor ) {
1466
+ if (isBorrowAccessor (constant) ) {
1452
1467
if (substResultTL.isTrivial ()) {
1453
1468
convention = ResultConvention::Unowned;
1454
1469
} else if (isFormallyReturnedIndirectly (origType, substType,
1455
1470
substResultTLForConvention)) {
1456
- assert (Convs.getResult (substResultTLForConvention) ==
1457
- ResultConvention::Guaranteed);
1458
1471
convention = ResultConvention::GuaranteedAddress;
1459
1472
} else {
1460
1473
convention = ResultConvention::Guaranteed;
1461
1474
}
1475
+ } else if (isMutateAccessor (constant)) {
1476
+ convention = ResultConvention::GuaranteedAddress;
1462
1477
} else if (isFormallyReturnedIndirectly (origType, substType,
1463
1478
substResultTLForConvention)) {
1464
1479
convention = ResultConvention::Indirect;
@@ -2368,17 +2383,6 @@ getAsCoroutineAccessor(std::optional<SILDeclRef> constant) {
2368
2383
return accessor;
2369
2384
}
2370
2385
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
-
2382
2386
static void destructureYieldsForReadAccessor (TypeConverter &TC,
2383
2387
TypeExpansionContext expansion,
2384
2388
AbstractionPattern origType,
@@ -2728,8 +2732,7 @@ static CanSILFunctionType getSILFunctionType(
2728
2732
SmallVector<SILResultInfo, 8 > results;
2729
2733
{
2730
2734
DestructureResults destructurer (expansionContext, TC, conventions, results,
2731
- hasSendingResult,
2732
- isBorrowOrMutateAccessor (constant));
2735
+ hasSendingResult, constant);
2733
2736
destructurer.destructure (origResultType, substFormalResultType);
2734
2737
}
2735
2738
@@ -3277,11 +3280,6 @@ static CanSILFunctionType getNativeSILFunctionType(
3277
3280
TC, context, origType, substInterfaceType, extInfoBuilder,
3278
3281
DefaultSetterConventions (), *constant);
3279
3282
}
3280
- if (constant->isBorrowAccessor ()) {
3281
- return getSILFunctionTypeForConventions (
3282
- DefaultConventions (NormalParameterConvention::Guaranteed,
3283
- ResultConvention::Guaranteed));
3284
- }
3285
3283
}
3286
3284
return getSILFunctionTypeForConventions (
3287
3285
DefaultConventions (NormalParameterConvention::Guaranteed));
0 commit comments