Skip to content

Commit 6065168

Browse files
committed
Parse: Test that we only parse function bodies in primary files
I added this optimization a while ago but didn't add a test for it.
1 parent d62e516 commit 6065168

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

include/swift/Basic/Statistics.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ FRONTEND_STATISTIC(AST, NumPrecedenceGroups)
132132
/// Number of conformances used by code processed by this frontend job.
133133
FRONTEND_STATISTIC(AST, NumUsedConformances)
134134

135+
/// Number of full function bodies parsed.
136+
FRONTEND_STATISTIC(Parse, NumFunctionsParsed)
137+
135138
/// Number of conformances that were deserialized by this frontend job.
136139
FRONTEND_STATISTIC(Sema, NumConformancesDeserialized)
137140

lib/Parse/ParseDecl.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/AST/Module.h"
3030
#include "swift/AST/ParameterList.h"
3131
#include "swift/Basic/Defer.h"
32+
#include "swift/Basic/Statistic.h"
3233
#include "swift/Basic/StringExtras.h"
3334
#include "llvm/Support/Compiler.h"
3435
#include "llvm/Support/MemoryBuffer.h"
@@ -4146,10 +4147,14 @@ bool Parser::parseGetSetImpl(ParseDeclOptions Flags,
41464147
SmallVector<ASTNode, 16> Entries;
41474148
{
41484149
llvm::SaveAndRestore<bool> T(IsParsingInterfaceTokens, false);
4149-
if (!isDelayedParsingEnabled())
4150+
if (!isDelayedParsingEnabled()) {
4151+
if (Context.Stats)
4152+
Context.Stats->getFrontendCounters().NumFunctionsParsed++;
4153+
41504154
parseBraceItems(Entries);
4151-
else
4155+
} else {
41524156
consumeGetSetBody(TheDecl, LBLoc);
4157+
}
41534158
}
41544159

41554160
SourceLoc RBLoc;
@@ -5193,6 +5198,9 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
51935198
diagnose(Tok, diag::protocol_method_with_body);
51945199
skipUntilDeclRBrace();
51955200
} else if (!isDelayedParsingEnabled()) {
5201+
if (Context.Stats)
5202+
Context.Stats->getFrontendCounters().NumFunctionsParsed++;
5203+
51965204
ParserResult<BraceStmt> Body =
51975205
parseBraceItemList(diag::func_decl_without_brace);
51985206
if (Body.isNull()) {
@@ -6063,6 +6071,9 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
60636071
ParseFunctionBody CC(*this, CD);
60646072

60656073
if (!isDelayedParsingEnabled()) {
6074+
if (Context.Stats)
6075+
Context.Stats->getFrontendCounters().NumFunctionsParsed++;
6076+
60666077
ParserResult<BraceStmt> Body =
60676078
parseBraceItemList(diag::invalid_diagnostic);
60686079

@@ -6131,7 +6142,11 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
61316142

61326143
ParseFunctionBody CC(*this, DD);
61336144
if (!isDelayedParsingEnabled()) {
6134-
ParserResult<BraceStmt> Body=parseBraceItemList(diag::invalid_diagnostic);
6145+
if (Context.Stats)
6146+
Context.Stats->getFrontendCounters().NumFunctionsParsed++;
6147+
6148+
ParserResult<BraceStmt> Body =
6149+
parseBraceItemList(diag::invalid_diagnostic);
61356150

61366151
if (!Body.isNull())
61376152
DD->setBody(Body.get());
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumFunctionsParsed %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
5+
func method${N}() {}

0 commit comments

Comments
 (0)