Skip to content

SerializeLoc: address Jordan's previous code review comments. NFC #27845

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
Oct 23, 2019
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
32 changes: 13 additions & 19 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ namespace Lowering {
class TypeConverter;
}

struct ModuleBuffers {
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
ModuleBuffers(std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer = nullptr,
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer = nullptr):
ModuleBuffer(std::move(ModuleBuffer)),
ModuleDocBuffer(std::move(ModuleDocBuffer)),
ModuleSourceInfoBuffer(std::move(ModuleSourceInfoBuffer)) {}
};

/// The abstract configuration of the compiler, including:
/// - options for all stages of translation,
/// - information about the build environment,
Expand Down Expand Up @@ -392,15 +404,9 @@ class CompilerInstance {
/// Contains buffer IDs for input source code files.
std::vector<unsigned> InputSourceCodeBufferIDs;

struct PartialModuleInputs {
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
};

/// Contains \c MemoryBuffers for partial serialized module files and
/// corresponding partial serialized module documentation files.
std::vector<PartialModuleInputs> PartialModules;
std::vector<ModuleBuffers> PartialModules;

enum : unsigned { NO_SUCH_BUFFER = ~0U };
unsigned MainBufferID = NO_SUCH_BUFFER;
Expand Down Expand Up @@ -556,18 +562,6 @@ class CompilerInstance {

Optional<unsigned> getRecordedBufferID(const InputFile &input, bool &failed);

struct ModuleBuffers {
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
ModuleBuffers(std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer = nullptr,
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer = nullptr):
ModuleBuffer(std::move(ModuleBuffer)),
ModuleDocBuffer(std::move(ModuleDocBuffer)),
ModuleSourceInfoBuffer(std::move(ModuleSourceInfoBuffer)) {}
};

/// Given an input file, return a buffer to use for its contents,
/// and a buffer for the corresponding module doc file if one exists.
/// On failure, return a null pointer for the first element of the returned
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
openModuleSourceInfoFileIfPresent(AccessPathElem ModuleID,
StringRef ModulePath,
StringRef ModuleSourceInfoFileName,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer);
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, when this left-alignment is necessary it's applied to all arguments for consistency. (We should all have clang-formats lying around…)


/// If the module loader subclass knows that all options have been tried for
/// loading an architecture-specific file out of a swiftmodule bundle, try
Expand Down
2 changes: 0 additions & 2 deletions lib/AST/USRGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ bool ide::printExtensionUSR(const ExtensionDecl *ED, raw_ostream &OS) {
}

bool ide::printDeclUSR(const Decl *D, raw_ostream &OS) {
if (D->isImplicit())
return true;
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (ide::printValueDeclUSR(VD, OS)) {
return true;
Expand Down
6 changes: 2 additions & 4 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ Optional<unsigned> CompilerInstance::getRecordedBufferID(const InputFile &input,
// FIXME: The fact that this test happens twice, for some cases,
// suggests that setupInputs could use another round of refactoring.
if (serialization::isSerializedAST(buffers->ModuleBuffer->getBuffer())) {
PartialModules.push_back(
{std::move(buffers->ModuleBuffer), std::move(buffers->ModuleDocBuffer),
std::move(buffers->ModuleSourceInfoBuffer)});
PartialModules.push_back(std::move(*buffers));
return None;
}
assert(buffers->ModuleDocBuffer.get() == nullptr);
Expand All @@ -516,7 +514,7 @@ Optional<unsigned> CompilerInstance::getRecordedBufferID(const InputFile &input,
return bufferID;
}

Optional<CompilerInstance::ModuleBuffers> CompilerInstance::getInputBuffersIfPresent(
Optional<ModuleBuffers> CompilerInstance::getInputBuffersIfPresent(
const InputFile &input) {
if (auto b = input.buffer()) {
return ModuleBuffers(llvm::MemoryBuffer::getMemBufferCopy(b->getBuffer(),
Expand Down
6 changes: 5 additions & 1 deletion lib/Serialization/ModuleFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ class ModuleFile::DeclUSRTableInfo {
std::unique_ptr<ModuleFile::SerializedDeclUSRTable>
ModuleFile::readDeclUSRsTable(ArrayRef<uint64_t> fields, StringRef blobData) {
if (fields.empty() || blobData.empty())
return nullptr;
return nullptr;
uint32_t tableOffset = static_cast<uint32_t>(fields.front());
auto base = reinterpret_cast<const uint8_t *>(blobData.data());
return std::unique_ptr<SerializedDeclUSRTable>(
Expand Down Expand Up @@ -2357,6 +2357,8 @@ Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {

if (!DeclCommentTable)
return None;
if (D->isImplicit())
return None;
// Compute the USR.
llvm::SmallString<128> USRBuffer;
llvm::raw_svector_ostream OS(USRBuffer);
Expand All @@ -2381,6 +2383,8 @@ ModuleFile::getBasicDeclLocsForDecl(const Decl *D) const {
// Future compilers may not provide BasicDeclLocsData anymore.
if (BasicDeclLocsData.empty())
return None;
if (D->isImplicit())
return None;
// Compute the USR.
llvm::SmallString<128> USRBuffer;
llvm::raw_svector_ostream OS(USRBuffer);
Expand Down
6 changes: 3 additions & 3 deletions lib/Serialization/SerializeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,12 @@ class StringWriter {
llvm::SmallString<1024> Buffer;
public:
uint32_t getTextOffset(StringRef Text) {
if (IndexMap.find(Text) == IndexMap.end()) {
IndexMap.insert({Text, Buffer.size()});
auto IterAndIsNew = IndexMap.insert({Text, Buffer.size()});
if (IterAndIsNew.second) {
Buffer.append(Text);
Buffer.push_back('\0');
}
return IndexMap[Text];
return (*IterAndIsNew.first).getValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: this is IterAndIsNew.first()->getValue(), no?

}

void emitSourceFilesRecord(llvm::BitstreamWriter &Out) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ std::error_code SerializedModuleLoaderBase::openModuleDocFile(

void
SerializedModuleLoaderBase::openModuleSourceInfoFileIfPresent(
AccessPathElem ModuleID,
StringRef ModulePath,
StringRef ModuleSourceInfoFilename,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) {
AccessPathElem ModuleID,
StringRef ModulePath,
StringRef ModuleSourceInfoFilename,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) {
if (!ModuleSourceInfoBuffer)
return;
llvm::vfs::FileSystem &FS = *Ctx.SourceMgr.getFileSystem();
Expand Down