Skip to content

Commit c7cce10

Browse files
committed
Add an Assert To Make Sure the SIL Parser Emits Diagnostics
In swiftlang#34693, we discovered the SIL parser can silently fail. Try to detect this in +asserts builds.
1 parent 5ea1305 commit c7cce10

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
8484
if (hadError) {
8585
// The rest of the SIL pipeline expects well-formed SIL, so if we encounter
8686
// a parsing error, just return an empty SIL module.
87+
//
88+
// Because the SIL parser's notion of failing with an error is distinct from
89+
// the ASTContext's notion of having emitted a diagnostic, it's possible for
90+
// the parser to fail silently without emitting a diagnostic. This assertion
91+
// ensures that +asserts builds will fail fast. If you crash here, please go
92+
// back and add a diagnostic after identifying where the SIL parser failed.
93+
assert(SF->getASTContext().hadError() &&
94+
"Failed to parse SIL but did not emit any errors!");
8795
return SILModule::createEmptyModule(desc.context, desc.conv, desc.opts);
8896
}
8997
return silMod;

0 commit comments

Comments
 (0)