Skip to content

[6.0][Basic] Don't rewrite source buffer copy multiple times #75118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions include/swift/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GeneratedSourceInfo {

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

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

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

/// Retrieve the list of ancestors of the given source buffer, starting with
/// the root buffer and proceding to the given buffer ID at the end.
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ ModuleDecl::getOriginalLocation(SourceLoc loc) const {

SourceLoc startLoc = loc;
unsigned startBufferID = bufferID;
while (std::optional<GeneratedSourceInfo> info =
while (const GeneratedSourceInfo *info =
SM.getGeneratedSourceInfo(bufferID)) {
switch (info->kind) {
#define MACRO_ROLE(Name, Description) \
Expand Down
9 changes: 5 additions & 4 deletions lib/Basic/SourceLoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ StringRef SourceManager::getIdentifierForBuffer(
// If this is generated source code, and we're supposed to force it to disk
// so external clients can see it, do so now.
if (ForceGeneratedSourceToDisk) {
if (auto generatedInfo = getGeneratedSourceInfo(bufferID)) {
if (const GeneratedSourceInfo *generatedInfo =
getGeneratedSourceInfo(bufferID)) {
// We only care about macros, so skip everything else.
if (generatedInfo->kind == GeneratedSourceInfo::ReplacedFunctionBody ||
generatedInfo->kind == GeneratedSourceInfo::PrettyPrinted ||
Expand Down Expand Up @@ -402,12 +403,12 @@ bool SourceManager::hasGeneratedSourceInfo(unsigned bufferID) {
return GeneratedSourceInfos.count(bufferID);
}

std::optional<GeneratedSourceInfo>
const GeneratedSourceInfo *
SourceManager::getGeneratedSourceInfo(unsigned bufferID) const {
auto known = GeneratedSourceInfos.find(bufferID);
if (known == GeneratedSourceInfos.end())
return std::nullopt;
return known->second;
return nullptr;
return &known->second;
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static DeclContext *getInnermostFunctionContext(DeclContext *DC) {
}

/// Return location of the macro expansion and the macro name.
static MacroInfo getMacroInfo(GeneratedSourceInfo &Info,
static MacroInfo getMacroInfo(const GeneratedSourceInfo &Info,
DeclContext *FunctionDC) {
MacroInfo Result(Info.generatedSourceRange.getStart(),
Info.originalSourceRange.getStart());
Expand Down