Skip to content

Commit 9aa3d01

Browse files
committed
[Serialization] Avoid serializing source orders, trust deserialized decls in preserving such order. rdar://24610992
Thank Jordan for suggesting this.
1 parent 9da87ef commit 9aa3d01

File tree

10 files changed

+21
-64
lines changed

10 files changed

+21
-64
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,6 @@ class alignas(1 << DeclAlignInBits) Decl {
759759

760760
Optional<StringRef> getGroupName() const;
761761

762-
Optional<unsigned> getSourceOrder() const;
763-
764762
/// \returns the brief comment attached to this declaration.
765763
StringRef getBriefComment() const;
766764

include/swift/AST/Module.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,6 @@ class FileUnit : public DeclContext {
675675
return None;
676676
}
677677

678-
virtual Optional<unsigned>
679-
getSourceOrderForDecl(const Decl *D) const {
680-
return None;
681-
}
682-
683678
virtual void collectAllGroups(std::vector<StringRef> &Names) const {}
684679

685680
/// Returns an implementation-defined "discriminator" for \p D, which

include/swift/AST/RawComment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct CommentInfo {
7373
StringRef Brief;
7474
RawComment Raw;
7575
uint32_t Group;
76-
uint32_t SourceOrder;
7776
};
7877

7978
} // namespace swift

include/swift/Serialization/ModuleFile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ class ModuleFile : public LazyMemberLoader {
616616

617617
Optional<StringRef> getGroupNameById(unsigned Id) const;
618618
Optional<StringRef> getGroupNameForDecl(const Decl *D) const;
619-
Optional<unsigned> getSourceOrderForDecl(const Decl *D) const;
620619
void collectAllGroups(std::vector<StringRef> &Names) const;
621620
Optional<CommentInfo> getCommentForDecl(const Decl *D) const;
622621
Optional<CommentInfo> getCommentForDeclByUSR(StringRef USR) const;

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ class SerializedASTFile final : public LoadedFile {
140140

141141
Optional<StringRef> getGroupNameForDecl(const Decl *D) const override;
142142

143-
Optional<unsigned> getSourceOrderForDecl(const Decl *D) const override;
144-
145143
void collectAllGroups(std::vector<StringRef> &Names) const override;
146144

147145
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;

lib/AST/RawComment.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,6 @@ Optional<StringRef> Decl::getGroupName() const {
171171
return None;
172172
}
173173

174-
Optional<unsigned> Decl::getSourceOrder() const {
175-
176-
// We can only get source orders from deserialized module files.
177-
if (auto *Unit =
178-
dyn_cast<FileUnit>(this->getDeclContext()->getModuleScopeContext())) {
179-
return Unit->getSourceOrderForDecl(this);
180-
}
181-
return None;
182-
}
183-
184174
static StringRef extractBriefComment(ASTContext &Context, RawComment RC,
185175
const Decl *D) {
186176
PrettyStackTraceDecl StackTrace("extracting brief comment for", D);

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -347,28 +347,27 @@ void swift::ide::printSubmoduleInterface(
347347
return false;
348348
});
349349

350-
std::sort(SwiftDecls.begin(), SwiftDecls.end(),
351-
[&](Decl *LHS, Decl *RHS) -> bool {
352-
auto *LHSValue = dyn_cast<ValueDecl>(LHS);
353-
auto *RHSValue = dyn_cast<ValueDecl>(RHS);
354-
355-
// If group is specified, we order the decls by their source order.
356-
if (GroupName && LHS->getSourceOrder() && RHS->getSourceOrder()) {
357-
return LHS->getSourceOrder().getValue() < RHS->getSourceOrder().getValue();
358-
}
359-
360-
if (LHSValue && RHSValue) {
361-
StringRef LHSName = LHSValue->getName().str();
362-
StringRef RHSName = RHSValue->getName().str();
363-
if (int Ret = LHSName.compare(RHSName))
364-
return Ret < 0;
365-
// FIXME: this is not sufficient to establish a total order for overloaded
366-
// decls.
367-
return LHS->getKind() < RHS->getKind();
368-
}
350+
// If the group name is specified, we sort them according to their source order,
351+
// which is the order preserved by getTopLeveDecls.
352+
if (!GroupName) {
353+
std::sort(SwiftDecls.begin(), SwiftDecls.end(),
354+
[&](Decl *LHS, Decl *RHS) -> bool {
355+
auto *LHSValue = dyn_cast<ValueDecl>(LHS);
356+
auto *RHSValue = dyn_cast<ValueDecl>(RHS);
357+
358+
if (LHSValue && RHSValue) {
359+
StringRef LHSName = LHSValue->getName().str();
360+
StringRef RHSName = RHSValue->getName().str();
361+
if (int Ret = LHSName.compare(RHSName))
362+
return Ret < 0;
363+
// FIXME: this is not sufficient to establish a total order for overloaded
364+
// decls.
365+
return LHS->getKind() < RHS->getKind();
366+
}
369367

370-
return LHS->getKind() < RHS->getKind();
371-
});
368+
return LHS->getKind() < RHS->getKind();
369+
});
370+
}
372371

373372
ASTPrinter *PrinterToUse = &Printer;
374373

lib/Serialization/ModuleFile.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ class ModuleFile::DeclCommentTableInfo {
597597
}
598598
result.Raw = RawComment(Comments);
599599
result.Group = endian::readNext<uint32_t, little, unaligned>(data);
600-
result.SourceOrder = endian::readNext<uint32_t, little, unaligned>(data);
601600
return result;
602601
}
603602
};
@@ -1557,15 +1556,6 @@ Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) const {
15571556
return getGroupNameById(Triple.getValue().Group);
15581557
}
15591558

1560-
Optional<unsigned>
1561-
ModuleFile::getSourceOrderForDecl(const Decl *D) const {
1562-
auto Triple = getCommentForDecl(D);
1563-
if (!Triple.hasValue()) {
1564-
return None;
1565-
}
1566-
return Triple.getValue().SourceOrder;
1567-
}
1568-
15691559
void ModuleFile::collectAllGroups(std::vector<StringRef> &Names) const {
15701560
if (!GroupNamesMap)
15711561
return;

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,6 @@ struct DeclCommentTableData {
34153415
StringRef Brief;
34163416
RawComment Raw;
34173417
uint32_t Group;
3418-
uint32_t Order;
34193418
};
34203419

34213420
class DeclCommentTableInfo {
@@ -3448,9 +3447,6 @@ class DeclCommentTableInfo {
34483447

34493448
// Group Id.
34503449
dataLength += numLen;
3451-
3452-
// Source order.
3453-
dataLength += numLen;
34543450
endian::Writer<little> writer(out);
34553451
writer.write<uint32_t>(keyLength);
34563452
writer.write<uint32_t>(dataLength);
@@ -3473,7 +3469,6 @@ class DeclCommentTableInfo {
34733469
out << C.RawText;
34743470
}
34753471
writer.write<uint32_t>(data.Group);
3476-
writer.write<uint32_t>(data.Order);
34773472
}
34783473
};
34793474

@@ -3580,8 +3575,7 @@ static void writeDeclCommentTable(
35803575

35813576
generator.insert(copyString(USRBuffer.str()),
35823577
{ VD->getBriefComment(), Raw,
3583-
GroupContext.getGroupSequence(VD),
3584-
SourceOrder ++ });
3578+
GroupContext.getGroupSequence(VD) });
35853579
return true;
35863580
}
35873581
};

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,6 @@ SerializedASTFile::getGroupNameForDecl(const Decl *D) const {
494494
return File.getGroupNameForDecl(D);
495495
}
496496

497-
Optional<unsigned>
498-
SerializedASTFile::getSourceOrderForDecl(const Decl *D) const {
499-
return File.getSourceOrderForDecl(D);
500-
}
501-
502497
void
503498
SerializedASTFile::collectAllGroups(std::vector<StringRef> &Names) const {
504499
File.collectAllGroups(Names);

0 commit comments

Comments
 (0)