Skip to content

Fix LifetimeDependenceDiagnostics to handle invalid SIL types #75428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions SwiftCompilerSources/Sources/SIL/Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions test/SIL/lazy_typecheck.swift
Original file line number Diff line number Diff line change
@@ -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
}
}