Skip to content

Commit f1e532c

Browse files
authored
Merge pull request #36270 from rintaro/ast-getserializedlocs-rdar75010520
[AST] Only use serialized locs for 'getRawComment()' in symbol graph
2 parents bb375c3 + 5a29371 commit f1e532c

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ class alignas(1 << DeclAlignInBits) Decl {
877877
}
878878

879879
/// \returns the unparsed comment attached to this declaration.
880-
RawComment getRawComment(bool SerializedOK = true) const;
880+
RawComment getRawComment(bool SerializedOK = false) const;
881881

882882
Optional<StringRef> getGroupName() const;
883883

lib/AST/Decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ const Decl::CachedExternalSourceLocs *Decl::getSerializedLocs() const {
602602
return CachedSerializedLocs;
603603
}
604604
auto *File = cast<FileUnit>(getDeclContext()->getModuleScopeContext());
605+
assert(File->getKind() == FileUnitKind::SerializedAST &&
606+
"getSerializedLocs() should only be called on decls in "
607+
"a 'SerializedASTFile'");
605608
auto Locs = File->getBasicLocsForDecl(this);
606609
if (!Locs.hasValue()) {
607610
static const Decl::CachedExternalSourceLocs NullLocs{};

lib/AST/DocComment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ const ValueDecl *findRequirementDeclWithDocComment(const ValueDecl *VD,
440440
std::queue<const ValueDecl *> requirements;
441441
while (true) {
442442
for (auto *req : VD->getSatisfiedProtocolRequirements()) {
443-
if (!req->getRawComment().isEmpty())
443+
if (!req->getRawComment(AllowSerialized).isEmpty())
444444
return req;
445445
else
446446
requirements.push(req);

lib/AST/RawComment.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,14 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
147147
return Result;
148148
}
149149

150-
// Ask the parent module.
151-
if (auto *Unit =
152-
dyn_cast<FileUnit>(this->getDeclContext()->getModuleScopeContext())) {
150+
if (!getDeclContext())
151+
return RawComment();
152+
auto *Unit = dyn_cast<FileUnit>(getDeclContext()->getModuleScopeContext());
153+
if (!Unit)
154+
return RawComment();
155+
156+
switch (Unit->getKind()) {
157+
case FileUnitKind::SerializedAST: {
153158
if (SerializedOK) {
154159
if (const auto *CachedLocs = getSerializedLocs()) {
155160
if (!CachedLocs->DocRanges.empty()) {
@@ -158,8 +163,8 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
158163
if (Range.isValid()) {
159164
SRCs.push_back({ Range, Context.SourceMgr });
160165
} else {
161-
// if we've run into an invalid range, don't bother trying to load any of
162-
// the other comments
166+
// if we've run into an invalid range, don't bother trying to load
167+
// any of the other comments
163168
SRCs.clear();
164169
break;
165170
}
@@ -178,10 +183,17 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
178183
Context.setRawComment(this, C->Raw);
179184
return C->Raw;
180185
}
181-
}
182186

183-
// Give up.
184-
return RawComment();
187+
return RawComment();
188+
}
189+
case FileUnitKind::Source:
190+
case FileUnitKind::Builtin:
191+
case FileUnitKind::Synthesized:
192+
case FileUnitKind::ClangModule:
193+
case FileUnitKind::DWARFModule:
194+
return RawComment();
195+
}
196+
llvm_unreachable("invalid file kind");
185197
}
186198

187199
static const Decl* getGroupDecl(const Decl *D) {

0 commit comments

Comments
 (0)