Skip to content

Commit a66b7b6

Browse files
committed
Don't represent mutate lifetime dependence separately
1 parent f9e6478 commit a66b7b6

File tree

5 files changed

+17
-52
lines changed

5 files changed

+17
-52
lines changed

include/swift/AST/LifetimeDependence.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class LifetimeDependenceSpecifier {
132132
class LifetimeDependenceInfo {
133133
IndexSubset *inheritLifetimeParamIndices;
134134
IndexSubset *borrowLifetimeParamIndices;
135-
IndexSubset *mutateLifetimeParamIndices;
136135

137136
static LifetimeDependenceInfo getForParamIndex(AbstractFunctionDecl *afd,
138137
unsigned index,
@@ -147,21 +146,17 @@ class LifetimeDependenceInfo {
147146
public:
148147
LifetimeDependenceInfo()
149148
: inheritLifetimeParamIndices(nullptr),
150-
borrowLifetimeParamIndices(nullptr),
151-
mutateLifetimeParamIndices(nullptr) {}
149+
borrowLifetimeParamIndices(nullptr) {}
152150
LifetimeDependenceInfo(IndexSubset *inheritLifetimeParamIndices,
153-
IndexSubset *borrowLifetimeParamIndices,
154-
IndexSubset *mutateLifetimeParamIndices)
151+
IndexSubset *borrowLifetimeParamIndices)
155152
: inheritLifetimeParamIndices(inheritLifetimeParamIndices),
156-
borrowLifetimeParamIndices(borrowLifetimeParamIndices),
157-
mutateLifetimeParamIndices(mutateLifetimeParamIndices) {}
153+
borrowLifetimeParamIndices(borrowLifetimeParamIndices) {}
158154

159155
operator bool() const { return !empty(); }
160156

161157
bool empty() const {
162158
return inheritLifetimeParamIndices == nullptr &&
163-
borrowLifetimeParamIndices == nullptr &&
164-
mutateLifetimeParamIndices == nullptr;
159+
borrowLifetimeParamIndices == nullptr;
165160
}
166161

167162
bool hasInheritLifetimeParamIndices() const {
@@ -170,9 +165,6 @@ class LifetimeDependenceInfo {
170165
bool hasBorrowLifetimeParamIndices() const {
171166
return borrowLifetimeParamIndices != nullptr;
172167
}
173-
bool hasMutateLifetimeParamIndices() const {
174-
return mutateLifetimeParamIndices != nullptr;
175-
}
176168

177169
std::string getString() const;
178170
void Profile(llvm::FoldingSetNodeID &ID) const;

lib/Sema/LifetimeDependence.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ std::string LifetimeDependenceInfo::getString() const {
4444
lifetimeDependenceString +=
4545
"_borrow(" + getOnIndices(borrowLifetimeParamIndices) + ")";
4646
}
47-
if (mutateLifetimeParamIndices && !mutateLifetimeParamIndices->isEmpty()) {
48-
lifetimeDependenceString +=
49-
"_mutate(" + getOnIndices(mutateLifetimeParamIndices) + ")";
50-
}
5147
return lifetimeDependenceString;
5248
}
5349

@@ -58,9 +54,6 @@ void LifetimeDependenceInfo::Profile(llvm::FoldingSetNodeID &ID) const {
5854
if (borrowLifetimeParamIndices) {
5955
borrowLifetimeParamIndices->Profile(ID);
6056
}
61-
if (mutateLifetimeParamIndices) {
62-
mutateLifetimeParamIndices->Profile(ID);
63-
}
6457
}
6558

6659
LifetimeDependenceInfo LifetimeDependenceInfo::getForParamIndex(
@@ -71,18 +64,12 @@ LifetimeDependenceInfo LifetimeDependenceInfo::getForParamIndex(
7164
auto indexSubset = IndexSubset::get(ctx, capacity, {index});
7265
if (ownership == ValueOwnership::Owned) {
7366
return LifetimeDependenceInfo{/*inheritLifetimeParamIndices*/ indexSubset,
74-
/*borrowLifetimeParamIndices*/ nullptr,
75-
/*mutateLifetimeParamIndices*/ nullptr};
76-
}
77-
if (ownership == ValueOwnership::Shared) {
78-
return LifetimeDependenceInfo{/*inheritLifetimeParamIndices*/ nullptr,
79-
/*borrowLifetimeParamIndices*/ indexSubset,
80-
/*mutateLifetimeParamIndices*/ nullptr};
67+
/*borrowLifetimeParamIndices*/ nullptr};
8168
}
82-
assert(ownership == ValueOwnership::InOut);
69+
assert(ownership == ValueOwnership::Shared ||
70+
ownership == ValueOwnership::InOut);
8371
return LifetimeDependenceInfo{/*inheritLifetimeParamIndices*/ nullptr,
84-
/*borrowLifetimeParamIndices*/ nullptr,
85-
/*mutateLifetimeParamIndices*/ indexSubset};
72+
/*borrowLifetimeParamIndices*/ indexSubset};
8673
}
8774

8875
void LifetimeDependenceInfo::getConcatenatedData(
@@ -107,9 +94,6 @@ void LifetimeDependenceInfo::getConcatenatedData(
10794
if (hasBorrowLifetimeParamIndices()) {
10895
pushData(borrowLifetimeParamIndices);
10996
}
110-
if (hasMutateLifetimeParamIndices()) {
111-
pushData(mutateLifetimeParamIndices);
112-
}
11397
}
11498

11599
llvm::Optional<LifetimeDependenceInfo>
@@ -124,7 +108,6 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
124108

125109
SmallBitVector inheritLifetimeParamIndices(capacity);
126110
SmallBitVector borrowLifetimeParamIndices(capacity);
127-
SmallBitVector mutateLifetimeParamIndices(capacity);
128111

129112
auto updateLifetimeDependenceInfo = [&](LifetimeDependenceSpecifier specifier,
130113
unsigned paramIndexToSet,
@@ -167,11 +150,10 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
167150
if (kind == LifetimeDependenceKind::Copy ||
168151
kind == LifetimeDependenceKind::Consume) {
169152
inheritLifetimeParamIndices.set(paramIndexToSet);
170-
} else if (kind == LifetimeDependenceKind::Borrow) {
171-
borrowLifetimeParamIndices.set(paramIndexToSet);
172153
} else {
173-
assert(kind == LifetimeDependenceKind::Mutate);
174-
mutateLifetimeParamIndices.set(paramIndexToSet);
154+
assert(kind == LifetimeDependenceKind::Borrow ||
155+
kind == LifetimeDependenceKind::Mutate);
156+
borrowLifetimeParamIndices.set(paramIndexToSet);
175157
}
176158
return false;
177159
};
@@ -247,9 +229,6 @@ LifetimeDependenceInfo::fromTypeRepr(AbstractFunctionDecl *afd, Type resultType,
247229
: nullptr,
248230
borrowLifetimeParamIndices.any()
249231
? IndexSubset::get(ctx, borrowLifetimeParamIndices)
250-
: nullptr,
251-
mutateLifetimeParamIndices.any()
252-
? IndexSubset::get(ctx, mutateLifetimeParamIndices)
253232
: nullptr);
254233
}
255234

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8610,12 +8610,11 @@ bool ModuleFile::maybeReadLifetimeDependence(
86108610
return false;
86118611
}
86128612

8613-
bool hasInheritLifetimeParamIndices, hasBorrowLifetimeParamIndices,
8614-
hasMutateLifetimeParamIndices;
8613+
bool hasInheritLifetimeParamIndices, hasBorrowLifetimeParamIndices;
86158614
ArrayRef<uint64_t> lifetimeDependenceData;
8616-
LifetimeDependenceLayout::readRecord(
8617-
scratch, hasInheritLifetimeParamIndices, hasBorrowLifetimeParamIndices,
8618-
hasMutateLifetimeParamIndices, lifetimeDependenceData);
8615+
LifetimeDependenceLayout::readRecord(scratch, hasInheritLifetimeParamIndices,
8616+
hasBorrowLifetimeParamIndices,
8617+
lifetimeDependenceData);
86198618

86208619
unsigned startIndex = 0;
86218620
auto pushData = [&](LifetimeDependenceKind kind) {
@@ -8635,8 +8634,5 @@ bool ModuleFile::maybeReadLifetimeDependence(
86358634
if (hasBorrowLifetimeParamIndices) {
86368635
pushData(LifetimeDependenceKind::Borrow);
86378636
}
8638-
if (hasMutateLifetimeParamIndices) {
8639-
pushData(LifetimeDependenceKind::Mutate);
8640-
}
86418637
return true;
86428638
}

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 848; // inroduced a package SIL linkage
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 849; // update LifetimeDependence
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -2179,7 +2179,6 @@ namespace decls_block {
21792179
BCRecordLayout<LIFETIME_DEPENDENCE,
21802180
BCFixed<1>, // hasInheritLifetimeParamIndices
21812181
BCFixed<1>, // hasBorrowLifetimeParamIndices
2182-
BCFixed<1>, // hasMutateLifetimeParamIndices
21832182
BCArray<BCFixed<1>> // concatenated param indices
21842183
>;
21852184

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,8 +3517,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
35173517
LifetimeDependenceLayout::emitRecord(
35183518
S.Out, S.ScratchRecord, abbrCode,
35193519
lifetimeDependenceInfo.hasInheritLifetimeParamIndices(),
3520-
lifetimeDependenceInfo.hasBorrowLifetimeParamIndices(),
3521-
lifetimeDependenceInfo.hasMutateLifetimeParamIndices(), paramIndices);
3520+
lifetimeDependenceInfo.hasBorrowLifetimeParamIndices(), paramIndices);
35223521
}
35233522

35243523
void writeGenericParams(const GenericParamList *genericParams) {

0 commit comments

Comments
 (0)