From 5d59a8fe16ae41ed70310d6fb8b5775d74bca05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 31 Oct 2022 07:48:43 -0700 Subject: [PATCH] [ModuleInterface] Implement silencing errors on rebuild with a new engine --- lib/Frontend/ModuleInterfaceBuilder.cpp | 10 +++++++- ...index_system_modules_swiftinterfaces.swift | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/Frontend/ModuleInterfaceBuilder.cpp b/lib/Frontend/ModuleInterfaceBuilder.cpp index 14d6d3ebc6d..c6f600d4bd1 100644 --- a/lib/Frontend/ModuleInterfaceBuilder.cpp +++ b/lib/Frontend/ModuleInterfaceBuilder.cpp @@ -320,11 +320,19 @@ bool ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal( llvm::RestorePrettyStackState(savedInnerPrettyStackState); }; + Optional localDiags; + DiagnosticEngine *rebuildDiags = diags; + if (silenceInterfaceDiagnostics) { + // To silence diagnostics, use a local temporary engine. + localDiags.emplace(sourceMgr); + rebuildDiags = &*localDiags; + } + SubError = (bool)subASTDelegate.runInSubCompilerInstance( moduleName, interfacePath, OutPath, diagnosticLoc, [&](SubCompilerInstanceInfo &info) { auto EBuilder = ExplicitModuleInterfaceBuilder( - *info.Instance, diags, sourceMgr, moduleCachePath, backupInterfaceDir, + *info.Instance, rebuildDiags, sourceMgr, moduleCachePath, backupInterfaceDir, prebuiltCachePath, ABIDescriptorPath, extraDependencies, diagnosticLoc, dependencyTracker); return EBuilder.buildSwiftModuleFromInterface( diff --git a/test/Index/index_system_modules_swiftinterfaces.swift b/test/Index/index_system_modules_swiftinterfaces.swift index 357d1f823fb..c9834d6f129 100644 --- a/test/Index/index_system_modules_swiftinterfaces.swift +++ b/test/Index/index_system_modules_swiftinterfaces.swift @@ -66,6 +66,7 @@ // RUN: c-index-test core -print-record %t/idx | %FileCheck -check-prefix=BROKEN-RECORD %s // BROKEN-RECORD-NOT: function/Swift | systemFunc() +/// Subsequent builds won't attempt to index the broken swiftinterface again // RUN: %target-swift-frontend -typecheck -parse-stdlib \ // RUN: -index-system-modules \ // RUN: -index-store-path %t/idx \ @@ -78,6 +79,20 @@ // RUN: 2>&1 | %FileCheck -check-prefix=BROKEN-BUILD-2 --allow-empty %s // BROKEN-BUILD-2-NOT: indexing system module +/// Local errors should be preserved even when indexing against a broken swiftinterface +// RUN: %empty-directory(%t/idx) +// RUN: %empty-directory(%t/modulecache) +// RUN: not %target-swift-frontend -typecheck -parse-stdlib \ +// RUN: -index-system-modules \ +// RUN: -index-store-path %t/idx \ +// RUN: -index-ignore-stdlib \ +// RUN: -sdk %t/SDK \ +// RUN: -Fsystem %t/SDK/Frameworks \ +// RUN: -module-cache-path %t/modulecache \ +// RUN: %t/ClientWithError.swift 2> %t/client-with-error.err +// RUN: cat %t/client-with-error.err | %FileCheck -check-prefix=WITH-ERROR %s +// WITH-ERROR: cannot convert return expression of type 'U' to return type 'T' + //--- SecretModule.swift public struct SecretType {} @@ -92,3 +107,12 @@ func leakyFunc(_ a: SecretType) { } import SystemModule public func clientFunc() {} + +//--- ClientWithError.swift + +import SystemModule +public func clientFunc() {} + +struct T {} +struct U {} +func f() -> T { return U() }