13
13
#include " DocFormat.h"
14
14
#include " Serialization.h"
15
15
#include " SourceInfoFormat.h"
16
+ #include " swift/Basic/Defer.h"
16
17
#include " swift/AST/ASTContext.h"
17
18
#include " swift/AST/ASTWalker.h"
18
19
#include " swift/AST/DiagnosticsCommon.h"
@@ -556,6 +557,7 @@ class DeclUSRsTableWriter {
556
557
llvm::OnDiskChainedHashTableGenerator<USRTableInfo> generator;
557
558
uint32_t CurId = 0 ;
558
559
public:
560
+ uint32_t peekNextId () const { return CurId; }
559
561
Optional<uint32_t > getNewUSRID (StringRef USR) {
560
562
if (USRMap.find (USR) == USRMap.end ()) {
561
563
generator.insert (USRMap.insert (std::make_pair (USR, CurId)).first ->getKey (), CurId);
@@ -690,6 +692,10 @@ Result.X.Column = Locs->X.Column;
690
692
}
691
693
692
694
bool walkToDeclPre (Decl *D) override {
695
+ SWIFT_DEFER {
696
+ assert (USRWriter.peekNextId () * sizeof (DeclLocationsTableData) == Buffer.size () &&
697
+ " USR Id has a one-to-one mapping with DeclLocationsTableData" );
698
+ };
693
699
// We shouldn't expose any Decls that .swiftdoc file isn't willing to expose.
694
700
// .swiftdoc doesn't include comments for double underscored symbols, but for .swiftsourceinfo,
695
701
// having the source location for these symbols isn't a concern becuase these
@@ -706,9 +712,6 @@ Result.X.Column = Locs->X.Column;
706
712
auto USR = calculateNewUSRId (D);
707
713
if (!USR.hasValue ())
708
714
return true ;
709
- // OK, we get a new USR, now append the associated source location data.
710
- assert (*USR * sizeof (DeclLocationsTableData) == Buffer.size () &&
711
- " USR id is used as an index to access basic location array" );
712
715
appendToBuffer (*LocData);
713
716
return true ;
714
717
}
0 commit comments