Skip to content

Commit 23cd3d6

Browse files
Merge pull request #26965 from varungandhi-apple/vg-skip-module-trace-if-error
Skip module trace emission if we encountered errors when compiling.
2 parents ee562b9 + 4bd7a89 commit 23cd3d6

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,15 @@ template <> struct ObjectTraits<LoadedModuleTraceFormat> {
241241
static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
242242
DependencyTracker *depTracker,
243243
StringRef loadedModuleTracePath) {
244+
ASTContext &ctxt = mainModule->getASTContext();
245+
assert(!ctxt.hadError()
246+
&& "We may not be able to emit a proper trace if there was an error.");
247+
244248
if (loadedModuleTracePath.empty())
245249
return false;
246250
std::error_code EC;
247251
llvm::raw_fd_ostream out(loadedModuleTracePath, EC, llvm::sys::fs::F_Append);
248252

249-
ASTContext &ctxt = mainModule->getASTContext();
250253
if (out.has_error() || EC) {
251254
ctxt.Diags.diagnose(SourceLoc(), diag::error_opening_output,
252255
loadedModuleTracePath, EC.message());
@@ -271,7 +274,9 @@ static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
271274
if (loadedDecl == mainModule)
272275
continue;
273276
assert(!loadedDecl->getModuleFilename().empty()
274-
&& "Don't know how to handle modules with empty names.");
277+
&& ("Don't know how to handle modules with empty names."
278+
" One potential reason for getting an empty module name might"
279+
" be that the module could not be deserialized correctly."));
275280
pathToModuleDecl.insert(
276281
std::make_pair(loadedDecl->getModuleFilename(), loadedDecl));
277282
}
@@ -1089,15 +1094,15 @@ static bool performCompile(CompilerInstance &Instance,
10891094

10901095
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Invocation, Instance);
10911096

1092-
(void)emitLoadedModuleTraceForAllPrimariesIfNeeded(
1093-
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
1094-
10951097
if (Context.hadError()) {
10961098
// Emit the index store data even if there were compiler errors.
10971099
(void)emitIndexData(Invocation, Instance);
10981100
return true;
10991101
}
11001102

1103+
(void)emitLoadedModuleTraceForAllPrimariesIfNeeded(
1104+
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
1105+
11011106
// FIXME: This is still a lousy approximation of whether the module file will
11021107
// be externally consumed.
11031108
bool moduleIsPublic =
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Placeholder text so that nobody accidentally deletes this when deleting empty files.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rdar://problem/54860311.
2+
// RUN: not %target-typecheck-verify-swift -emit-loaded-module-trace -o %t/mytrace -I %S/Inputs 2>&1 | %FileCheck %s
3+
4+
import IllformedModule
5+
// CHECK: unexpected error produced: malformed compiled module

0 commit comments

Comments
 (0)