Skip to content

Commit a3815fb

Browse files
authored
Merge pull request #81291 from eeckstein/fix-false-error-in-sourcekit-6.2
[6.2] embedded: avoid false error "Deinit of non-copyable type not visible in the current module" in SourceKit
2 parents 44ecddd + 7e212a8 commit a3815fb

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
@@ -137,11 +137,17 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
137137
// We need to de-virtualize deinits of non-copyable types to be able to specialize the deinitializers.
138138
case let destroyValue as DestroyValueInst:
139139
if !devirtualizeDeinits(of: destroyValue, simplifyCtxt) {
140-
context.diagnosticEngine.diagnose(destroyValue.location.sourceLoc, .deinit_not_visible)
140+
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
141+
if moduleContext.enableWMORequiredDiagnostics {
142+
context.diagnosticEngine.diagnose(destroyValue.location.sourceLoc, .deinit_not_visible)
143+
}
141144
}
142145
case let destroyAddr as DestroyAddrInst:
143146
if !devirtualizeDeinits(of: destroyAddr, simplifyCtxt) {
144-
context.diagnosticEngine.diagnose(destroyAddr.location.sourceLoc, .deinit_not_visible)
147+
// If invoked from SourceKit avoid reporting false positives when WMO is turned off for indexing purposes.
148+
if moduleContext.enableWMORequiredDiagnostics {
149+
context.diagnosticEngine.diagnose(destroyAddr.location.sourceLoc, .deinit_not_visible)
150+
}
145151
}
146152

147153
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)