[ModuleInterface] Address misc review comments.

This commit is contained in:
Graydon Hoare
2018-10-11 14:56:44 -07:00
parent 410fc10045
commit b71c55ab8b
3 changed files with 54 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
//===--- ParseableInterfaceSupport.h - swiftinterface files --*- C++ -*-===// //===--- ParseableInterfaceSupport.h - swiftinterface files -----*- C++ -*-===//
// //
// This source file is part of the Swift.org open source project // This source file is part of the Swift.org open source project
// //

View File

@@ -23,7 +23,6 @@ class ModuleFile;
/// Common functionality shared between \c SerializedModuleLoader and /// Common functionality shared between \c SerializedModuleLoader and
/// \c ParseableInterfaceModuleLoader. /// \c ParseableInterfaceModuleLoader.
class SerializedModuleLoaderBase : public ModuleLoader { class SerializedModuleLoaderBase : public ModuleLoader {
llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> MemoryBuffers;
/// A { module, generation # } pair. /// A { module, generation # } pair.
using LoadedModulePair = std::pair<std::unique_ptr<ModuleFile>, unsigned>; using LoadedModulePair = std::pair<std::unique_ptr<ModuleFile>, unsigned>;
std::vector<LoadedModulePair> LoadedModuleFiles; std::vector<LoadedModulePair> LoadedModuleFiles;
@@ -31,11 +30,12 @@ class SerializedModuleLoaderBase : public ModuleLoader {
SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> OrphanedMemoryBuffers; SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> OrphanedMemoryBuffers;
protected: protected:
llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> MemoryBuffers;
ASTContext &Ctx; ASTContext &Ctx;
explicit SerializedModuleLoaderBase(ASTContext &ctx, DependencyTracker *tracker); SerializedModuleLoaderBase(ASTContext &ctx, DependencyTracker *tracker);
using AccessPathElem = std::pair<Identifier, SourceLoc>; using AccessPathElem = std::pair<Identifier, SourceLoc>;
virtual bool findModule(AccessPathElem moduleID, bool findModule(AccessPathElem moduleID,
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer, std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer, std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
bool &isFramework); bool &isFramework);
@@ -63,24 +63,14 @@ public:
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer, std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
bool isFramework = false); bool isFramework = false);
/// \brief Register a memory buffer that contains the serialized /// Check whether the module with a given name can be imported without
/// module for the given access path. This API is intended to be
/// used by LLDB to add swiftmodules discovered in the __apple_ast
/// section of a Mach-O file to the search path.
/// FIXME: make this an actual access *path* once submodules are designed.
void registerMemoryBuffer(StringRef AccessPath,
std::unique_ptr<llvm::MemoryBuffer> input) {
MemoryBuffers[AccessPath] = std::move(input);
}
/// \brief Check whether the module with a given name can be imported without
/// importing it. /// importing it.
/// ///
/// Note that even if this check succeeds, errors may still occur if the /// Note that even if this check succeeds, errors may still occur if the
/// module is loaded in full. /// module is loaded in full.
virtual bool canImportModule(std::pair<Identifier, SourceLoc> named) override; virtual bool canImportModule(std::pair<Identifier, SourceLoc> named) override;
/// \brief Import a module with the given module path. /// Import a module with the given module path.
/// ///
/// \param importLoc The location of the 'import' keyword. /// \param importLoc The location of the 'import' keyword.
/// ///
@@ -107,17 +97,27 @@ public:
virtual void verifyAllModules() override; virtual void verifyAllModules() override;
}; };
/// \brief Imports serialized Swift modules into an ASTContext. /// Imports serialized Swift modules into an ASTContext.
class SerializedModuleLoader : public SerializedModuleLoaderBase { class SerializedModuleLoader : public SerializedModuleLoaderBase {
explicit SerializedModuleLoader(ASTContext &ctx, DependencyTracker *tracker) SerializedModuleLoader(ASTContext &ctx, DependencyTracker *tracker)
: SerializedModuleLoaderBase(ctx, tracker) : SerializedModuleLoaderBase(ctx, tracker)
{} {}
public: public:
virtual ~SerializedModuleLoader(); virtual ~SerializedModuleLoader();
/// \brief Create a new importer that can load serialized Swift modules /// Register a memory buffer that contains the serialized
/// module for the given access path. This API is intended to be
/// used by LLDB to add swiftmodules discovered in the __apple_ast
/// section of a Mach-O file to the search path.
/// FIXME: make this an actual access *path* once submodules are designed.
void registerMemoryBuffer(StringRef AccessPath,
std::unique_ptr<llvm::MemoryBuffer> input) {
MemoryBuffers[AccessPath] = std::move(input);
}
/// Create a new importer that can load serialized Swift modules
/// into the given ASTContext. /// into the given ASTContext.
static std::unique_ptr<SerializedModuleLoader> static std::unique_ptr<SerializedModuleLoader>
create(ASTContext &ctx, DependencyTracker *tracker = nullptr) { create(ASTContext &ctx, DependencyTracker *tracker = nullptr) {

View File

@@ -130,7 +130,33 @@ generateOptimizationRemarkRegex(DiagnosticEngine &Diags, ArgList &Args,
return Pattern; return Pattern;
} }
/// \brief Save a copy of any flags marked as ParseableInterfaceOption, if running // Lifted from the clang driver.
static void PrintArg(raw_ostream &OS, const char *Arg, StringRef TempDir) {
const bool Escape = std::strpbrk(Arg, "\"\\$ ");
if (!TempDir.empty() && StringRef(Arg).startswith(TempDir)) {
// Don't write temporary file names in the debug info. This would prevent
// incremental llvm compilation because we would generate different IR on
// every compiler invocation.
Arg = "<temporary-file>";
}
if (!Escape) {
OS << Arg;
return;
}
// Quote and escape. This isn't really complete, but good enough.
OS << '"';
while (const char c = *Arg++) {
if (c == '"' || c == '\\' || c == '$')
OS << '\\';
OS << c;
}
OS << '"';
}
/// Save a copy of any flags marked as ParseableInterfaceOption, if running
/// in a mode that is going to emit a .swiftinterface file. /// in a mode that is going to emit a .swiftinterface file.
static void SaveParseableInterfaceArgs(ParseableInterfaceOptions &Opts, static void SaveParseableInterfaceArgs(ParseableInterfaceOptions &Opts,
ArgList &Args, DiagnosticEngine &Diags) { ArgList &Args, DiagnosticEngine &Diags) {
@@ -632,6 +658,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
return true; return true;
} }
} }
if (Args.hasArg(OPT_sil_existential_specializer)) {
Opts.ExistentialSpecializer = true;
}
if (const Arg *A = Args.getLastArg(OPT_num_threads)) { if (const Arg *A = Args.getLastArg(OPT_num_threads)) {
if (StringRef(A->getValue()).getAsInteger(10, Opts.NumThreads)) { if (StringRef(A->getValue()).getAsInteger(10, Opts.NumThreads)) {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,