File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
lib/SILOptimizer/Mandatory
test/SourceKit/Diagnostics
tools/SourceKit/lib/SwiftLang Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,10 @@ class SILOptions {
150150 // / Enables SIL-level diagnostics for NonescapableTypes.
151151 bool EnableLifetimeDependenceDiagnostics = true ;
152152
153+ // / Enables SIL-level performance diagnostics (for @noLocks, @noAllocation
154+ // / annotations and for Embedded Swift).
155+ bool EnablePerformanceDiagnostics = true ;
156+
153157 // / Controls whether or not paranoid verification checks are run.
154158 bool VerifyAll = false ;
155159
Original file line number Diff line number Diff line change @@ -805,6 +805,11 @@ class PerformanceDiagnosticsPass : public SILModuleTransform {
805805 void run () override {
806806 SILModule *module = getModule ();
807807
808+ // Skip all performance/embedded diagnostics if asked. This is used from
809+ // SourceKit to avoid reporting false positives when WMO is turned off for
810+ // indexing purposes.
811+ if (!module ->getOptions ().EnablePerformanceDiagnostics ) return ;
812+
808813 PerformanceDiagnostics diagnoser (*module , getAnalysis<BasicCalleeAnalysis>());
809814
810815 // Check that @_section, @_silgen_name is only on constant globals
Original file line number Diff line number Diff line change 1+ // Check that when emitting diagnostics in SourceKit, we don't report false positives in PerformanceDiagnostics (because WMO is disabled).
2+
3+ // RUN: %empty-directory(%t)
4+ // RUN: split-file %s %t
5+
6+ // RUN: %sourcekitd-test -req=diags %t/file1.swift -- %t/file1.swift %t/file2.swift -enable-experimental-feature Embedded -target %target-cpu-apple-macos14 | %FileCheck %s
7+
8+ // REQUIRES: swift_in_compiler
9+ // REQUIRES: embedded_stdlib
10+ // REQUIRES: OS=macosx
11+
12+ //--- file1.swift
13+
14+ func foo( ) {
15+ bar ( Int . self)
16+ }
17+
18+ @main
19+ struct Main {
20+ static func main( ) {
21+ foo ( )
22+ }
23+ }
24+
25+ //--- file2.swift
26+
27+ func bar< T> ( _ T: T . Type ) {
28+
29+ }
30+
31+ // CHECK: {
32+ // CHECK-NEXT: key.diagnostics: [
33+ // CHECK-NEXT: ]
34+ // CHECK-NEXT: }
Original file line number Diff line number Diff line change @@ -1217,6 +1217,11 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
12171217 // flag and might thus fail, which SILGen cannot handle.
12181218 llvm::SaveAndRestore<std::shared_ptr<std::atomic<bool >>> DisableCancellationDuringSILGen (CompIns.getASTContext ().CancellationFlag , nullptr );
12191219 SILOptions SILOpts = Invocation.getSILOptions ();
1220+
1221+ // Disable PerformanceDiagnostics SIL pass, which in some cases requires
1222+ // WMO (e.g. for Embedded Swift diags) but SourceKit compiles without WMO.
1223+ SILOpts.EnablePerformanceDiagnostics = false ;
1224+
12201225 auto &TC = CompIns.getSILTypes ();
12211226 std::unique_ptr<SILModule> SILMod = performASTLowering (*SF, TC, SILOpts);
12221227 if (CancellationFlag->load (std::memory_order_relaxed)) {
You can’t perform that action at this time.
0 commit comments