Skip to content

Commit eea07b3

Browse files
committed
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.
1 parent 685d35b commit eea07b3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,18 @@ bool ModuleInterfaceBuilder::collectDepsForSerialization(
244244
bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
245245
StringRef OutPath, bool ShouldSerializeDeps,
246246
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer) {
247+
248+
auto outerPrettyStackState = llvm::SavePrettyStackState();
249+
247250
bool SubError = false;
248251
bool RunSuccess = llvm::CrashRecoveryContext().RunSafelyOnThread([&] {
252+
// Pretend we're on the original thread for pretty-stack-trace purposes.
253+
auto savedInnerPrettyStackState = llvm::SavePrettyStackState();
254+
llvm::RestorePrettyStackState(outerPrettyStackState);
255+
SWIFT_DEFER {
256+
llvm::RestorePrettyStackState(savedInnerPrettyStackState);
257+
};
258+
249259
// Note that we don't assume cachePath is the same as the Clang
250260
// module cache path at this point.
251261
if (!moduleCachePath.empty())

0 commit comments

Comments
 (0)