embedded: avoid false error "Deinit of non-copyable type not visible in the current module" in SourceKit

As SourceKit explicitly disables WMO, silence the diagnostic in this case (but leave it enabled for explicit non-WMO builds otherwise).

rdar://150596807
This commit is contained in:
Erik Eckstein
2025-05-05 09:19:08 +02:00
parent 4cde33c4b0
commit 7e212a8580
2 changed files with 18 additions and 2 deletions

View File

@@ -137,11 +137,17 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
// We need to de-virtualize deinits of non-copyable types to be able to specialize the deinitializers.
case let destroyValue as DestroyValueInst:
if !devirtualizeDeinits(of: destroyValue, simplifyCtxt) {
context.diagnosticEngine.diagnose(destroyValue.location.sourceLoc, .deinit_not_visible)
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
if moduleContext.enableWMORequiredDiagnostics {
context.diagnosticEngine.diagnose(destroyValue.location.sourceLoc, .deinit_not_visible)
}
}
case let destroyAddr as DestroyAddrInst:
if !devirtualizeDeinits(of: destroyAddr, simplifyCtxt) {
context.diagnosticEngine.diagnose(destroyAddr.location.sourceLoc, .deinit_not_visible)
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
if moduleContext.enableWMORequiredDiagnostics {
context.diagnosticEngine.diagnose(destroyAddr.location.sourceLoc, .deinit_not_visible)
}
}
case let iem as InitExistentialMetatypeInst:

View File

@@ -16,6 +16,11 @@ func foo() {
bar(Int.self)
}
func testNonCopyable() {
let nc = NonCopyable()
nc.doSomething()
}
@main
struct Main {
var someClass = SomeClass()
@@ -31,6 +36,11 @@ final class SomeClass {}
func bar<T>(_ T: T.Type) {}
struct NonCopyable : ~Copyable {
func doSomething() {}
deinit {}
}
// CHECK: {
// CHECK-NEXT: key.diagnostics: [
// CHECK-NEXT: ]