Skip to content

Commit d60b43c

Browse files
committed
Store parameter indices of mutate lifetime dependence specifiers separately from borrow
1 parent f716c09 commit d60b43c

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

include/swift/AST/ExtInfo.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,28 @@ class ClangTypeInfo {
158158
};
159159

160160
class LifetimeDependenceInfo {
161-
IndexSubset *copyLifetimeParamIndices;
161+
IndexSubset *inheritLifetimeParamIndices;
162162
IndexSubset *borrowLifetimeParamIndices;
163+
IndexSubset *mutateLifetimeParamIndices;
163164

164165
public:
165166
LifetimeDependenceInfo()
166-
: copyLifetimeParamIndices(nullptr), borrowLifetimeParamIndices(nullptr) {
167-
}
168-
LifetimeDependenceInfo(IndexSubset *copyLifetimeParamIndices,
169-
IndexSubset *borrowLifetimeParamIndices)
170-
: copyLifetimeParamIndices(copyLifetimeParamIndices),
171-
borrowLifetimeParamIndices(borrowLifetimeParamIndices) {}
167+
: inheritLifetimeParamIndices(nullptr),
168+
borrowLifetimeParamIndices(nullptr),
169+
mutateLifetimeParamIndices(nullptr) {}
170+
LifetimeDependenceInfo(IndexSubset *inheritLifetimeParamIndices,
171+
IndexSubset *borrowLifetimeParamIndices,
172+
IndexSubset *mutateLifetimeParamIndices)
173+
: inheritLifetimeParamIndices(inheritLifetimeParamIndices),
174+
borrowLifetimeParamIndices(borrowLifetimeParamIndices),
175+
mutateLifetimeParamIndices(mutateLifetimeParamIndices) {}
172176

173177
operator bool() const { return empty(); }
174178

175179
bool empty() const {
176-
return copyLifetimeParamIndices == nullptr &&
177-
borrowLifetimeParamIndices == nullptr;
180+
return inheritLifetimeParamIndices == nullptr &&
181+
borrowLifetimeParamIndices == nullptr &&
182+
mutateLifetimeParamIndices == nullptr;
178183
}
179184
std::string getString() const;
180185
};

lib/AST/ExtInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,18 @@ std::string LifetimeDependenceInfo::getString() const {
7474
}
7575
return result;
7676
};
77-
if (!copyLifetimeParamIndices->isEmpty()) {
77+
if (!inheritLifetimeParamIndices->isEmpty()) {
7878
lifetimeDependenceString =
79-
"_copy(" + getOnIndices(copyLifetimeParamIndices) + ")";
79+
"_inherit(" + getOnIndices(inheritLifetimeParamIndices) + ")";
8080
}
8181
if (!borrowLifetimeParamIndices->isEmpty()) {
8282
lifetimeDependenceString +=
8383
"_borrow(" + getOnIndices(borrowLifetimeParamIndices) + ")";
8484
}
85+
if (!mutateLifetimeParamIndices->isEmpty()) {
86+
lifetimeDependenceString +=
87+
"_mutate(" + getOnIndices(mutateLifetimeParamIndices) + ")";
88+
}
8589
return lifetimeDependenceString;
8690
}
8791

lib/Sema/TypeCheckDecl.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,8 +2583,9 @@ llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo(
25832583
auto *dc = decl->getDeclContext();
25842584
auto &ctx = dc->getASTContext();
25852585
auto &diags = ctx.Diags;
2586-
SmallBitVector copyLifetimeParamIndices(afd->getParameters()->size() + 1);
2586+
SmallBitVector inheritLifetimeParamIndices(afd->getParameters()->size() + 1);
25872587
SmallBitVector borrowLifetimeParamIndices(afd->getParameters()->size() + 1);
2588+
SmallBitVector mutateLifetimeParamIndices(afd->getParameters()->size() + 1);
25882589

25892590
auto updateLifetimeDependenceInfo = [&](LifetimeDependenceSpecifier specifier,
25902591
unsigned paramIndexToSet,
@@ -2619,18 +2620,19 @@ llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo(
26192620
getOwnershipSpelling(ownership));
26202621
return true;
26212622
}
2622-
if (copyLifetimeParamIndices.test(paramIndexToSet) ||
2623+
if (inheritLifetimeParamIndices.test(paramIndexToSet) ||
26232624
borrowLifetimeParamIndices.test(paramIndexToSet)) {
26242625
diags.diagnose(loc, diag::lifetime_dependence_duplicate_param_id);
26252626
return true;
26262627
}
26272628
if (kind == LifetimeDependenceKind::Copy ||
26282629
kind == LifetimeDependenceKind::Consume) {
2629-
copyLifetimeParamIndices.set(paramIndexToSet);
2630-
} else {
2631-
assert(kind == LifetimeDependenceKind::Borrow ||
2632-
kind == LifetimeDependenceKind::Mutate);
2630+
inheritLifetimeParamIndices.set(paramIndexToSet);
2631+
} else if (kind == LifetimeDependenceKind::Borrow) {
26332632
borrowLifetimeParamIndices.set(paramIndexToSet);
2633+
} else {
2634+
assert(kind == LifetimeDependenceKind::Mutate);
2635+
mutateLifetimeParamIndices.set(paramIndexToSet);
26342636
}
26352637
return false;
26362638
};
@@ -2691,8 +2693,9 @@ llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo(
26912693
}
26922694

26932695
return LifetimeDependenceInfo(
2694-
IndexSubset::get(ctx, copyLifetimeParamIndices),
2695-
IndexSubset::get(ctx, borrowLifetimeParamIndices));
2696+
IndexSubset::get(ctx, inheritLifetimeParamIndices),
2697+
IndexSubset::get(ctx, borrowLifetimeParamIndices),
2698+
IndexSubset::get(ctx, mutateLifetimeParamIndices));
26962699
}
26972700

26982701
static void maybeAddParameterIsolation(AnyFunctionType::ExtInfoBuilder &infoBuilder,

0 commit comments

Comments
 (0)