Skip to content

Commit 876e847

Browse files
committed
[LifetimeCompletion] Removed "with leaks" mode.
Now that the two known issues which resulted in invalid SIL being provided to lifetime completion have been addressed, tighten up the completion done on the availability boundary not to allow leaks.
1 parent d24c764 commit 876e847

File tree

4 files changed

+15
-55
lines changed

4 files changed

+15
-55
lines changed

include/swift/SIL/OSSALifetimeCompletion.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,13 @@ class OSSALifetimeCompletion {
5757
// Availability: "As late as possible." Consume the value in the last blocks
5858
// beyond the non-consuming uses in which the value has been
5959
// consumed on no incoming paths.
60-
// AvailabilityWithLeaks: "As late as possible or later." Consume the value
61-
// in the last blocks beyond the non-consuming uses in
62-
// which the value has been consumed on no incoming
63-
// paths, unless that block's terminator isn't an
64-
// unreachable, in which case, don't consume it there.
6560
//
6661
// This boundary works around bugs where SILGen emits
6762
// illegal OSSA lifetimes.
6863
struct Boundary {
6964
enum Value : uint8_t {
7065
Liveness,
7166
Availability,
72-
AvailabilityWithLeaks,
7367
};
7468
Value value;
7569

@@ -115,11 +109,6 @@ class OSSALifetimeCompletion {
115109
: LifetimeCompletion::AlreadyComplete;
116110
}
117111

118-
enum AllowLeaks_t : bool {
119-
AllowLeaks = true,
120-
DoNotAllowLeaks = false,
121-
};
122-
123112
enum class LifetimeEnd : uint8_t {
124113
/// The lifetime ends at the boundary.
125114
Boundary,
@@ -128,8 +117,7 @@ class OSSALifetimeCompletion {
128117
};
129118

130119
static void visitAvailabilityBoundary(
131-
SILValue value, AllowLeaks_t allowLeaks,
132-
const SSAPrunedLiveness &liveness,
120+
SILValue value, const SSAPrunedLiveness &liveness,
133121
llvm::function_ref<void(SILInstruction *, LifetimeEnd end)> visit);
134122

135123
protected:
@@ -187,9 +175,6 @@ operator<<(llvm::raw_ostream &OS, OSSALifetimeCompletion::Boundary boundary) {
187175
case OSSALifetimeCompletion::Boundary::Availability:
188176
OS << "availability";
189177
break;
190-
case OSSALifetimeCompletion::Boundary::AvailabilityWithLeaks:
191-
OS << "availability_with_leaks";
192-
break;
193178
}
194179
return OS;
195180
}

lib/SIL/Utils/OSSALifetimeCompletion.cpp

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,14 @@ class AvailabilityBoundaryVisitor {
168168
/// The value whose dead-end block lifetime ends are to be visited.
169169
SILValue value;
170170

171-
/// Whether to allow leaks.
172-
///
173-
/// Here, that entails allowing walks to reach non-unreachable terminators and
174-
/// not creating lifetime ends before them.
175-
OSSALifetimeCompletion::AllowLeaks_t allowLeaks;
176-
177171
/// The non-lifetime-ending boundary of `value`.
178172
BasicBlockSet starts;
179173
/// The region between (inclusive) the `starts` and the unreachable blocks.
180174
BasicBlockSetVector region;
181175

182176
public:
183-
AvailabilityBoundaryVisitor(SILValue value,
184-
OSSALifetimeCompletion::AllowLeaks_t allowLeaks)
185-
: value(value), allowLeaks(allowLeaks), starts(value->getFunction()),
177+
AvailabilityBoundaryVisitor(SILValue value)
178+
: value(value), starts(value->getFunction()),
186179
region(value->getFunction()) {}
187180

188181
using Visit = llvm::function_ref<void(SILInstruction *,
@@ -307,10 +300,7 @@ void AvailabilityBoundaryVisitor::computeRegion(
307300
// Thus finding a value available at the end of such a block means that
308301
// the block does _not_ must not exits the function normally; in other
309302
// words its terminator must be an UnreachableInst.
310-
//
311-
// In invalid OSSA, indicated by the `allowLeaks` flag, no such guarantee
312-
// exists.
313-
assert(isa<UnreachableInst>(block->getTerminator()) || allowLeaks);
303+
assert(isa<UnreachableInst>(block->getTerminator()));
314304
}
315305
for (auto *successor : block->getSuccessorBlocks()) {
316306
regionWorklist.pushIfNotVisited(successor);
@@ -379,12 +369,6 @@ void AvailabilityBoundaryVisitor::visitAvailabilityBoundary(
379369
if (!block->succ_empty() && !hasUnavailableSuccessor()) {
380370
continue;
381371
}
382-
if (allowLeaks && block->succ_empty() &&
383-
!isa<UnreachableInst>(block->getTerminator())) {
384-
// Availability extends to the end of a function-exiting-normally block.
385-
// If leaks are allowed, don't visit.
386-
continue;
387-
}
388372
assert(hasUnavailableSuccessor() ||
389373
isa<UnreachableInst>(block->getTerminator()));
390374
visit(block->getTerminator(),
@@ -394,10 +378,10 @@ void AvailabilityBoundaryVisitor::visitAvailabilityBoundary(
394378
} // end anonymous namespace
395379

396380
void OSSALifetimeCompletion::visitAvailabilityBoundary(
397-
SILValue value, AllowLeaks_t allowLeaks, const SSAPrunedLiveness &liveness,
381+
SILValue value, const SSAPrunedLiveness &liveness,
398382
llvm::function_ref<void(SILInstruction *, LifetimeEnd end)> visit) {
399383

400-
AvailabilityBoundaryVisitor visitor(value, allowLeaks);
384+
AvailabilityBoundaryVisitor visitor(value);
401385
AvailabilityBoundaryVisitor::Result result(value->getFunction());
402386
visitor.visit(liveness, result, visit);
403387

@@ -410,12 +394,12 @@ void OSSALifetimeCompletion::visitAvailabilityBoundary(
410394
});
411395
}
412396

413-
static bool endLifetimeAtAvailabilityBoundary(
414-
SILValue value, OSSALifetimeCompletion::AllowLeaks_t allowLeaks,
415-
const SSAPrunedLiveness &liveness) {
397+
static bool
398+
endLifetimeAtAvailabilityBoundary(SILValue value,
399+
const SSAPrunedLiveness &liveness) {
416400
bool changed = false;
417401
OSSALifetimeCompletion::visitAvailabilityBoundary(
418-
value, allowLeaks, liveness, [&](auto *unreachable, auto end) {
402+
value, liveness, [&](auto *unreachable, auto end) {
419403
SILBuilderWithScope builder(unreachable);
420404
endOSSALifetime(value, end, builder);
421405
changed = true;
@@ -442,12 +426,7 @@ bool OSSALifetimeCompletion::analyzeAndUpdateLifetime(SILValue value,
442426
changed |= endLifetimeAtLivenessBoundary(value, liveness.getLiveness());
443427
break;
444428
case Boundary::Availability:
445-
changed |= endLifetimeAtAvailabilityBoundary(value, DoNotAllowLeaks,
446-
liveness.getLiveness());
447-
break;
448-
case Boundary::AvailabilityWithLeaks:
449-
changed |= endLifetimeAtAvailabilityBoundary(value, AllowLeaks,
450-
liveness.getLiveness());
429+
changed |= endLifetimeAtAvailabilityBoundary(value, liveness.getLiveness());
451430
break;
452431
}
453432
// TODO: Rebuild outer adjacent phis on demand (SILGen does not currently
@@ -472,9 +451,7 @@ static FunctionTest OSSALifetimeCompletionTest(
472451
arguments.takeString())
473452
.Case("liveness", OSSALifetimeCompletion::Boundary::Liveness)
474453
.Case("availability",
475-
OSSALifetimeCompletion::Boundary::Availability)
476-
.Case("availability_with_leaks",
477-
OSSALifetimeCompletion::Boundary::AvailabilityWithLeaks);
454+
OSSALifetimeCompletion::Boundary::Availability);
478455
llvm::outs() << "OSSA lifetime completion on " << kind
479456
<< " boundary: " << value;
480457
OSSALifetimeCompletion completion(&function, /*domInfo*/ nullptr);

lib/SILOptimizer/Mandatory/SILGenCleanup.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ bool SILGenCleanup::completeOSSALifetimes(SILFunction *function) {
118118
for (SILInstruction &inst : reverse(*block)) {
119119
for (auto result : inst.getResults()) {
120120
if (completion.completeOSSALifetime(
121-
result,
122-
OSSALifetimeCompletion::Boundary::AvailabilityWithLeaks) ==
121+
result, OSSALifetimeCompletion::Boundary::Availability) ==
123122
LifetimeCompletion::WasCompleted) {
124123
changed = true;
125124
}
@@ -128,7 +127,7 @@ bool SILGenCleanup::completeOSSALifetimes(SILFunction *function) {
128127
for (SILArgument *arg : block->getArguments()) {
129128
assert(!arg->isReborrow() && "reborrows not legal at this SIL stage");
130129
if (completion.completeOSSALifetime(
131-
arg, OSSALifetimeCompletion::Boundary::AvailabilityWithLeaks) ==
130+
arg, OSSALifetimeCompletion::Boundary::Availability) ==
132131
LifetimeCompletion::WasCompleted) {
133132
changed = true;
134133
}

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ void CanonicalizeOSSALifetime::extendLivenessToDeinitBarriers() {
274274
}
275275

276276
OSSALifetimeCompletion::visitAvailabilityBoundary(
277-
getCurrentDef(), OSSALifetimeCompletion::DoNotAllowLeaks,
278-
completeLiveness, [&](auto *unreachable, auto end) {
277+
getCurrentDef(), completeLiveness, [&](auto *unreachable, auto end) {
279278
if (end == OSSALifetimeCompletion::LifetimeEnd::Boundary) {
280279
recordUnreachableLifetimeEnd(unreachable);
281280
}

0 commit comments

Comments
 (0)