[Basic] Introduce abortWithPrettyStackTraceMessage

Introduce a convenience for aborting while printing a given message
to a frame of the pretty stack trace. Use this in the existing places
where we're currently doing this.
This commit is contained in:
Hamish Knight
2025-04-03 14:21:38 +01:00
parent 5d81f4d83a
commit fd7c2595f2
5 changed files with 50 additions and 30 deletions

View File

@@ -19,6 +19,7 @@
#include "swift/AST/Module.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/LangOptions.h"
#include "swift/Basic/PrettyStackTrace.h"
#include "swift/Parse/ParseVersion.h"
#include "swift/Serialization/SerializedModuleLoader.h"
#include "swift/Strings.h"
@@ -697,23 +698,19 @@ std::string ModuleFileSharedCore::Dependency::getPrettyPrintedPath() const {
}
void ModuleFileSharedCore::fatal(llvm::Error error) const {
llvm::SmallString<0> errorStr;
llvm::raw_svector_ostream out(errorStr);
out << "*** DESERIALIZATION FAILURE ***\n";
out << "*** If any module named here was modified in the SDK, please delete the ***\n";
out << "*** new swiftmodule files from the SDK and keep only swiftinterfaces. ***\n";
outputDiagnosticInfo(out);
out << "\n";
if (error) {
handleAllErrors(std::move(error), [&](const llvm::ErrorInfoBase &ei) {
ei.log(out);
out << "\n";
});
}
llvm::PrettyStackTraceString trace(errorStr.c_str());
abort();
abortWithPrettyStackTraceMessage([&](auto &out) {
out << "*** DESERIALIZATION FAILURE ***\n";
out << "*** If any module named here was modified in the SDK, please delete the ***\n";
out << "*** new swiftmodule files from the SDK and keep only swiftinterfaces. ***\n";
outputDiagnosticInfo(out);
out << "\n";
if (error) {
handleAllErrors(std::move(error), [&](const llvm::ErrorInfoBase &ei) {
ei.log(out);
out << "\n";
});
}
});
}
void ModuleFileSharedCore::outputDiagnosticInfo(llvm::raw_ostream &os) const {