Skip to content

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

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
May 5, 2025
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 @@ -151,11 +151,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(.deinit_not_visible, at: destroyValue.location)
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
if moduleContext.enableWMORequiredDiagnostics {
context.diagnosticEngine.diagnose(.deinit_not_visible, at: destroyValue.location)
}
}
case let destroyAddr as DestroyAddrInst:
if !devirtualizeDeinits(of: destroyAddr, simplifyCtxt) {
context.diagnosticEngine.diagnose(.deinit_not_visible, at: destroyAddr.location)
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
if moduleContext.enableWMORequiredDiagnostics {
context.diagnosticEngine.diagnose(.deinit_not_visible, at: destroyAddr.location)
}
}

case let iem as InitExistentialMetatypeInst:
Expand Down
10 changes: 10 additions & 0 deletions test/SourceKit/Diagnostics/embedded_non_wmo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func foo() {
bar(Int.self)
}

func testNonCopyable() {
let nc = NonCopyable()
nc.doSomething()
}

@main
struct Main {
var someClass = SomeClass()
Expand All @@ -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: ]
Expand Down