Skip to content

Commit 1d46ca0

Browse files
committed
[ModuleInterface] Implement silencing errors on rebuild with a new engine
1 parent a135aa5 commit 1d46ca0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,19 @@ bool ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(
320320
llvm::RestorePrettyStackState(savedInnerPrettyStackState);
321321
};
322322

323+
Optional<DiagnosticEngine> localDiags;
324+
DiagnosticEngine *rebuildDiags = diags;
325+
if (silenceInterfaceDiagnostics) {
326+
// To silence diagnostics, use a local temporary engine.
327+
localDiags.emplace(sourceMgr);
328+
rebuildDiags = &*localDiags;
329+
}
330+
323331
SubError = (bool)subASTDelegate.runInSubCompilerInstance(
324332
moduleName, interfacePath, OutPath, diagnosticLoc,
325333
[&](SubCompilerInstanceInfo &info) {
326334
auto EBuilder = ExplicitModuleInterfaceBuilder(
327-
*info.Instance, diags, sourceMgr, moduleCachePath, backupInterfaceDir,
335+
*info.Instance, rebuildDiags, sourceMgr, moduleCachePath, backupInterfaceDir,
328336
prebuiltCachePath, ABIDescriptorPath, extraDependencies, diagnosticLoc,
329337
dependencyTracker);
330338
return EBuilder.buildSwiftModuleFromInterface(

test/Index/index_system_modules_swiftinterfaces.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
// RUN: c-index-test core -print-record %t/idx | %FileCheck -check-prefix=BROKEN-RECORD %s
6767
// BROKEN-RECORD-NOT: function/Swift | systemFunc()
6868

69+
/// Subsequent builds won't attempt to index the broken swiftinterface again
6970
// RUN: %target-swift-frontend -typecheck -parse-stdlib \
7071
// RUN: -index-system-modules \
7172
// RUN: -index-store-path %t/idx \
@@ -78,6 +79,20 @@
7879
// RUN: 2>&1 | %FileCheck -check-prefix=BROKEN-BUILD-2 --allow-empty %s
7980
// BROKEN-BUILD-2-NOT: indexing system module
8081

82+
/// Local errors should be preserved even when indexing against a broken swiftinterface
83+
// RUN: %empty-directory(%t/idx)
84+
// RUN: %empty-directory(%t/modulecache)
85+
// RUN: not %target-swift-frontend -typecheck -parse-stdlib \
86+
// RUN: -index-system-modules \
87+
// RUN: -index-store-path %t/idx \
88+
// RUN: -index-ignore-stdlib \
89+
// RUN: -sdk %t/SDK \
90+
// RUN: -Fsystem %t/SDK/Frameworks \
91+
// RUN: -module-cache-path %t/modulecache \
92+
// RUN: %t/ClientWithError.swift 2> %t/client-with-error.err
93+
// RUN: cat %t/client-with-error.err | %FileCheck -check-prefix=WITH-ERROR %s
94+
// WITH-ERROR: cannot convert return expression of type 'U' to return type 'T'
95+
8196
//--- SecretModule.swift
8297
public struct SecretType {}
8398

@@ -92,3 +107,12 @@ func leakyFunc(_ a: SecretType) { }
92107
import SystemModule
93108

94109
public func clientFunc() {}
110+
111+
//--- ClientWithError.swift
112+
113+
import SystemModule
114+
public func clientFunc() {}
115+
116+
struct T {}
117+
struct U {}
118+
func f() -> T { return U() }

0 commit comments

Comments
 (0)