Skip to content

Commit 25825e2

Browse files
committed
SwiftCompilerSources: use Type.isVoid instead of Type.isEmpty.
1 parent 0958bdd commit 25825e2

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

SwiftCompilerSources/Sources/SIL/ApplySite.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ extension FullApplySite {
301301
beginApply.yieldedValues.forEach { values.push($0) }
302302
} else {
303303
let result = singleDirectResult!
304-
if !result.type.isEmpty(in: parentFunction) {
304+
if !result.type.isVoid {
305305
values.push(result)
306306
}
307307
}

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
9595
bridged.isExactSuperclassOf(type.bridged)
9696
}
9797

98+
public var isVoid: Bool {
99+
bridged.isVoid()
100+
}
101+
98102
public func isEmpty(in function: Function) -> Bool {
99103
bridged.isEmpty(function.bridged)
100104
}

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ struct BridgedType {
405405
BRIDGED_INLINE bool containsNoEscapeFunction() const;
406406
BRIDGED_INLINE bool isThickFunction() const;
407407
BRIDGED_INLINE bool isAsyncFunction() const;
408+
BRIDGED_INLINE bool isVoid() const;
408409
BRIDGED_INLINE bool isEmpty(BridgedFunction f) const;
409410
BRIDGED_INLINE TraitResult canBeClass() const;
410411
BRIDGED_INLINE bool isMoveOnly() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ bool BridgedType::isAsyncFunction() const {
316316
return unbridged().isAsyncFunction();
317317
}
318318

319+
bool BridgedType::isVoid() const {
320+
return unbridged().isVoid();
321+
}
322+
319323
bool BridgedType::isEmpty(BridgedFunction f) const {
320324
return unbridged().isEmpty(*f.getFunction());
321325
}

test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow_fail.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@ struct NC : ~Copyable {
2929
borrowing func getBV() -> dependsOn(self) BV {
3030
BV(p, i)
3131
}
32+
33+
borrowing func getEmpty() -> Empty {
34+
Empty()
35+
}
3236
}
3337

38+
// Test dependencies on an empty struct.
39+
public struct Empty: ~Escapable {}
40+
41+
func use(e: Empty) {}
42+
3443
struct NE : ~Escapable {
3544
let p: UnsafeRawPointer
3645
let i: Int
@@ -68,3 +77,12 @@ let nc = NC(ptr, 0) // expected-error {{lifetime-dependent variable 'nc' escapes
6877
func bv_global(dummy: BV) -> BV {
6978
nc.getBV()
7079
} // expected-note {{this use causes the lifetime-dependent value to escape}}
80+
81+
func testEmpty(nc: consuming NC) {
82+
var e: Empty // expected-error {{lifetime-dependent variable 'e' escapes its scope}}
83+
do {
84+
let inner = nc // expected-note {{it depends on the lifetime of variable 'inner'}}
85+
e = inner.getEmpty()
86+
}
87+
use(e: e) // expected-note {{this use of the lifetime-dependent value is out of scope}}
88+
}

0 commit comments

Comments
 (0)