Skip to content

Commit c32c238

Browse files
committed
Fix LifetimeDependenceDiagnostics to handle invalid SIL types
Invalid types are not considered Escapable. This makes it difficult to make any assumptions about nonescapable types. Fixes rdar://132348528 (Fix LifetimeDependenceDiagnostics to handle invalid SIL types)
1 parent a22dd98 commit c32c238

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ extension LifetimeDependence {
195195
if arg.isIndirectResult {
196196
return nil
197197
}
198-
self.scope = Scope(base: arg, context)!
198+
guard let scope = Scope(base: arg, context) else {
199+
// Ignore invalid argument types.
200+
return nil
201+
}
202+
self.scope = scope
199203
self.dependentValue = arg
200204
}
201205

@@ -309,7 +313,7 @@ extension LifetimeDependence.Scope {
309313
}
310314
self = scope
311315
case .none:
312-
// lifetime dependence requires a nontrivial value"
316+
// lifetime dependence requires a nontrivial value
313317
return nil
314318
case .unowned:
315319
self = .unknown(base)

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
6565

6666
public var isMoveOnly: Bool { bridged.isMoveOnly() }
6767

68+
// Note that invalid types are not considered Escapable. This makes it difficult to make any assumptions about
69+
// nonescapable types.
6870
public func isEscapable(in function: Function) -> Bool {
6971
bridged.isEscapable(function.bridged)
7072
}

test/SIL/lazy_typecheck.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -emit-sil %s -parse-as-library -enable-library-evolution -module-name Test -experimental-lazy-typecheck -verify
2+
3+
// SIL diagnostics should not crash on invalid types.
4+
final class C {
5+
private let x: Nonexistent // expected-error {{cannot find type 'Nonexistent' in scope}}
6+
7+
init(x: Nonexistent) { // expected-error {{cannot find type 'Nonexistent' in scope}}
8+
self.x = x
9+
}
10+
}

0 commit comments

Comments
 (0)