Skip to content

Commit 7e043cf

Browse files
committed
[Serialization] Add extra counters and PrettyStackTraces.
And consolidate two slightly different subclasses of PrettyStackTrace that mostly did the same thing.
1 parent f2dbd65 commit 7e043cf

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
STATISTIC(NumDeclsLoaded, "# of decls deserialized");
3636
STATISTIC(NumMemberListsLoaded,
3737
"# of nominals/extensions whose members were loaded");
38+
STATISTIC(NumNormalProtocolConformancesLoaded,
39+
"# of normal protocol conformances deserialized");
40+
STATISTIC(NumNormalProtocolConformancesCompleted,
41+
"# of normal protocol conformances completed");
3842
STATISTIC(NumNestedTypeShortcuts,
3943
"# of same-module nested types resolved without lookup");
4044

@@ -108,18 +112,6 @@ namespace {
108112
XRefTracePath::print(os, "\t");
109113
}
110114
};
111-
112-
class PrettyStackTraceModuleFile : public llvm::PrettyStackTraceEntry {
113-
const char *Action;
114-
const ModuleFile *MF;
115-
public:
116-
explicit PrettyStackTraceModuleFile(const char *action, ModuleFile *module)
117-
: Action(action), MF(module) {}
118-
119-
void print(raw_ostream &os) const override {
120-
os << Action << " \'" << getNameOfModule(MF) << "'\n";
121-
}
122-
};
123115
} // end anonymous namespace
124116

125117
const char DeclDeserializationError::ID = '\0';
@@ -583,7 +575,7 @@ ProtocolConformanceRef ModuleFile::readConformance(
583575
nominal->lookupConformance(module, proto, conformances);
584576
PrettyStackTraceModuleFile traceMsg(
585577
"If you're seeing a crash here, check that your SDK and dependencies "
586-
"are at least as new as the versions used to build", this);
578+
"are at least as new as the versions used to build", *this);
587579
// This would normally be an assertion but it's more useful to print the
588580
// PrettyStackTrace here even in no-asserts builds.
589581
if (conformances.empty())
@@ -640,6 +632,7 @@ NormalProtocolConformance *ModuleFile::readNormalConformance(
640632

641633
auto proto = cast<ProtocolDecl>(getDecl(protoID));
642634
PrettyStackTraceDecl traceTo("... to", proto);
635+
++NumNormalProtocolConformancesLoaded;
643636

644637
auto conformance = ctx.getConformance(conformingType, proto, SourceLoc(), dc,
645638
ProtocolConformanceState::Incomplete);
@@ -1588,7 +1581,7 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
15881581
if (M != getAssociatedModule()) {
15891582
traceMsg.emplace("If you're seeing a crash here, check that your SDK "
15901583
"and dependencies match the versions used to build",
1591-
this);
1584+
*this);
15921585
}
15931586

15941587
if (values.empty()) {
@@ -4565,6 +4558,13 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
45654558
uint64_t contextData) {
45664559
using namespace decls_block;
45674560

4561+
PrettyStackTraceModuleFile traceModule("While reading from", *this);
4562+
PrettyStackTraceType trace(getAssociatedModule()->getASTContext(),
4563+
"finishing conformance for",
4564+
conformance->getType());
4565+
PrettyStackTraceDecl traceTo("... to", conformance->getProtocol());
4566+
++NumNormalProtocolConformancesCompleted;
4567+
45684568
// Find the conformance record.
45694569
BCOffsetRAII restoreOffset(DeclTypeCursor);
45704570
DeclTypeCursor.JumpToBit(contextData);

lib/Serialization/DeserializationErrors.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
#include "swift/AST/Module.h"
1818
#include "swift/Serialization/ModuleFormat.h"
1919
#include "llvm/Support/Error.h"
20+
#include "llvm/Support/PrettyStackTrace.h"
2021

2122
namespace swift {
23+
class ModuleFile;
24+
25+
StringRef getNameOfModule(const ModuleFile *);
26+
2227
namespace serialization {
2328

2429
class XRefTracePath {
@@ -313,6 +318,20 @@ class TypeError : public llvm::ErrorInfo<TypeError, DeclDeserializationError> {
313318
}
314319
};
315320

321+
class PrettyStackTraceModuleFile : public llvm::PrettyStackTraceEntry {
322+
const char *Action;
323+
const ModuleFile &MF;
324+
public:
325+
explicit PrettyStackTraceModuleFile(const char *action, ModuleFile &module)
326+
: Action(action), MF(module) {}
327+
explicit PrettyStackTraceModuleFile(ModuleFile &module)
328+
: PrettyStackTraceModuleFile("While reading from", module) {}
329+
330+
void print(raw_ostream &os) const override {
331+
os << Action << " \'" << getNameOfModule(&MF) << "'\n";
332+
}
333+
};
334+
316335
} // end namespace serialization
317336
} // end namespace swift
318337

lib/Serialization/ModuleFile.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "llvm/ADT/StringExtras.h"
2828
#include "llvm/Support/MemoryBuffer.h"
2929
#include "llvm/Support/OnDiskHashTable.h"
30-
#include "llvm/Support/PrettyStackTrace.h"
3130

3231
using namespace swift;
3332
using namespace swift::serialization;
@@ -297,19 +296,6 @@ std::string ModuleFile::Dependency::getPrettyPrintedPath() const {
297296
return output;
298297
}
299298

300-
namespace {
301-
class PrettyModuleFileDeserialization : public llvm::PrettyStackTraceEntry {
302-
const ModuleFile &File;
303-
public:
304-
explicit PrettyModuleFileDeserialization(const ModuleFile &file)
305-
: File(file) {}
306-
307-
void print(raw_ostream &os) const override {
308-
os << "While reading from " << File.getModuleFilename() << "\n";
309-
}
310-
};
311-
} // end anonymous namespace
312-
313299
/// Used to deserialize entries in the on-disk decl hash table.
314300
class ModuleFile::DeclTableInfo {
315301
public:
@@ -918,7 +904,7 @@ ModuleFile::ModuleFile(
918904
assert(getStatus() == Status::Valid);
919905
Bits.IsFramework = isFramework;
920906

921-
PrettyModuleFileDeserialization stackEntry(*this);
907+
PrettyStackTraceModuleFile stackEntry(*this);
922908

923909
llvm::BitstreamCursor cursor{ModuleInputBuffer->getMemBufferRef()};
924910

@@ -1188,7 +1174,7 @@ ModuleFile::ModuleFile(
11881174

11891175
Status ModuleFile::associateWithFileContext(FileUnit *file,
11901176
SourceLoc diagLoc) {
1191-
PrettyModuleFileDeserialization stackEntry(*this);
1177+
PrettyStackTraceModuleFile stackEntry(*this);
11921178

11931179
assert(getStatus() == Status::Valid && "invalid module file");
11941180
assert(!FileContext && "already associated with an AST module");
@@ -1303,7 +1289,7 @@ ModuleFile::~ModuleFile() { }
13031289

13041290
void ModuleFile::lookupValue(DeclName name,
13051291
SmallVectorImpl<ValueDecl*> &results) {
1306-
PrettyModuleFileDeserialization stackEntry(*this);
1292+
PrettyStackTraceModuleFile stackEntry(*this);
13071293

13081294
if (TopLevelDecls) {
13091295
// Find top-level declarations with the given name.
@@ -1347,7 +1333,7 @@ void ModuleFile::lookupValue(DeclName name,
13471333
}
13481334

13491335
TypeDecl *ModuleFile::lookupLocalType(StringRef MangledName) {
1350-
PrettyModuleFileDeserialization stackEntry(*this);
1336+
PrettyStackTraceModuleFile stackEntry(*this);
13511337

13521338
if (!LocalTypeDecls)
13531339
return nullptr;
@@ -1361,7 +1347,7 @@ TypeDecl *ModuleFile::lookupLocalType(StringRef MangledName) {
13611347

13621348
TypeDecl *ModuleFile::lookupNestedType(Identifier name,
13631349
const ValueDecl *parent) {
1364-
PrettyModuleFileDeserialization stackEntry(*this);
1350+
PrettyStackTraceModuleFile stackEntry(*this);
13651351

13661352
if (!NestedTypeDecls)
13671353
return nullptr;
@@ -1387,7 +1373,7 @@ TypeDecl *ModuleFile::lookupNestedType(Identifier name,
13871373
}
13881374

13891375
OperatorDecl *ModuleFile::lookupOperator(Identifier name, DeclKind fixity) {
1390-
PrettyModuleFileDeserialization stackEntry(*this);
1376+
PrettyStackTraceModuleFile stackEntry(*this);
13911377

13921378
if (!OperatorDecls)
13931379
return nullptr;
@@ -1407,7 +1393,7 @@ OperatorDecl *ModuleFile::lookupOperator(Identifier name, DeclKind fixity) {
14071393
}
14081394

14091395
PrecedenceGroupDecl *ModuleFile::lookupPrecedenceGroup(Identifier name) {
1410-
PrettyModuleFileDeserialization stackEntry(*this);
1396+
PrettyStackTraceModuleFile stackEntry(*this);
14111397

14121398
if (!PrecedenceGroupDecls)
14131399
return nullptr;
@@ -1424,7 +1410,7 @@ PrecedenceGroupDecl *ModuleFile::lookupPrecedenceGroup(Identifier name) {
14241410
void ModuleFile::getImportedModules(
14251411
SmallVectorImpl<ModuleDecl::ImportedModule> &results,
14261412
ModuleDecl::ImportFilter filter) {
1427-
PrettyModuleFileDeserialization stackEntry(*this);
1413+
PrettyStackTraceModuleFile stackEntry(*this);
14281414

14291415
for (auto &dep : Dependencies) {
14301416
if (filter != ModuleDecl::ImportFilter::All &&
@@ -1506,7 +1492,7 @@ void ModuleFile::getImportDecls(SmallVectorImpl<Decl *> &Results) {
15061492
void ModuleFile::lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
15071493
VisibleDeclConsumer &consumer,
15081494
NLKind lookupKind) {
1509-
PrettyModuleFileDeserialization stackEntry(*this);
1495+
PrettyStackTraceModuleFile stackEntry(*this);
15101496
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
15111497

15121498
if (!TopLevelDecls)
@@ -1542,7 +1528,7 @@ void ModuleFile::lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
15421528
}
15431529

15441530
void ModuleFile::loadExtensions(NominalTypeDecl *nominal) {
1545-
PrettyModuleFileDeserialization stackEntry(*this);
1531+
PrettyStackTraceModuleFile stackEntry(*this);
15461532
if (!ExtensionDecls)
15471533
return;
15481534

@@ -1609,7 +1595,7 @@ void ModuleFile::loadObjCMethods(
16091595
void ModuleFile::lookupClassMember(ModuleDecl::AccessPathTy accessPath,
16101596
DeclName name,
16111597
SmallVectorImpl<ValueDecl*> &results) {
1612-
PrettyModuleFileDeserialization stackEntry(*this);
1598+
PrettyStackTraceModuleFile stackEntry(*this);
16131599
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
16141600

16151601
if (!ClassMembersByName)
@@ -1658,7 +1644,7 @@ void ModuleFile::lookupClassMember(ModuleDecl::AccessPathTy accessPath,
16581644

16591645
void ModuleFile::lookupClassMembers(ModuleDecl::AccessPathTy accessPath,
16601646
VisibleDeclConsumer &consumer) {
1661-
PrettyModuleFileDeserialization stackEntry(*this);
1647+
PrettyStackTraceModuleFile stackEntry(*this);
16621648
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
16631649

16641650
if (!ClassMembersByName)
@@ -1714,7 +1700,7 @@ ModuleFile::collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const
17141700
}
17151701

17161702
void ModuleFile::getTopLevelDecls(SmallVectorImpl<Decl *> &results) {
1717-
PrettyModuleFileDeserialization stackEntry(*this);
1703+
PrettyStackTraceModuleFile stackEntry(*this);
17181704
if (PrecedenceGroupDecls) {
17191705
for (auto entry : PrecedenceGroupDecls->data()) {
17201706
for (auto item : entry)
@@ -1754,7 +1740,7 @@ void ModuleFile::getTopLevelDecls(SmallVectorImpl<Decl *> &results) {
17541740

17551741
void
17561742
ModuleFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl *> &results) {
1757-
PrettyModuleFileDeserialization stackEntry(*this);
1743+
PrettyStackTraceModuleFile stackEntry(*this);
17581744
if (!LocalTypeDecls)
17591745
return;
17601746

@@ -1770,7 +1756,7 @@ void ModuleFile::getDisplayDecls(SmallVectorImpl<Decl *> &results) {
17701756
if (ShadowedModule)
17711757
ShadowedModule->getDisplayDecls(results);
17721758

1773-
PrettyModuleFileDeserialization stackEntry(*this);
1759+
PrettyStackTraceModuleFile stackEntry(*this);
17741760
getImportDecls(results);
17751761
getTopLevelDecls(results);
17761762
}

0 commit comments

Comments
 (0)