mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ModuleInterface] Address misc review comments.
This commit is contained in:
@@ -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
|
||||
//
|
||||
|
||||
@@ -23,7 +23,6 @@ class ModuleFile;
|
||||
/// Common functionality shared between \c SerializedModuleLoader and
|
||||
/// \c ParseableInterfaceModuleLoader.
|
||||
class SerializedModuleLoaderBase : public ModuleLoader {
|
||||
llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> MemoryBuffers;
|
||||
/// A { module, generation # } pair.
|
||||
using LoadedModulePair = std::pair<std::unique_ptr<ModuleFile>, unsigned>;
|
||||
std::vector<LoadedModulePair> LoadedModuleFiles;
|
||||
@@ -31,11 +30,12 @@ class SerializedModuleLoaderBase : public ModuleLoader {
|
||||
SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> OrphanedMemoryBuffers;
|
||||
|
||||
protected:
|
||||
llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> MemoryBuffers;
|
||||
ASTContext &Ctx;
|
||||
explicit SerializedModuleLoaderBase(ASTContext &ctx, DependencyTracker *tracker);
|
||||
SerializedModuleLoaderBase(ASTContext &ctx, DependencyTracker *tracker);
|
||||
|
||||
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> *moduleDocBuffer,
|
||||
bool &isFramework);
|
||||
@@ -63,24 +63,14 @@ public:
|
||||
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
|
||||
bool isFramework = false);
|
||||
|
||||
/// \brief 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);
|
||||
}
|
||||
|
||||
/// \brief Check whether the module with a given name can be imported without
|
||||
/// Check whether the module with a given name can be imported without
|
||||
/// importing it.
|
||||
///
|
||||
/// Note that even if this check succeeds, errors may still occur if the
|
||||
/// module is loaded in full.
|
||||
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.
|
||||
///
|
||||
@@ -107,17 +97,27 @@ public:
|
||||
virtual void verifyAllModules() override;
|
||||
};
|
||||
|
||||
/// \brief Imports serialized Swift modules into an ASTContext.
|
||||
/// Imports serialized Swift modules into an ASTContext.
|
||||
class SerializedModuleLoader : public SerializedModuleLoaderBase {
|
||||
|
||||
explicit SerializedModuleLoader(ASTContext &ctx, DependencyTracker *tracker)
|
||||
SerializedModuleLoader(ASTContext &ctx, DependencyTracker *tracker)
|
||||
: SerializedModuleLoaderBase(ctx, tracker)
|
||||
{}
|
||||
|
||||
public:
|
||||
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.
|
||||
static std::unique_ptr<SerializedModuleLoader>
|
||||
create(ASTContext &ctx, DependencyTracker *tracker = nullptr) {
|
||||
|
||||
@@ -130,7 +130,33 @@ generateOptimizationRemarkRegex(DiagnosticEngine &Diags, ArgList &Args,
|
||||
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.
|
||||
static void SaveParseableInterfaceArgs(ParseableInterfaceOptions &Opts,
|
||||
ArgList &Args, DiagnosticEngine &Diags) {
|
||||
@@ -632,6 +658,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Args.hasArg(OPT_sil_existential_specializer)) {
|
||||
Opts.ExistentialSpecializer = true;
|
||||
}
|
||||
if (const Arg *A = Args.getLastArg(OPT_num_threads)) {
|
||||
if (StringRef(A->getValue()).getAsInteger(10, Opts.NumThreads)) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
|
||||
Reference in New Issue
Block a user