Skip to content

Commit d24a2f5

Browse files
make ASTContext RawComment cache aware of serialization
rdar://76162972
1 parent 172df21 commit d24a2f5

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,8 @@ class ASTContext final {
11701170

11711171
private:
11721172
friend Decl;
1173-
Optional<RawComment> getRawComment(const Decl *D);
1174-
void setRawComment(const Decl *D, RawComment RC);
1173+
Optional<std::pair<RawComment, bool>> getRawComment(const Decl *D);
1174+
void setRawComment(const Decl *D, RawComment RC, bool FromSerialized);
11751175

11761176
Optional<StringRef> getBriefComment(const Decl *D);
11771177
void setBriefComment(const Decl *D, StringRef Comment);

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ struct ASTContext::Implementation {
285285
ClangModuleLoader *TheDWARFModuleLoader = nullptr;
286286

287287
/// Map from Swift declarations to raw comments.
288-
llvm::DenseMap<const Decl *, RawComment> RawComments;
288+
llvm::DenseMap<const Decl *, std::pair<RawComment, bool>> RawComments;
289289

290290
/// Map from Swift declarations to brief comments.
291291
llvm::DenseMap<const Decl *, StringRef> BriefComments;
@@ -2020,16 +2020,16 @@ ModuleDecl *ASTContext::getStdlibModule(bool loadIfAbsent) {
20202020
return TheStdlibModule;
20212021
}
20222022

2023-
Optional<RawComment> ASTContext::getRawComment(const Decl *D) {
2023+
Optional<std::pair<RawComment, bool>> ASTContext::getRawComment(const Decl *D) {
20242024
auto Known = getImpl().RawComments.find(D);
20252025
if (Known == getImpl().RawComments.end())
20262026
return None;
20272027

20282028
return Known->second;
20292029
}
20302030

2031-
void ASTContext::setRawComment(const Decl *D, RawComment RC) {
2032-
getImpl().RawComments[D] = RC;
2031+
void ASTContext::setRawComment(const Decl *D, RawComment RC, bool FromSerialized) {
2032+
getImpl().RawComments[D] = std::make_pair(RC, FromSerialized);
20332033
}
20342034

20352035
Optional<StringRef> ASTContext::getBriefComment(const Decl *D) {

lib/AST/RawComment.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,16 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
137137

138138
// Check the cache in ASTContext.
139139
auto &Context = getASTContext();
140-
if (Optional<RawComment> RC = Context.getRawComment(this))
141-
return RC.getValue();
140+
if (Optional<std::pair<RawComment, bool>> RC = Context.getRawComment(this)) {
141+
auto P = RC.getValue();
142+
if (!SerializedOK || P.second)
143+
return P.first;
144+
}
142145

143146
// Check the declaration itself.
144147
if (auto *Attr = getAttrs().getAttribute<RawDocCommentAttr>()) {
145148
RawComment Result = toRawComment(Context, Attr->getCommentRange());
146-
Context.setRawComment(this, Result);
149+
Context.setRawComment(this, Result, true);
147150
return Result;
148151
}
149152

@@ -172,15 +175,15 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
172175
auto RC = RawComment(Context.AllocateCopy(llvm::makeArrayRef(SRCs)));
173176

174177
if (!RC.isEmpty()) {
175-
Context.setRawComment(this, RC);
178+
Context.setRawComment(this, RC, true);
176179
return RC;
177180
}
178181
}
179182
}
180183
}
181184

182185
if (Optional<CommentInfo> C = Unit->getCommentForDecl(this)) {
183-
Context.setRawComment(this, C->Raw);
186+
Context.setRawComment(this, C->Raw, false);
184187
return C->Raw;
185188
}
186189

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name BatchMode -emit-module-path %t/BatchMode.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t -O -enable-batch-mode -incremental
3+
// RUN: %FileCheck %s --input-file %t/BatchMode.symbols.json
4+
5+
/// This is some func.
6+
public func someFunc() {}
7+
8+
// CHECK: range

0 commit comments

Comments
 (0)