Merge pull request #75308 from kubamracek/embedded-indexing-non-wmo

[embedded] Don't produce PerfDiags when in non-WMO mode (e.g. when building during indexing)
This commit is contained in:
Kuba (Brecka) Mracek
2024-08-12 23:29:30 -07:00
committed by GitHub
4 changed files with 48 additions and 0 deletions

View File

@@ -150,6 +150,10 @@ public:
/// Enables SIL-level diagnostics for NonescapableTypes.
bool EnableLifetimeDependenceDiagnostics = true;
/// Enables SIL-level performance diagnostics (for @noLocks, @noAllocation
/// annotations and for Embedded Swift).
bool EnablePerformanceDiagnostics = true;
/// Controls whether or not paranoid verification checks are run.
bool VerifyAll = false;

View File

@@ -805,6 +805,11 @@ private:
void run() override {
SILModule *module = getModule();
// Skip all performance/embedded diagnostics if asked. This is used from
// SourceKit to avoid reporting false positives when WMO is turned off for
// indexing purposes.
if (!module->getOptions().EnablePerformanceDiagnostics) return;
PerformanceDiagnostics diagnoser(*module, getAnalysis<BasicCalleeAnalysis>());
// Check that @_section, @_silgen_name is only on constant globals

View File

@@ -0,0 +1,34 @@
// Check that when emitting diagnostics in SourceKit, we don't report false positives in PerformanceDiagnostics (because WMO is disabled).
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// 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
// REQUIRES: swift_in_compiler
// REQUIRES: embedded_stdlib
// REQUIRES: OS=macosx
//--- file1.swift
func foo() {
bar(Int.self)
}
@main
struct Main {
static func main() {
foo()
}
}
//--- file2.swift
func bar<T>(_ T: T.Type) {
}
// CHECK: {
// CHECK-NEXT: key.diagnostics: [
// CHECK-NEXT: ]
// CHECK-NEXT: }

View File

@@ -1217,6 +1217,11 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
// flag and might thus fail, which SILGen cannot handle.
llvm::SaveAndRestore<std::shared_ptr<std::atomic<bool>>> DisableCancellationDuringSILGen(CompIns.getASTContext().CancellationFlag, nullptr);
SILOptions SILOpts = Invocation.getSILOptions();
// Disable PerformanceDiagnostics SIL pass, which in some cases requires
// WMO (e.g. for Embedded Swift diags) but SourceKit compiles without WMO.
SILOpts.EnablePerformanceDiagnostics = false;
auto &TC = CompIns.getSILTypes();
std::unique_ptr<SILModule> SILMod = performASTLowering(*SF, TC, SILOpts);
if (CancellationFlag->load(std::memory_order_relaxed)) {