Preserve PrettyStackTrace context in the interface worker thread.

Because we block the calling thread, this should be safe for the existing
implementation of PrettyStackTrace; however, it would be much nicer if
LLVM provided direct support for this.

The most important thing from the trace that we want to print is the
original command line, so an alternative would be to just make a
PrettyStackTrace that printed all of the CompilerInvocation context;
I think that's accessible somewhere.  But this is a nice, simple
improvement.
This commit is contained in:
John McCall
2020-03-09 10:49:54 -04:00
parent 685d35b7d1
commit eea07b318d

View File

@@ -244,8 +244,18 @@ bool ModuleInterfaceBuilder::collectDepsForSerialization(
bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
StringRef OutPath, bool ShouldSerializeDeps,
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer) {
auto outerPrettyStackState = llvm::SavePrettyStackState();
bool SubError = false;
bool RunSuccess = llvm::CrashRecoveryContext().RunSafelyOnThread([&] {
// Pretend we're on the original thread for pretty-stack-trace purposes.
auto savedInnerPrettyStackState = llvm::SavePrettyStackState();
llvm::RestorePrettyStackState(outerPrettyStackState);
SWIFT_DEFER {
llvm::RestorePrettyStackState(savedInnerPrettyStackState);
};
// Note that we don't assume cachePath is the same as the Clang
// module cache path at this point.
if (!moduleCachePath.empty())