Skip to content

Commit 40bcc74

Browse files
committed
[OSSACanOwned] Don't dead-end extend if consumed.
When the utility is used by the ConsumeOperatorCopyableValuesChecker, the checker guarantees that the lifetime can end at the consumes, that there are no uses after those consumes. In that circumstance, the utility maintains liveness to those consumes and as far as possible without introducing a copy everywhere else. The lack of complete lifetimes has forced the utility to extend liveness of values to dead-ends. That extension, however, is in tension with the use that the checker is putting the utility to. If there is a dead-end after a consume, liveness must not be maintained to that dead-end. rdar://147586673
1 parent 6ff0c07 commit 40bcc74

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

+6
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,12 @@ class CanonicalizeOSSALifetime final {
469469
return explicitLifetimeEnds.size() > 0;
470470
}
471471

472+
bool respectsDeadEnds() const {
473+
// TODO: OSSALifetimeCompletion: Once lifetimes are always complete, delete
474+
// this method.
475+
return !endingLifetimeAtExplicitEnds();
476+
}
477+
472478
bool respectsDeinitBarriers() const {
473479
if (!currentDef->isLexical())
474480
return false;

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1406,10 +1406,12 @@ bool CanonicalizeOSSALifetime::computeLiveness() {
14061406
clear();
14071407
return false;
14081408
}
1409-
if (respectsDeinitBarriers()) {
1410-
extendLexicalLivenessToDeadEnds();
1409+
if (respectsDeadEnds()) {
1410+
if (respectsDeinitBarriers()) {
1411+
extendLexicalLivenessToDeadEnds();
1412+
}
1413+
extendLivenessToDeadEnds();
14111414
}
1412-
extendLivenessToDeadEnds();
14131415
if (respectsDeinitBarriers()) {
14141416
extendLivenessToDeinitBarriers();
14151417
}

test/Interpreter/consume_operator_kills_copyable_values.swift.gyb

+15
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ func testNested2_${introducer}(_ c1: Bool, _ c2: Bool) {
176176
end([c1, c2])
177177
}
178178

179+
// CHECK-LABEL: begin testDeadEnd_{{let|var}}(_:)(true)
180+
// CHECK: hi
181+
// CHECK: adios
182+
// CHECK: barrier
183+
// CHECK-LABEL: end testDeadEnd_{{let|var}}(_:)(true)
184+
func testDeadEnd_${introducer}(_ condition: Bool) {
185+
begin([condition])
186+
${introducer} x = X(0)
187+
_ = consume x
188+
guard condition else { fatalError() }
189+
barrier()
190+
end([condition])
191+
}
192+
179193
func main_${introducer}() {
180194
simple_${introducer}()
181195
testLeft_${introducer}(true)
@@ -188,6 +202,7 @@ func main_${introducer}() {
188202
testNested2_${introducer}(false, true)
189203
testNested2_${introducer}(true, false)
190204
testNested2_${introducer}(true, true)
205+
testDeadEnd_${introducer}(true)
191206
}
192207

193208
% end

0 commit comments

Comments
 (0)