@@ -55,26 +55,27 @@ StringRef swift::getNameOfModule(const ModuleFile *MF) {
55
55
}
56
56
57
57
namespace {
58
- struct IDAndKind {
58
+ struct OffsetAndKind {
59
59
const Decl *D;
60
- DeclID ID ;
60
+ uint64_t offset ;
61
61
};
62
62
63
- static raw_ostream &operator <<(raw_ostream &os, IDAndKind &&pair) {
63
+ static raw_ostream &operator <<(raw_ostream &os, OffsetAndKind &&pair) {
64
64
return os << Decl::getKindName (pair.D ->getKind ())
65
- << " Decl # " << pair.ID ;
65
+ << " Decl @ " << pair.offset ;
66
66
}
67
67
68
68
class PrettyDeclDeserialization : public llvm ::PrettyStackTraceEntry {
69
69
const ModuleFile *MF;
70
70
const ModuleFile::Serialized<Decl*> &DeclOrOffset;
71
- DeclID ID ;
71
+ uint64_t offset ;
72
72
decls_block::RecordKind Kind;
73
73
public:
74
74
PrettyDeclDeserialization (ModuleFile *module ,
75
75
const ModuleFile::Serialized<Decl*> &declOrOffset,
76
- DeclID DID, decls_block::RecordKind kind)
77
- : MF(module ), DeclOrOffset(declOrOffset), ID(DID), Kind(kind) {
76
+ decls_block::RecordKind kind)
77
+ : MF(module ), DeclOrOffset(declOrOffset), offset(declOrOffset),
78
+ Kind (kind) {
78
79
}
79
80
80
81
static const char *getRecordKindString (decls_block::RecordKind Kind) {
@@ -88,18 +89,19 @@ namespace {
88
89
89
90
void print (raw_ostream &os) const override {
90
91
if (!DeclOrOffset.isComplete ()) {
91
- os << " While deserializing decl # " << ID << " ("
92
+ os << " While deserializing decl @ " << offset << " ("
92
93
<< getRecordKindString (Kind) << " )" ;
93
94
} else {
94
95
os << " While deserializing " ;
95
96
96
97
if (auto VD = dyn_cast<ValueDecl>(DeclOrOffset.get ())) {
97
- os << " '" << VD->getBaseName () << " ' (" << IDAndKind{VD, ID} << " )" ;
98
+ os << " '" << VD->getBaseName () << " ' (" << OffsetAndKind{VD, offset}
99
+ << " )" ;
98
100
} else if (auto ED = dyn_cast<ExtensionDecl>(DeclOrOffset.get ())) {
99
101
os << " extension of '" << ED->getExtendedType () << " ' ("
100
- << IDAndKind {ED, ID } << " )" ;
102
+ << OffsetAndKind {ED, offset } << " )" ;
101
103
} else {
102
- os << IDAndKind {DeclOrOffset.get (), ID };
104
+ os << OffsetAndKind {DeclOrOffset.get (), offset };
103
105
}
104
106
}
105
107
os << " in '" << getNameOfModule (MF) << " '\n " ;
@@ -2226,7 +2228,7 @@ Decl *ModuleFile::getDecl(DeclID DID) {
2226
2228
}
2227
2229
2228
2230
// / Used to split up methods that would otherwise live in ModuleFile.
2229
- class swift ::ASTDeserializer {
2231
+ class swift ::DeclDeserializer {
2230
2232
template <typename T>
2231
2233
using Serialized = ModuleFile::Serialized<T>;
2232
2234
using TypeID = serialization::TypeID;
@@ -2289,20 +2291,35 @@ class swift::ASTDeserializer {
2289
2291
};
2290
2292
2291
2293
ModuleFile &MF;
2294
+ Serialized<Decl *> &declOrOffset;
2295
+
2296
+ DeclAttribute *DAttrs = nullptr ;
2297
+ DeclAttribute **AttrsNext = &DAttrs;
2298
+
2299
+ void AddAttribute (DeclAttribute *Attr) {
2300
+ // Advance the linked list.
2301
+ // This isn't just using DeclAttributes because that would result in the
2302
+ // attributes getting reversed.
2303
+ // FIXME: If we reverse them at serialization time we could get rid of this.
2304
+ *AttrsNext = Attr;
2305
+ AttrsNext = Attr->getMutableNext ();
2306
+ };
2307
+
2292
2308
public:
2293
- ASTDeserializer (ModuleFile &MF) : MF(MF) {}
2309
+ DeclDeserializer (ModuleFile &MF, Serialized<Decl *> &declOrOffset)
2310
+ : MF(MF), declOrOffset(declOrOffset) {}
2294
2311
2295
2312
// / Deserializes decl attribute and attribute-like records from
2296
2313
// / \c MF.DeclTypesCursor until a non-attribute record is found,
2297
2314
// / passing each one to \p AddAttribute.
2298
2315
llvm::Error deserializeDeclAttributes (
2299
2316
ASTContext &ctx,
2300
- llvm::function_ref<void (DeclAttribute *)> AddAttribute,
2301
2317
FilenameForPrivateRAII &filenameForPrivate,
2302
2318
LocalDiscriminatorRAII &localDiscriminatorRAII,
2303
2319
PrivateDiscriminatorRAII &privateDiscriminatorRAII);
2304
2320
2305
- Expected<Decl *> getDeclCheckedImpl (DeclID DID);
2321
+ static Expected<Decl *> getDeclCheckedImpl (ModuleFile &MF, DeclID DID);
2322
+ Expected<Decl *> getDeclCheckedImpl ();
2306
2323
2307
2324
Expected<Decl *> deserializeTypeAlias (Serialized<Decl *> &declOrOffset,
2308
2325
ArrayRef<uint64_t > scratch,
@@ -2362,7 +2379,7 @@ Expected<Decl *>
2362
2379
ModuleFile::getDeclChecked (DeclID DID) {
2363
2380
// Tag every deserialized ValueDecl coming out of getDeclChecked with its ID.
2364
2381
Expected<Decl *> deserialized =
2365
- ASTDeserializer (*this ). getDeclCheckedImpl ( DID);
2382
+ DeclDeserializer::getDeclCheckedImpl (*this , DID);
2366
2383
if (deserialized && deserialized.get ()) {
2367
2384
if (auto *IDC = dyn_cast<IterableDeclContext>(deserialized.get ())) {
2368
2385
// Only set the DeclID on the returned Decl if it's one that was loaded
@@ -2385,9 +2402,8 @@ static bool attributeChainContains(DeclAttribute *attr) {
2385
2402
return tempAttrs.hasAttribute <DERIVED>();
2386
2403
}
2387
2404
2388
- llvm::Error ASTDeserializer ::deserializeDeclAttributes (
2405
+ llvm::Error DeclDeserializer ::deserializeDeclAttributes (
2389
2406
ASTContext &ctx,
2390
- llvm::function_ref<void (DeclAttribute *)> AddAttribute,
2391
2407
FilenameForPrivateRAII &filenameForPrivate,
2392
2408
LocalDiscriminatorRAII &localDiscriminatorRAII,
2393
2409
PrivateDiscriminatorRAII &privateDiscriminatorRAII) {
@@ -2663,7 +2679,7 @@ llvm::Error ASTDeserializer::deserializeDeclAttributes(
2663
2679
}
2664
2680
2665
2681
Expected<Decl *>
2666
- ASTDeserializer ::getDeclCheckedImpl (DeclID DID) {
2682
+ DeclDeserializer ::getDeclCheckedImpl (ModuleFile &MF, DeclID DID) {
2667
2683
if (DID == 0 )
2668
2684
return nullptr ;
2669
2685
@@ -2677,23 +2693,16 @@ ASTDeserializer::getDeclCheckedImpl(DeclID DID) {
2677
2693
BCOffsetRAII restoreOffset (MF.DeclTypeCursor );
2678
2694
MF.DeclTypeCursor .JumpToBit (declOrOffset);
2679
2695
2696
+ return DeclDeserializer (MF, declOrOffset).getDeclCheckedImpl ();
2697
+ }
2698
+
2699
+ Expected<Decl *>
2700
+ DeclDeserializer::getDeclCheckedImpl () {
2680
2701
ASTContext &ctx = MF.getContext ();
2681
2702
2682
2703
if (auto s = ctx.Stats )
2683
2704
s->getFrontendCounters ().NumDeclsDeserialized ++;
2684
2705
2685
- // Read the attributes (if any).
2686
- // This isn't just using DeclAttributes because that would result in the
2687
- // attributes getting reversed.
2688
- // FIXME: If we reverse them at serialization time we could get rid of this.
2689
- DeclAttribute *DAttrs = nullptr ;
2690
- DeclAttribute **AttrsNext = &DAttrs;
2691
- auto AddAttribute = [&](DeclAttribute *Attr) {
2692
- // Advance the linked list.
2693
- *AttrsNext = Attr;
2694
- AttrsNext = Attr->getMutableNext ();
2695
- };
2696
-
2697
2706
PrivateDiscriminatorRAII privateDiscriminatorRAII{MF, declOrOffset};
2698
2707
LocalDiscriminatorRAII localDiscriminatorRAII (declOrOffset);
2699
2708
ModuleFile::DeserializingEntityRAII deserializingEntity (MF);
@@ -2710,7 +2719,7 @@ ASTDeserializer::getDeclCheckedImpl(DeclID DID) {
2710
2719
nominal->setInherited (inheritedTypes);
2711
2720
};
2712
2721
2713
- auto attrError = deserializeDeclAttributes (ctx, AddAttribute,
2722
+ auto attrError = deserializeDeclAttributes (ctx,
2714
2723
filenameForPrivate,
2715
2724
localDiscriminatorRAII,
2716
2725
privateDiscriminatorRAII);
@@ -2740,7 +2749,7 @@ ASTDeserializer::getDeclCheckedImpl(DeclID DID) {
2740
2749
&blobData);
2741
2750
2742
2751
PrettyDeclDeserialization stackTraceEntry (
2743
- &MF, declOrOffset, DID, static_cast <decls_block::RecordKind>(recordID));
2752
+ &MF, declOrOffset, static_cast <decls_block::RecordKind>(recordID));
2744
2753
2745
2754
switch (recordID) {
2746
2755
case decls_block::TypeAliasLayout::Code:
0 commit comments