Skip to content

Commit e11b5b8

Browse files
authored
Merge pull request #15036 from slavapestov/test-delayed-body-parsing
Test delayed body parsing
2 parents d62e516 + 47c6117 commit e11b5b8

File tree

13 files changed

+34
-22
lines changed

13 files changed

+34
-22
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/Frontend/Frontend.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,16 +646,11 @@ void CompilerInstance::parseLibraryFile(
646646
SourceFileKind::Library, implicitImports.kind, BufferID);
647647
addAdditionalInitialImportsTo(NextInput, implicitImports);
648648

649-
auto *DelayedCB = SecondaryDelayedCB;
650-
if (isPrimaryInput(BufferID)) {
651-
DelayedCB = PrimaryDelayedCB;
652-
}
653-
if (isWholeModuleCompilation())
654-
DelayedCB = PrimaryDelayedCB;
649+
auto IsPrimary = isWholeModuleCompilation() || isPrimaryInput(BufferID);
650+
auto *DelayedCB = IsPrimary ? PrimaryDelayedCB : SecondaryDelayedCB;
655651

656652
auto &Diags = NextInput->getASTContext().Diags;
657653
auto DidSuppressWarnings = Diags.getSuppressWarnings();
658-
auto IsPrimary = isWholeModuleCompilation() || isPrimaryInput(BufferID);
659654
Diags.setSuppressWarnings(DidSuppressWarnings || !IsPrimary);
660655

661656
bool Done;

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());

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7556,8 +7556,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
75567556
return;
75577557
}
75587558

7559-
SWIFT_FUNC_STAT;
7560-
// FIXME: (transitional) increment the redundant "always-on" counter.
75617559
if (Context.Stats)
75627560
Context.Stats->getFrontendCounters().NumDeclsValidated++;
75637561

lib/Sema/TypeCheckStmt.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,8 +1415,6 @@ bool TypeChecker::typeCheckAbstractFunctionBody(AbstractFunctionDecl *AFD) {
14151415
if (!AFD->getBody())
14161416
return false;
14171417

1418-
SWIFT_FUNC_STAT;
1419-
// FIXME: (transitional) increment the redundant "always-on" counter.
14201418
if (Context.Stats)
14211419
Context.Stats->getFrontendCounters().NumFunctionsTypechecked++;
14221420

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,6 @@ bool TypeChecker::validateType(TypeLoc &Loc, DeclContext *DC,
15141514
if (Loc.wasValidated())
15151515
return Loc.isError();
15161516

1517-
SWIFT_FUNC_STAT;
1518-
// FIXME: (transitional) increment the redundant "always-on" counter.
15191517
if (Context.Stats)
15201518
Context.Stats->getFrontendCounters().NumTypesValidated++;
15211519

validation-test/compiler_scale/bind_extension_decl.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
22
// REQUIRES: OS=macosx
33
// REQUIRES: asserts
44

validation-test/compiler_scale/class_members.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
22
// REQUIRES: OS=macosx
33
// REQUIRES: asserts
44

validation-test/compiler_scale/enum_members.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
22
// REQUIRES: OS=macosx
33
// REQUIRES: asserts
44

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}() {}

validation-test/compiler_scale/protocol_members.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
22
// REQUIRES: OS=macosx
33
// REQUIRES: asserts
44

validation-test/compiler_scale/scale_neighbouring_getset.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select typeCheckAbstractFunctionBody %s
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumFunctionsTypechecked %s
22
// REQUIRES: OS=macosx
33
// REQUIRES: asserts
44

validation-test/compiler_scale/struct_members.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
1+
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
22
// REQUIRES: OS=macosx
33
// REQUIRES: asserts
44

0 commit comments

Comments
 (0)