Skip to content

Commit f6899ed

Browse files
committed
[SourceKit] Suppress oslog_invalid_log_message diagnostic in live issues
The index build skips *all* function bodies, including inlinable. The `OSLogOptimization` pass expects SIL for inlinable bodies and thus outputs a spurious diagnostic for live issues when the `OSLogInterpolation` extension is in a separate module to the log statement. Ignore this for now, but we may need to re-evaluate if this becomes a more widespread problem. Resolves rdar://79100763
1 parent b12ab96 commit f6899ed

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

test/SourceKit/Sema/oslog.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// REQUIRES: VENDOR=apple
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %{python} %utils/split_file.py -o %t %s
5+
6+
// RUN: %target-build-swift -emit-module -module-name Lib -o %t -Xfrontend -experimental-allow-module-with-compiler-errors -Xfrontend -experimental-skip-all-function-bodies %t/lib.swift
7+
// RUN: %sourcekitd-test -req=sema %t/main.swift -- %t/main.swift -I%t -sdk %sdk -Xfrontend -experimental-allow-module-with-compiler-errors | %FileCheck %s
8+
// CHECK-NOT: oslog_invalid_log_message
9+
10+
// BEGIN lib.swift
11+
import os
12+
13+
public struct Foo {
14+
public let prop: String
15+
public init() { self.prop = "boop" }
16+
}
17+
18+
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
19+
extension OSLogInterpolation {
20+
@_optimize(none)
21+
@_transparent
22+
@_semantics("oslog.requires_constant_arguments")
23+
public mutating func appendInterpolation(_ value: @autoclosure @escaping () -> Foo) {
24+
let v = value()
25+
appendInterpolation(v.prop)
26+
}
27+
}
28+
29+
// BEGIN main.swift
30+
import os
31+
import Lib
32+
33+
if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
34+
let logger = Logger()
35+
logger.log("Log a foo: \(Foo())")
36+
}

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/AST/DiagnosticsClangImporter.h"
2828
#include "swift/AST/DiagnosticsParse.h"
2929
#include "swift/AST/DiagnosticsFrontend.h"
30+
#include "swift/AST/DiagnosticsSIL.h"
3031
#include "swift/Basic/SourceManager.h"
3132
#include "swift/Demangling/ManglingUtils.h"
3233
#include "swift/Frontend/Frontend.h"
@@ -83,7 +84,13 @@ void EditorDiagConsumer::handleDiagnostic(SourceManager &SM,
8384
}
8485

8586
// Filter out benign diagnostics for editing.
86-
if (Info.ID == diag::lex_editor_placeholder.ID)
87+
// oslog_invalid_log_message is spuriously output for live issues as modules
88+
// in the index build are built without function bodies (including inline
89+
// functions). OSLogOptimization expects SIL for bodies and hence errors
90+
// when there isn't any. Ignore in live issues for now and re-evaluate if
91+
// this (not having SIL for inline functions) becomes a more widespread issue.
92+
if (Info.ID == diag::lex_editor_placeholder.ID ||
93+
Info.ID == diag::oslog_invalid_log_message.ID)
8794
return;
8895

8996
bool IsNote = (Info.Kind == DiagnosticKind::Note);

0 commit comments

Comments
 (0)