Skip to content

Test delayed body parsing #15036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Basic/Statistics.def
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ FRONTEND_STATISTIC(AST, NumPrecedenceGroups)
/// Number of conformances used by code processed by this frontend job.
FRONTEND_STATISTIC(AST, NumUsedConformances)

/// Number of full function bodies parsed.
FRONTEND_STATISTIC(Parse, NumFunctionsParsed)

/// Number of conformances that were deserialized by this frontend job.
FRONTEND_STATISTIC(Sema, NumConformancesDeserialized)

Expand Down
9 changes: 2 additions & 7 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,16 +646,11 @@ void CompilerInstance::parseLibraryFile(
SourceFileKind::Library, implicitImports.kind, BufferID);
addAdditionalInitialImportsTo(NextInput, implicitImports);

auto *DelayedCB = SecondaryDelayedCB;
if (isPrimaryInput(BufferID)) {
DelayedCB = PrimaryDelayedCB;
}
if (isWholeModuleCompilation())
DelayedCB = PrimaryDelayedCB;
auto IsPrimary = isWholeModuleCompilation() || isPrimaryInput(BufferID);
auto *DelayedCB = IsPrimary ? PrimaryDelayedCB : SecondaryDelayedCB;

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

bool Done;
Expand Down
21 changes: 18 additions & 3 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "swift/AST/Module.h"
#include "swift/AST/ParameterList.h"
#include "swift/Basic/Defer.h"
#include "swift/Basic/Statistic.h"
#include "swift/Basic/StringExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryBuffer.h"
Expand Down Expand Up @@ -4146,10 +4147,14 @@ bool Parser::parseGetSetImpl(ParseDeclOptions Flags,
SmallVector<ASTNode, 16> Entries;
{
llvm::SaveAndRestore<bool> T(IsParsingInterfaceTokens, false);
if (!isDelayedParsingEnabled())
if (!isDelayedParsingEnabled()) {
if (Context.Stats)
Context.Stats->getFrontendCounters().NumFunctionsParsed++;

parseBraceItems(Entries);
else
} else {
consumeGetSetBody(TheDecl, LBLoc);
}
}

SourceLoc RBLoc;
Expand Down Expand Up @@ -5193,6 +5198,9 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
diagnose(Tok, diag::protocol_method_with_body);
skipUntilDeclRBrace();
} else if (!isDelayedParsingEnabled()) {
if (Context.Stats)
Context.Stats->getFrontendCounters().NumFunctionsParsed++;

ParserResult<BraceStmt> Body =
parseBraceItemList(diag::func_decl_without_brace);
if (Body.isNull()) {
Expand Down Expand Up @@ -6063,6 +6071,9 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
ParseFunctionBody CC(*this, CD);

if (!isDelayedParsingEnabled()) {
if (Context.Stats)
Context.Stats->getFrontendCounters().NumFunctionsParsed++;

ParserResult<BraceStmt> Body =
parseBraceItemList(diag::invalid_diagnostic);

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

ParseFunctionBody CC(*this, DD);
if (!isDelayedParsingEnabled()) {
ParserResult<BraceStmt> Body=parseBraceItemList(diag::invalid_diagnostic);
if (Context.Stats)
Context.Stats->getFrontendCounters().NumFunctionsParsed++;

ParserResult<BraceStmt> Body =
parseBraceItemList(diag::invalid_diagnostic);

if (!Body.isNull())
DD->setBody(Body.get());
Expand Down
2 changes: 0 additions & 2 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7556,8 +7556,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
return;
}

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

Expand Down
2 changes: 0 additions & 2 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,8 +1415,6 @@ bool TypeChecker::typeCheckAbstractFunctionBody(AbstractFunctionDecl *AFD) {
if (!AFD->getBody())
return false;

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

Expand Down
2 changes: 0 additions & 2 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,8 +1514,6 @@ bool TypeChecker::validateType(TypeLoc &Loc, DeclContext *DC,
if (Loc.wasValidated())
return Loc.isError();

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

Expand Down
2 changes: 1 addition & 1 deletion validation-test/compiler_scale/bind_extension_decl.gyb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

Expand Down
2 changes: 1 addition & 1 deletion validation-test/compiler_scale/class_members.gyb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

Expand Down
2 changes: 1 addition & 1 deletion validation-test/compiler_scale/enum_members.gyb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

Expand Down
5 changes: 5 additions & 0 deletions validation-test/compiler_scale/function_bodies.gyb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumFunctionsParsed %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

func method${N}() {}
2 changes: 1 addition & 1 deletion validation-test/compiler_scale/protocol_members.gyb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select typeCheckAbstractFunctionBody %s
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumFunctionsTypechecked %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

Expand Down
2 changes: 1 addition & 1 deletion validation-test/compiler_scale/struct_members.gyb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select validateDecl %s
// RUN: %scale-test --sum-multi --typecheck --begin 5 --end 16 --step 5 --select NumDeclsValidated %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

Expand Down