File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -888,7 +888,8 @@ class Parser {
888
888
void parseTopLevel (SmallVectorImpl<Decl *> &decls);
889
889
890
890
// / Parse the top-level SIL decls into the SIL module.
891
- void parseTopLevelSIL ();
891
+ // / \returns \c true if there was a parsing error.
892
+ bool parseTopLevelSIL ();
892
893
893
894
// / Flags that control the parsing of declarations.
894
895
enum ParseDeclFlags {
Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ void Parser::parseTopLevel(SmallVectorImpl<Decl *> &decls) {
241
241
TokReceiver->finalize ();
242
242
}
243
243
244
- void Parser::parseTopLevelSIL () {
244
+ bool Parser::parseTopLevelSIL () {
245
245
assert (SIL && isInSILMode ());
246
246
247
247
// Prime the lexer.
@@ -253,6 +253,7 @@ void Parser::parseTopLevelSIL() {
253
253
skipSingle ();
254
254
};
255
255
256
+ auto hadError = false ;
256
257
while (!Tok.is (tok::eof)) {
257
258
// If we run into a Swift decl, skip over until we find the next SIL decl.
258
259
if (isStartOfSwiftDecl ()) {
@@ -269,6 +270,7 @@ void Parser::parseTopLevelSIL() {
269
270
if (SIL->parse ##NAME (*this )) { \
270
271
Lexer::SILBodyRAII sbr (*L); \
271
272
skipToNextSILDecl (); \
273
+ hadError = true ; \
272
274
} \
273
275
break ; \
274
276
}
@@ -288,9 +290,11 @@ void Parser::parseTopLevelSIL() {
288
290
// or a SIL decl. Emit an error and skip ahead to the next SIL decl.
289
291
diagnose (Tok, diag::expected_sil_keyword);
290
292
skipToNextSILDecl ();
293
+ hadError = true ;
291
294
break ;
292
295
}
293
296
}
297
+ return hadError;
294
298
}
295
299
296
300
ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList (
Original file line number Diff line number Diff line change @@ -121,7 +121,14 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
121
121
SILParserState parserState (silMod.get ());
122
122
Parser parser (*bufferID, *SF, parserState.Impl .get ());
123
123
PrettyStackTraceParser StackTrace (parser);
124
- parser.parseTopLevelSIL ();
124
+
125
+ auto hadError = parser.parseTopLevelSIL ();
126
+ if (hadError) {
127
+ // The rest of the SIL pipeline expects well-formed SIL, so if we encounter
128
+ // a parsing error, just return an empty SIL module.
129
+ return SILModule::createEmptyModule (mod, desc.conv , desc.opts ,
130
+ desc.isWholeModule ());
131
+ }
125
132
return silMod;
126
133
}
127
134
You can’t perform that action at this time.
0 commit comments