@@ -1578,6 +1578,7 @@ class DestructureInputs {
15781578 SmallVectorImpl<SILParameterInfo> &Inputs;
15791579 SmallVectorImpl<int > &ParameterMap;
15801580 SmallBitVector &AddressableLoweredParameters;
1581+ SmallBitVector &ConditionallyAddressableLoweredParameters;
15811582 unsigned NextOrigParamIndex = 0 ;
15821583
15831584 void addLoweredParameter (SILParameterInfo parameter,
@@ -1593,11 +1594,13 @@ class DestructureInputs {
15931594 std::optional<ActorIsolation> isolationInfo,
15941595 SmallVectorImpl<SILParameterInfo> &inputs,
15951596 SmallVectorImpl<int > ¶meterMap,
1596- SmallBitVector &addressableParams)
1597- : expansion(expansion), TC(TC), Convs(conventions), Foreign(foreign),
1598- IsolationInfo(isolationInfo), Inputs(inputs),
1599- ParameterMap(parameterMap),
1600- AddressableLoweredParameters(addressableParams)
1597+ SmallBitVector &addressableParams,
1598+ SmallBitVector &conditionallyAddressableParams)
1599+ : expansion(expansion), TC(TC), Convs(conventions), Foreign(foreign),
1600+ IsolationInfo(isolationInfo), Inputs(inputs),
1601+ ParameterMap(parameterMap),
1602+ AddressableLoweredParameters(addressableParams),
1603+ ConditionallyAddressableLoweredParameters(conditionallyAddressableParams)
16011604 {}
16021605
16031606 void destructure (AbstractionPattern origType,
@@ -1768,7 +1771,9 @@ class DestructureInputs {
17681771
17691772 // Any parameters not yet marked addressable shouldn't be.
17701773 assert (AddressableLoweredParameters.size () <= ParameterMap.size ());
1774+ assert (ConditionallyAddressableLoweredParameters.size () <= ParameterMap.size ());
17711775 AddressableLoweredParameters.resize (ParameterMap.size (), false );
1776+ ConditionallyAddressableLoweredParameters.resize (ParameterMap.size (), false );
17721777 }
17731778
17741779 void visit (AbstractionPattern origType, AnyFunctionType::Param substParam,
@@ -1809,8 +1814,8 @@ class DestructureInputs {
18091814 if (origFlags.isAddressable ()) {
18101815 origType = AbstractionPattern::getOpaque ();
18111816
1812- // Remember that this lowered parameter is addressable in the
1813- // addressable parameters vector.
1817+ // Remember that this lowered parameter is unconditionally addressable in
1818+ // the addressable parameters vector.
18141819 AddressableLoweredParameters.resize (ParameterMap.size () + 1 , false );
18151820 AddressableLoweredParameters[ParameterMap.size ()] = true ;
18161821 } else if (hasScopedDependency) {
@@ -1821,10 +1826,14 @@ class DestructureInputs {
18211826 if (initialSubstTL.getRecursiveProperties ().isAddressableForDependencies ()) {
18221827 origType = AbstractionPattern::getOpaque ();
18231828
1824- // Remember that this lowered parameter is addressable in the
1825- // addressable parameters vector.
1829+ // Remember that this lowered parameter is conditionally addressable in
1830+ // the addressable parameters vector.
18261831 AddressableLoweredParameters.resize (ParameterMap.size () + 1 , false );
18271832 AddressableLoweredParameters[ParameterMap.size ()] = true ;
1833+
1834+ ConditionallyAddressableLoweredParameters
1835+ .resize (ParameterMap.size () + 1 , false );
1836+ ConditionallyAddressableLoweredParameters[ParameterMap.size ()] = true ;
18281837 }
18291838 }
18301839
@@ -2565,6 +2574,7 @@ static CanSILFunctionType getSILFunctionType(
25652574 SmallVector<SILParameterInfo, 8 > inputs;
25662575 SmallVector<int , 8 > parameterMap;
25672576 SmallBitVector addressableParams;
2577+ SmallBitVector conditionallyAddressableParams;
25682578 {
25692579 std::optional<ActorIsolation> actorIsolation;
25702580 if (constant) {
@@ -2587,7 +2597,9 @@ static CanSILFunctionType getSILFunctionType(
25872597 }
25882598 DestructureInputs destructurer (expansionContext, TC, conventions,
25892599 foreignInfo, actorIsolation, inputs,
2590- parameterMap, addressableParams);
2600+ parameterMap,
2601+ addressableParams,
2602+ conditionallyAddressableParams);
25912603 destructurer.destructure (origType, substFnInterfaceType.getParams (),
25922604 extInfoBuilder, unimplementable);
25932605 }
@@ -2668,11 +2680,19 @@ static CanSILFunctionType getSILFunctionType(
26682680 IndexSubset *addressableSet = addressableDeps.any ()
26692681 ? IndexSubset::get (TC.Context , addressableDeps)
26702682 : nullptr ;
2683+
2684+ SmallBitVector condAddressableDeps = scopeIndicesSet
2685+ ? scopeIndicesSet->getBitVector () & conditionallyAddressableParams
2686+ : SmallBitVector (1 , false );
2687+ IndexSubset *condAddressableSet = condAddressableDeps.any ()
2688+ ? IndexSubset::get (TC.Context , condAddressableDeps)
2689+ : nullptr ;
26712690
26722691 return LifetimeDependenceInfo (inheritIndicesSet,
26732692 scopeIndicesSet,
26742693 target, /* immortal*/ false ,
2675- addressableSet);
2694+ addressableSet,
2695+ condAddressableSet);
26762696 };
26772697 // Lower parameter dependencies.
26782698 for (unsigned i = 0 ; i < parameterMap.size (); ++i) {
@@ -2759,10 +2779,12 @@ static CanSILFunctionType getSILFunctionTypeForInitAccessor(
27592779 std::optional<ActorIsolation> actorIsolation; // For now always null.
27602780 SmallVector<int , 8 > unusedParameterMap;
27612781 SmallBitVector unusedAddressableParams;
2782+ SmallBitVector unusedConditionalAddressableParams;
27622783 DestructureInputs destructurer (context, TC, conventions, foreignInfo,
27632784 actorIsolation, inputs,
27642785 unusedParameterMap,
2765- unusedAddressableParams);
2786+ unusedAddressableParams,
2787+ unusedConditionalAddressableParams);
27662788 destructurer.destructure (
27672789 origType, substAccessorType.getParams (),
27682790 extInfoBuilder.withRepresentation (SILFunctionTypeRepresentation::Thin),
0 commit comments