Skip to content

[Serialization] Refactor subset of ModuleFile into ModuleFileCore #32470

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 7, 2020
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
2 changes: 1 addition & 1 deletion include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
using LoadedModulePair = std::pair<std::unique_ptr<ModuleFile>, unsigned>;
std::vector<LoadedModulePair> LoadedModuleFiles;

SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> OrphanedMemoryBuffers;
SmallVector<std::unique_ptr<ModuleFile>, 2> OrphanedModuleFiles;

protected:
ASTContext &Ctx;
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ constexpr static const StringLiteral SWIFT_ONONE_SUPPORT = "SwiftOnoneSupport";
constexpr static const StringLiteral SWIFT_SHIMS_NAME = "SwiftShims";
/// The name of the Builtin module, which contains Builtin functions.
constexpr static const StringLiteral BUILTIN_NAME = "Builtin";
/// The name of the clang imported header module.
constexpr static const StringLiteral CLANG_HEADER_MODULE_NAME = "__ObjC";
/// The prefix of module names used by LLDB to capture Swift expressions
constexpr static const StringLiteral LLDB_EXPRESSIONS_MODULE_NAME_PREFIX =
"__lldb_expr_";
Expand Down
4 changes: 3 additions & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "swift/Config.h"
#include "swift/Parse/Lexer.h"
#include "swift/Parse/Parser.h"
#include "swift/Strings.h"
#include "swift/Subsystems.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Mangle.h"
Expand Down Expand Up @@ -1196,7 +1197,8 @@ ClangImporter::create(ASTContext &ctx, const ClangImporterOptions &importerOpts,
= clangContext.Selectors.getSelector(2, setObjectForKeyedSubscriptIdents);

// Set up the imported header module.
auto *importedHeaderModule = ModuleDecl::create(ctx.getIdentifier("__ObjC"), ctx);
auto *importedHeaderModule =
ModuleDecl::create(ctx.getIdentifier(CLANG_HEADER_MODULE_NAME), ctx);
importer->Impl.ImportedHeaderUnit =
new (ctx) ClangModuleUnit(*importedHeaderModule, importer->Impl, nullptr);
importedHeaderModule->addFile(*importer->Impl.ImportedHeaderUnit);
Expand Down
1 change: 1 addition & 0 deletions lib/Serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_swift_host_library(swiftSerialization STATIC
DeserializeSIL.cpp
ModuleDependencyScanner.cpp
ModuleFile.cpp
ModuleFileSharedCore.cpp
Serialization.cpp
SerializedModuleLoader.cpp
SerializedSILLoader.cpp
Expand Down
27 changes: 9 additions & 18 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ using namespace swift::serialization;
using llvm::Expected;

StringRef swift::getNameOfModule(const ModuleFile *MF) {
return MF->Name;
return MF->getName();
}

namespace {
Expand Down Expand Up @@ -166,33 +166,30 @@ static void skipRecord(llvm::BitstreamCursor &cursor, unsigned recordKind) {

void ModuleFile::fatal(llvm::Error error) {
if (FileContext) {
getContext().Diags.diagnose(SourceLoc(), diag::serialization_fatal, Name);
getContext().Diags.diagnose(SourceLoc(), diag::serialization_fatal, Core->Name);
getContext().Diags.diagnose(SourceLoc(), diag::serialization_misc_version,
Name, MiscVersion);
Core->Name, Core->MiscVersion);

if (!CompatibilityVersion.empty()) {
if (!Core->CompatibilityVersion.empty()) {
if (getContext().LangOpts.EffectiveLanguageVersion
!= CompatibilityVersion) {
!= Core->CompatibilityVersion) {
SmallString<16> effectiveVersionBuffer, compatVersionBuffer;
{
llvm::raw_svector_ostream out(effectiveVersionBuffer);
out << getContext().LangOpts.EffectiveLanguageVersion;
}
{
llvm::raw_svector_ostream out(compatVersionBuffer);
out << CompatibilityVersion;
out << Core->CompatibilityVersion;
}
getContext().Diags.diagnose(
SourceLoc(), diag::serialization_compatibility_version_mismatch,
effectiveVersionBuffer, Name, compatVersionBuffer);
effectiveVersionBuffer, Core->Name, compatVersionBuffer);
}
}
}

logAllUnhandledErrors(std::move(error), llvm::errs(),
"\n*** DESERIALIZATION FAILURE (please include this "
"section in any bug report) ***\n");
abort();
ModuleFileSharedCore::fatal(std::move(error));
}

static Optional<swift::AccessorKind>
Expand Down Expand Up @@ -1871,13 +1868,7 @@ StringRef ModuleFile::getIdentifierText(IdentifierID IID) {
if (!identRecord.Ident.empty())
return identRecord.Ident.str();

assert(!IdentifierData.empty() && "no identifier data in module");

StringRef rawStrPtr = IdentifierData.substr(identRecord.Offset);
size_t terminatorOffset = rawStrPtr.find('\0');
assert(terminatorOffset != StringRef::npos &&
"unterminated identifier string data");
return rawStrPtr.slice(0, terminatorOffset);
return Core->getIdentifierText(IID);
}

DeclContext *ModuleFile::getLocalDeclContext(LocalDeclContextID DCID) {
Expand Down
13 changes: 13 additions & 0 deletions lib/Serialization/DeserializationErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

namespace swift {
class ModuleFile;
class ModuleFileSharedCore;

StringRef getNameOfModule(const ModuleFile *);
StringRef getNameOfModule(const ModuleFileSharedCore *);

namespace serialization {

Expand Down Expand Up @@ -456,6 +458,17 @@ class PrettyStackTraceModuleFile : public llvm::PrettyStackTraceEntry {
}
};

class PrettyStackTraceModuleFileCore : public llvm::PrettyStackTraceEntry {
const ModuleFileSharedCore &MF;
public:
explicit PrettyStackTraceModuleFileCore(ModuleFileSharedCore &module)
: MF(module) {}

void print(raw_ostream &os) const override {
os << "While reading from \'" << getNameOfModule(&MF) << "'\n";
}
};

} // end namespace serialization
} // end namespace swift

Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
// Mark this function as deserialized. This avoids rerunning diagnostic
// passes. Certain passes in the madatory pipeline may not work as expected
// after arbitrary optimization and lowering.
if (!MF->IsSIB)
if (!MF->isSIB())
fn->setWasDeserializedCanonical();

fn->setBare(IsBare);
Expand Down
Loading