Skip to content

Commit ee010a9

Browse files
authored
Merge pull request swiftlang#75118 from rintaro/6.0-basic-ondiscbuffer-cache
[6.0][Basic] Don't rewrite source buffer copy multiple times
2 parents 5f191e4 + 78e14a4 commit ee010a9

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class GeneratedSourceInfo {
7171

7272
/// The name of the source file on disk that was created to hold the
7373
/// contents of this file for external clients.
74-
StringRef onDiskBufferCopyFileName = StringRef();
74+
mutable StringRef onDiskBufferCopyFileName = StringRef();
7575

7676
/// Contains the ancestors of this source buffer, starting with the root source
7777
/// buffer and ending at this source buffer.
@@ -209,8 +209,7 @@ class SourceManager {
209209
bool hasGeneratedSourceInfo(unsigned bufferID);
210210

211211
/// Retrieve the generated source information for the given buffer.
212-
std::optional<GeneratedSourceInfo>
213-
getGeneratedSourceInfo(unsigned bufferID) const;
212+
const GeneratedSourceInfo *getGeneratedSourceInfo(unsigned bufferID) const;
214213

215214
/// Retrieve the list of ancestors of the given source buffer, starting with
216215
/// the root buffer and proceding to the given buffer ID at the end.

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ ModuleDecl::getOriginalLocation(SourceLoc loc) const {
906906

907907
SourceLoc startLoc = loc;
908908
unsigned startBufferID = bufferID;
909-
while (std::optional<GeneratedSourceInfo> info =
909+
while (const GeneratedSourceInfo *info =
910910
SM.getGeneratedSourceInfo(bufferID)) {
911911
switch (info->kind) {
912912
#define MACRO_ROLE(Name, Description) \

lib/Basic/SourceLoc.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ StringRef SourceManager::getIdentifierForBuffer(
287287
// If this is generated source code, and we're supposed to force it to disk
288288
// so external clients can see it, do so now.
289289
if (ForceGeneratedSourceToDisk) {
290-
if (auto generatedInfo = getGeneratedSourceInfo(bufferID)) {
290+
if (const GeneratedSourceInfo *generatedInfo =
291+
getGeneratedSourceInfo(bufferID)) {
291292
// We only care about macros, so skip everything else.
292293
if (generatedInfo->kind == GeneratedSourceInfo::ReplacedFunctionBody ||
293294
generatedInfo->kind == GeneratedSourceInfo::PrettyPrinted ||
@@ -402,12 +403,12 @@ bool SourceManager::hasGeneratedSourceInfo(unsigned bufferID) {
402403
return GeneratedSourceInfos.count(bufferID);
403404
}
404405

405-
std::optional<GeneratedSourceInfo>
406+
const GeneratedSourceInfo *
406407
SourceManager::getGeneratedSourceInfo(unsigned bufferID) const {
407408
auto known = GeneratedSourceInfos.find(bufferID);
408409
if (known == GeneratedSourceInfos.end())
409-
return std::nullopt;
410-
return known->second;
410+
return nullptr;
411+
return &known->second;
411412
}
412413

413414
namespace {

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static DeclContext *getInnermostFunctionContext(DeclContext *DC) {
284284
}
285285

286286
/// Return location of the macro expansion and the macro name.
287-
static MacroInfo getMacroInfo(GeneratedSourceInfo &Info,
287+
static MacroInfo getMacroInfo(const GeneratedSourceInfo &Info,
288288
DeclContext *FunctionDC) {
289289
MacroInfo Result(Info.generatedSourceRange.getStart(),
290290
Info.originalSourceRange.getStart());

0 commit comments

Comments
 (0)