1818
1919#include " swift/AST/Expr.h"
2020#include " swift/AST/Type.h"
21+ #include " swift/SIL/AbstractionPattern.h"
2122#define DEBUG_TYPE " libsil"
2223
2324#include " swift/AST/AnyFunctionRef.h"
@@ -1467,7 +1468,10 @@ class DestructureResults {
14671468 ResultConvention convention;
14681469
14691470 if (isBorrowAccessor (constant)) {
1470- if (substResultTL.isTrivial ()) {
1471+ if (substResultTL.getRecursiveProperties ()
1472+ .isAddressableForDependencies ()) {
1473+ convention = ResultConvention::GuaranteedAddress;
1474+ } else if (substResultTL.isTrivial ()) {
14711475 convention = ResultConvention::Unowned;
14721476 } else if (isFormallyReturnedIndirectly (origType, substType,
14731477 substResultTLForConvention)) {
@@ -1674,6 +1678,7 @@ class DestructureInputs {
16741678 AnyFunctionType::CanParam SubstSelfParam;
16751679 };
16761680 std::optional<ForeignSelfInfo> ForeignSelf;
1681+ std::optional<SILDeclRef> Constant;
16771682 AbstractionPattern TopLevelOrigType = AbstractionPattern::getInvalid();
16781683 SmallVectorImpl<SILParameterInfo> &Inputs;
16791684 SmallVectorImpl<int > &ParameterMap;
@@ -1695,9 +1700,11 @@ class DestructureInputs {
16951700 SmallVectorImpl<SILParameterInfo> &inputs,
16961701 SmallVectorImpl<int > ¶meterMap,
16971702 SmallBitVector &addressableParams,
1698- SmallBitVector &conditionallyAddressableParams)
1703+ SmallBitVector &conditionallyAddressableParams,
1704+ std::optional<SILDeclRef> constant)
16991705 : expansion(expansion), TC(TC), Convs(conventions), Foreign(foreign),
1700- IsolationInfo(isolationInfo), Inputs(inputs),
1706+ IsolationInfo(isolationInfo),
1707+ Constant(constant), Inputs(inputs),
17011708 ParameterMap(parameterMap),
17021709 AddressableLoweredParameters(addressableParams),
17031710 ConditionallyAddressableLoweredParameters(conditionallyAddressableParams)
@@ -1851,8 +1858,20 @@ class DestructureInputs {
18511858 // parameter, we should have processed it earlier in a call to
18521859 // maybeAddForeignParameters().
18531860 if (hasSelf && !hasForeignSelf) {
1854- auto origParamType = origType.getFunctionParamType (numOrigParams - 1 );
1861+ auto origParamType
1862+ = origType.getFunctionParamType (numOrigParams - 1 );
18551863 auto substParam = params.back ();
1864+
1865+ // If the self type is addressable-for-dependencies, and this is a
1866+ // borrow accessor, then we should pass it indirectly, as an abstract.
1867+ // parameter.
1868+ if (isBorrowAccessor (Constant)
1869+ && TC.getTypeLowering (origParamType,
1870+ substParam.getParameterType (), expansion)
1871+ .getRecursiveProperties ()
1872+ .isAddressableForDependencies ()) {
1873+ origParamType = AbstractionPattern::getOpaque ();
1874+ }
18561875 visit (origParamType, substParam,
18571876 params.size () - 1 ,
18581877 /* forSelf*/ true ,
@@ -2717,7 +2736,8 @@ static CanSILFunctionType getSILFunctionType(
27172736 foreignInfo, actorIsolation, inputs,
27182737 parameterMap,
27192738 addressableParams,
2720- conditionallyAddressableParams);
2739+ conditionallyAddressableParams,
2740+ constant);
27212741 destructurer.destructure (origType, substFnInterfaceType.getParams (),
27222742 extInfoBuilder, unimplementable);
27232743 }
@@ -2923,7 +2943,8 @@ static CanSILFunctionType getSILFunctionTypeForInitAccessor(
29232943 actorIsolation, inputs,
29242944 unusedParameterMap,
29252945 unusedAddressableParams,
2926- unusedConditionalAddressableParams);
2946+ unusedConditionalAddressableParams,
2947+ constant);
29272948 destructurer.destructure (
29282949 origType, substAccessorType.getParams (),
29292950 extInfoBuilder.withRepresentation (SILFunctionTypeRepresentation::Thin),
0 commit comments