Skip to content

Commit e212093

Browse files
authored
Merge pull request #81285 from eeckstein/fix-false-error-in-sourcekit
embedded: avoid false error "Deinit of non-copyable type not visible in the current module" in SourceKit
2 parents 3022270 + 08ce2f0 commit e212093

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,17 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
151151
// We need to de-virtualize deinits of non-copyable types to be able to specialize the deinitializers.
152152
case let destroyValue as DestroyValueInst:
153153
if !devirtualizeDeinits(of: destroyValue, simplifyCtxt) {
154-
context.diagnosticEngine.diagnose(.deinit_not_visible, at: destroyValue.location)
154+
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
155+
if moduleContext.enableWMORequiredDiagnostics {
156+
context.diagnosticEngine.diagnose(.deinit_not_visible, at: destroyValue.location)
157+
}
155158
}
156159
case let destroyAddr as DestroyAddrInst:
157160
if !devirtualizeDeinits(of: destroyAddr, simplifyCtxt) {
158-
context.diagnosticEngine.diagnose(.deinit_not_visible, at: destroyAddr.location)
161+
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
162+
if moduleContext.enableWMORequiredDiagnostics {
163+
context.diagnosticEngine.diagnose(.deinit_not_visible, at: destroyAddr.location)
164+
}
159165
}
160166

161167
case let iem as InitExistentialMetatypeInst:

test/SourceKit/Diagnostics/embedded_non_wmo.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func foo() {
1616
bar(Int.self)
1717
}
1818

19+
func testNonCopyable() {
20+
let nc = NonCopyable()
21+
nc.doSomething()
22+
}
23+
1924
@main
2025
struct Main {
2126
var someClass = SomeClass()
@@ -31,6 +36,11 @@ final class SomeClass {}
3136

3237
func bar<T>(_ T: T.Type) {}
3338

39+
struct NonCopyable : ~Copyable {
40+
func doSomething() {}
41+
deinit {}
42+
}
43+
3444
// CHECK: {
3545
// CHECK-NEXT: key.diagnostics: [
3646
// CHECK-NEXT: ]

0 commit comments

Comments
 (0)