Skip to content

Commit 36d2b5b

Browse files
committed
Fix lifetime dependence diagnostics on Void types.
Allow a dependence on Void to be considered immortal. This is the ultimate override in cases where no other code pattern is supported yet.
1 parent bcc4a78 commit 36d2b5b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,16 @@ private struct DiagnoseDependence {
199199
if function.hasUnsafeNonEscapableResult {
200200
return .continueWalk
201201
}
202-
// If the dependence scope is global, then it has immortal lifetime.
203-
if case .global = dependence.scope {
202+
// Check for immortal lifetime.
203+
switch dependence.scope {
204+
case .global:
204205
return .continueWalk
206+
case let .unknown(value):
207+
if value.type.isVoid {
208+
return .continueWalk
209+
}
210+
default:
211+
break
205212
}
206213
// Check that the parameter dependence for this result is the same
207214
// as the current dependence scope.

test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public struct NEInt: ~Escapable {
106106
init(owner: borrowing NCInt) {
107107
self.i = owner.i
108108
}
109+
110+
@_lifetime(immortal)
111+
init(immortal i: Int) {
112+
self.i = i
113+
}
109114
}
110115

111116
struct TestDeinitCallsAddressor: ~Copyable, ~Escapable {
@@ -228,3 +233,13 @@ class ClassStorage {
228233
_ = ne
229234
}
230235
}
236+
237+
// =============================================================================
238+
// Immortal
239+
// =============================================================================
240+
241+
@_lifetime(immortal)
242+
func testVoid() -> NEInt {
243+
let ne = NEInt(immortal: 3)
244+
return _overrideLifetime(ne, borrowing: ())
245+
}

0 commit comments

Comments
 (0)