Skip to content

Commit 180fccf

Browse files
committed
Add some convenience functions to LifetimeDependenceInfo
1 parent db424e2 commit 180fccf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/swift/AST/LifetimeDependence.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class LifetimeDependenceInfo {
166166

167167
std::string getString() const;
168168
void Profile(llvm::FoldingSetNodeID &ID) const;
169+
void getConcatenatedData(SmallVectorImpl<bool> &concatenatedData) const;
169170

170171
static llvm::Optional<LifetimeDependenceInfo>
171172
get(AbstractFunctionDecl *decl, Type resultType, bool allowIndex = false);

lib/Sema/LifetimeDependence.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,33 @@ LifetimeDependenceInfo LifetimeDependenceInfo::getForParamIndex(
8585
/*mutateLifetimeParamIndices*/ indexSubset};
8686
}
8787

88+
void LifetimeDependenceInfo::getConcatenatedData(
89+
SmallVectorImpl<bool> &concatenatedData) const {
90+
auto pushData = [&](IndexSubset *paramIndices) {
91+
if (paramIndices == nullptr) {
92+
return;
93+
}
94+
assert(!paramIndices->isEmpty());
95+
96+
for (auto i = 0; i < paramIndices->getCapacity(); i++) {
97+
if (paramIndices->contains(i)) {
98+
concatenatedData.push_back(true);
99+
continue;
100+
}
101+
concatenatedData.push_back(false);
102+
}
103+
};
104+
if (hasInheritLifetimeParamIndices()) {
105+
pushData(inheritLifetimeParamIndices);
106+
}
107+
if (hasBorrowLifetimeParamIndices()) {
108+
pushData(borrowLifetimeParamIndices);
109+
}
110+
if (hasMutateLifetimeParamIndices()) {
111+
pushData(mutateLifetimeParamIndices);
112+
}
113+
}
114+
88115
llvm::Optional<LifetimeDependenceInfo>
89116
LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
90117
bool allowIndex) {

0 commit comments

Comments
 (0)