Skip to content

Commit a431a7b

Browse files
committed
LifetimeDependence: conditionallyAddressableParamIndices
Preserve conditionallyAddressableParamIndices independent of any addressableParamIndices. The conditional dependencies are subject to change based on type substitution.
1 parent 1964f07 commit a431a7b

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

SwiftCompilerSources/Sources/SIL/FunctionConvention.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ extension FunctionConvention {
313313
}
314314
if scope {
315315
let addressable = bridged.checkAddressable(bridgedIndex(parameterIndex: index))
316+
|| bridged.checkConditionallyAddressable(bridgedIndex(parameterIndex: index))
316317
return .scope(addressable: addressable)
317318
}
318319
return nil

include/swift/AST/LifetimeDependence.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ class LifetimeDependenceInfo {
250250
assert(!inheritLifetimeParamIndices ||
251251
!inheritLifetimeParamIndices->isEmpty());
252252
assert(!scopeLifetimeParamIndices || !scopeLifetimeParamIndices->isEmpty());
253-
assert((!conditionallyAddressableParamIndices
254-
|| (addressableParamIndices
255-
&& conditionallyAddressableParamIndices
256-
->isSubsetOf(addressableParamIndices)))
257-
&& "conditionally-addressable params not a subset of addressable params?");
253+
assert((!addressableParamIndices
254+
|| !conditionallyAddressableParamIndices
255+
|| conditionallyAddressableParamIndices->isDisjointWith(
256+
addressableParamIndices)));
258257
}
259258

260259
operator bool() const { return !empty(); }

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct BridgedLifetimeDependenceInfo {
159159
swift::IndexSubset *_Nullable inheritLifetimeParamIndices;
160160
swift::IndexSubset *_Nullable scopeLifetimeParamIndices;
161161
swift::IndexSubset *_Nullable addressableParamIndices;
162+
swift::IndexSubset *_Nullable conditionallyAddressableParamIndices;
162163
SwiftUInt targetIndex;
163164
bool immortal;
164165

@@ -168,6 +169,7 @@ struct BridgedLifetimeDependenceInfo {
168169
BRIDGED_INLINE bool checkInherit(SwiftInt index) const;
169170
BRIDGED_INLINE bool checkScope(SwiftInt index) const;
170171
BRIDGED_INLINE bool checkAddressable(SwiftInt index) const;
172+
BRIDGED_INLINE bool checkConditionallyAddressable(SwiftInt index) const;
171173
BRIDGED_INLINE SwiftInt getTargetIndex() const;
172174

173175
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ BridgedLifetimeDependenceInfo::BridgedLifetimeDependenceInfo(swift::LifetimeDepe
147147
: inheritLifetimeParamIndices(info.getInheritIndices()),
148148
scopeLifetimeParamIndices(info.getScopeIndices()),
149149
addressableParamIndices(info.getAddressableIndices()),
150+
conditionallyAddressableParamIndices(
151+
info.getConditionallyAddressableIndices()),
150152
targetIndex(info.getTargetIndex()), immortal(info.isImmortal()) {}
151153

152154
SwiftInt BridgedLifetimeDependenceInfoArray::count() const {
@@ -177,6 +179,12 @@ bool BridgedLifetimeDependenceInfo::checkAddressable(SwiftInt index) const {
177179
return addressableParamIndices && addressableParamIndices->contains(index);
178180
}
179181

182+
bool BridgedLifetimeDependenceInfo::
183+
checkConditionallyAddressable(SwiftInt index) const {
184+
return conditionallyAddressableParamIndices
185+
&& conditionallyAddressableParamIndices->contains(index);
186+
}
187+
180188
SwiftInt BridgedLifetimeDependenceInfo::getTargetIndex() const {
181189
return targetIndex;
182190
}

lib/AST/LifetimeDependence.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ std::string LifetimeDependenceInfo::getString() const {
6363
}
6464
result += kind;
6565
if (addressable && addressable->contains(i)) {
66-
if (condAddressable && condAddressable->contains(i)) {
67-
result += "address_for_deps ";
68-
} else {
69-
result += "address ";
70-
}
66+
result += "address ";
67+
} else if (condAddressable && condAddressable->contains(i)) {
68+
result += "address_for_deps ";
7169
}
7270
result += std::to_string(i);
7371
isFirstSetBit = false;
@@ -1136,7 +1134,6 @@ static std::optional<LifetimeDependenceInfo> checkSILTypeModifiers(
11361134
break;
11371135
case LifetimeDescriptor::IsConditionallyAddressable:
11381136
conditionallyAddressableLifetimeParamIndices.set(index);
1139-
addressableLifetimeParamIndices.set(index);
11401137
break;
11411138
case LifetimeDescriptor::IsAddressable:
11421139
addressableLifetimeParamIndices.set(index);

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,14 +1823,12 @@ class DestructureInputs {
18231823
// is addressable-for-dependencies, then lower it with maximal abstraction
18241824
// as well.
18251825
auto &initialSubstTL = TC.getTypeLowering(origType, substType, expansion);
1826-
if (initialSubstTL.getRecursiveProperties().isAddressableForDependencies()) {
1826+
if (initialSubstTL.getRecursiveProperties()
1827+
.isAddressableForDependencies()) {
18271828
origType = AbstractionPattern::getOpaque();
18281829

1829-
// Remember that this lowered parameter is conditionally addressable in
1830-
// the addressable parameters vector.
1831-
AddressableLoweredParameters.resize(ParameterMap.size() + 1, false);
1832-
AddressableLoweredParameters[ParameterMap.size()] = true;
1833-
1830+
// Remember that this lowered parameter is conditionally
1831+
// addressable. Specialization may clear this flag.
18341832
ConditionallyAddressableLoweredParameters
18351833
.resize(ParameterMap.size() + 1, false);
18361834
ConditionallyAddressableLoweredParameters[ParameterMap.size()] = true;

0 commit comments

Comments
 (0)