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)
This commit is contained in:
Andrew Trick
2024-07-23 16:00:18 -07:00
parent a22dd98bfa
commit c32c238720
3 changed files with 18 additions and 2 deletions

View File

@@ -195,7 +195,11 @@ extension LifetimeDependence {
if arg.isIndirectResult {
return nil
}
self.scope = Scope(base: arg, context)!
guard let scope = Scope(base: arg, context) else {
// Ignore invalid argument types.
return nil
}
self.scope = scope
self.dependentValue = arg
}
@@ -309,7 +313,7 @@ extension LifetimeDependence.Scope {
}
self = scope
case .none:
// lifetime dependence requires a nontrivial value"
// lifetime dependence requires a nontrivial value
return nil
case .unowned:
self = .unknown(base)

View File

@@ -65,6 +65,8 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
public var isMoveOnly: Bool { bridged.isMoveOnly() }
// Note that invalid types are not considered Escapable. This makes it difficult to make any assumptions about
// nonescapable types.
public func isEscapable(in function: Function) -> Bool {
bridged.isEscapable(function.bridged)
}

View File

@@ -0,0 +1,10 @@
// RUN: %target-swift-frontend -emit-sil %s -parse-as-library -enable-library-evolution -module-name Test -experimental-lazy-typecheck -verify
// SIL diagnostics should not crash on invalid types.
final class C {
private let x: Nonexistent // expected-error {{cannot find type 'Nonexistent' in scope}}
init(x: Nonexistent) { // expected-error {{cannot find type 'Nonexistent' in scope}}
self.x = x
}
}