Skip to content

[Frontend] Ensure constraint solving runs salvaging #70129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Frontend/ModuleInterfaceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,14 @@ bool ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(
llvm::RestorePrettyStackState(savedInnerPrettyStackState);
};

NullDiagnosticConsumer noopConsumer;
llvm::Optional<DiagnosticEngine> localDiags;
DiagnosticEngine *rebuildDiags = diags;
if (silenceInterfaceDiagnostics) {
// To silence diagnostics, use a local temporary engine.
localDiags.emplace(sourceMgr);
rebuildDiags = &*localDiags;
rebuildDiags->addConsumer(noopConsumer);
}

SubError = (bool)subASTDelegate.runInSubCompilerInstance(
Expand Down
7 changes: 6 additions & 1 deletion lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,8 +2007,13 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
subInstance.getSourceMgr().setFileSystem(SM.getFileSystem());

ForwardingDiagnosticConsumer FDC(*Diags);
if (!silenceErrors)
NullDiagnosticConsumer noopConsumer;
if (!silenceErrors) {
subInstance.addDiagnosticConsumer(&FDC);
} else {
subInstance.addDiagnosticConsumer(&noopConsumer);
}

std::string InstanceSetupError;
if (subInstance.setup(subInvocation, InstanceSetupError)) {
return std::make_error_code(std::errc::not_supported);
Expand Down
17 changes: 15 additions & 2 deletions test/Index/index_system_modules_swiftinterfaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
/// Index a client reading from a broken swiftinterface
// RUN: %empty-directory(%t/idx)
// RUN: %empty-directory(%t/modulecache)
// RUN: echo "breaking_the_swifinterface" >> %t/SDK/Frameworks/SystemModule.framework/Modules/SystemModule.swiftmodule/%module-target-triple.swiftinterface
// RUN: echo "breaking_the_swiftinterface" >> %t/SDK/Frameworks/SystemModule.framework/Modules/SystemModule.swiftmodule/%module-target-triple.swiftinterface

// RUN: %target-swift-frontend -typecheck -parse-stdlib \
// RUN: -index-system-modules \
Expand All @@ -128,7 +128,7 @@

/// We don't expect to see the swiftinterface error for indexing
// BROKEN-BUILD-NOT: error
// BROKEN-BUILD-NOT: breaking_the_swifinterface
// BROKEN-BUILD-NOT: breaking_the_swiftinterface
// BROKEN-BUILD: indexing system module {{.*}} skipping

/// We don't expect SystemModule to be indexed with a broken swiftinterface
Expand Down Expand Up @@ -178,6 +178,19 @@ import SystemDepB
public func systemFunc() {}
func leakyFunc(_ a: SecretType) {}

// Currently requires salvaging, which we need to make sure runs when the
// interface is rebuilt (as it produces a solution), we'll crash if it isn't.
public struct SysA { public init() {} }
public struct SysB { public init() {} }
@available(macOS, unavailable)
public func forceDisjunction() -> SysA { return SysA() }
public func forceDisjunction() -> SysB { return SysB() }
@available(macOS, unavailable)
@inlinable
public func requireSalvage() -> SysA {
return forceDisjunction()
}

//--- SystemDepA.swift
import SystemDepCommon
public func systemDepAFunc() {}
Expand Down