Skip to content

Commit 72018db

Browse files
committed
Parse: Remove some dead code
1 parent e47543c commit 72018db

File tree

5 files changed

+23
-46
lines changed

5 files changed

+23
-46
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ class Parser {
869869
/// Return true if parser is at the start of a decl or decl-import.
870870
bool isStartOfDecl();
871871

872-
bool parseTopLevel();
872+
void parseTopLevel();
873873

874874
/// Flags that control the parsing of declarations.
875875
enum ParseDeclFlags {

include/swift/Subsystems.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,14 @@ namespace swift {
119119
///
120120
/// \param PersistentState if non-null the same PersistentState object can
121121
/// be used to resume parsing or parse delayed function bodies.
122-
///
123-
/// \return true if the parser found code with side effects.
124-
bool parseIntoSourceFile(SourceFile &SF, unsigned BufferID, bool *Done,
122+
void parseIntoSourceFile(SourceFile &SF, unsigned BufferID, bool *Done,
125123
SILParserState *SIL = nullptr,
126124
PersistentParserState *PersistentState = nullptr,
127125
bool DelayBodyParsing = true);
128126

129127
/// Parse a single buffer into the given source file, until the full source
130128
/// contents are parsed.
131-
///
132-
/// \return true if the parser found code with side effects.
133-
bool parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
129+
void parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
134130
PersistentParserState *PersistentState = nullptr,
135131
bool DelayBodyParsing = true);
136132

lib/Immediate/REPL.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,10 @@ typeCheckREPLInput(ModuleDecl *MostRecentModule, StringRef Name,
187187
REPLInputFile.addImports(ImportsWithOptions);
188188
}
189189

190-
bool FoundAnySideEffects = false;
191190
bool Done;
192191
do {
193-
FoundAnySideEffects |=
194-
parseIntoSourceFile(REPLInputFile, BufferID, &Done, nullptr,
195-
&PersistentState);
192+
parseIntoSourceFile(REPLInputFile, BufferID, &Done, nullptr,
193+
&PersistentState);
196194
} while (!Done);
197195
performTypeChecking(REPLInputFile);
198196
return REPLModule;

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ namespace {
189189
/// decl-sil [[only in SIL mode]
190190
/// decl-sil-stage [[only in SIL mode]
191191
/// \endverbatim
192-
bool Parser::parseTopLevel() {
192+
void Parser::parseTopLevel() {
193193
SF.ASTStage = SourceFile::Parsing;
194194

195195
// Prime the lexer.
@@ -246,17 +246,6 @@ bool Parser::parseTopLevel() {
246246
consumeToken();
247247
}
248248

249-
// If this is a Main source file, determine if we found code that needs to be
250-
// executed (this is used by the repl to know whether to compile and run the
251-
// newly parsed stuff).
252-
bool FoundTopLevelCodeToExecute = false;
253-
if (allowTopLevelCode()) {
254-
for (auto V : Items) {
255-
if (isa<TopLevelCodeDecl>(V.get<Decl*>()))
256-
FoundTopLevelCodeToExecute = true;
257-
}
258-
}
259-
260249
// Add newly parsed decls to the module.
261250
for (auto Item : Items) {
262251
if (auto *D = Item.dyn_cast<Decl*>()) {
@@ -279,8 +268,6 @@ bool Parser::parseTopLevel() {
279268
SyntaxContext->addToken(Tok, LeadingTrivia, TrailingTrivia);
280269
TokReceiver->finalize();
281270
}
282-
283-
return FoundTopLevelCodeToExecute;
284271
}
285272

286273
ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(

lib/ParseSIL/ParseSIL.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ void PrettyStackTraceParser::print(llvm::raw_ostream &out) const {
112112
out << '\n';
113113
}
114114

115-
static bool parseIntoSourceFileImpl(SourceFile &SF,
116-
unsigned BufferID,
117-
bool *Done,
118-
SILParserState *SIL,
119-
PersistentParserState *PersistentState,
120-
bool FullParse,
121-
bool DelayBodyParsing) {
115+
static void parseIntoSourceFileImpl(SourceFile &SF,
116+
unsigned BufferID,
117+
bool *Done,
118+
SILParserState *SIL,
119+
PersistentParserState *PersistentState,
120+
bool FullParse,
121+
bool DelayBodyParsing) {
122122
assert((!FullParse || (SF.canBeParsedInFull() && !SIL)) &&
123123
"cannot parse in full with the given parameters!");
124124

@@ -149,40 +149,36 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,
149149
llvm::SaveAndRestore<bool> S(P.IsParsingInterfaceTokens,
150150
SF.hasInterfaceHash());
151151

152-
bool FoundSideEffects = false;
153152
do {
154-
bool hasSideEffects = P.parseTopLevel();
155-
FoundSideEffects = FoundSideEffects || hasSideEffects;
153+
P.parseTopLevel();
156154
*Done = P.Tok.is(tok::eof);
157155
} while (FullParse && !*Done);
158156

159157
if (STreeCreator) {
160158
auto rawNode = P.finalizeSyntaxTree();
161159
STreeCreator->acceptSyntaxRoot(rawNode, SF);
162160
}
163-
164-
return FoundSideEffects;
165161
}
166162

167-
bool swift::parseIntoSourceFile(SourceFile &SF,
163+
void swift::parseIntoSourceFile(SourceFile &SF,
168164
unsigned BufferID,
169165
bool *Done,
170166
SILParserState *SIL,
171167
PersistentParserState *PersistentState,
172168
bool DelayBodyParsing) {
173-
return parseIntoSourceFileImpl(SF, BufferID, Done, SIL,
174-
PersistentState,
175-
/*FullParse=*/SF.shouldBuildSyntaxTree(),
176-
DelayBodyParsing);
169+
parseIntoSourceFileImpl(SF, BufferID, Done, SIL,
170+
PersistentState,
171+
/*FullParse=*/SF.shouldBuildSyntaxTree(),
172+
DelayBodyParsing);
177173
}
178174

179-
bool swift::parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
175+
void swift::parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
180176
PersistentParserState *PersistentState,
181177
bool DelayBodyParsing) {
182178
bool Done = false;
183-
return parseIntoSourceFileImpl(SF, BufferID, &Done, /*SIL=*/nullptr,
184-
PersistentState, /*FullParse=*/true,
185-
DelayBodyParsing);
179+
parseIntoSourceFileImpl(SF, BufferID, &Done, /*SIL=*/nullptr,
180+
PersistentState, /*FullParse=*/true,
181+
DelayBodyParsing);
186182
}
187183

188184

0 commit comments

Comments
 (0)