Merge remote-tracking branch 'origin/master' into master-next

This commit is contained in:
swift-ci
2017-04-04 20:48:32 -07:00
24 changed files with 333 additions and 26 deletions

View File

@@ -209,6 +209,12 @@ public:
return OutputKind == IRGenOutputKind::LLVMAssembly;
}
}
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
return llvm::hash_value(0);
}
};
} // end namespace swift

View File

@@ -19,6 +19,7 @@
#define SWIFT_AST_SILOPTIONS_H
#include "swift/Basic/Sanitizers.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include <string>
#include <climits>
@@ -147,6 +148,11 @@ public:
SILOptions() : Sanitize(SanitizerKind::None) {}
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
return llvm::hash_value(0);
}
};
} // end namespace swift

View File

@@ -13,6 +13,8 @@
#ifndef SWIFT_AST_SEARCHPATHOPTIONS_H
#define SWIFT_AST_SEARCHPATHOPTIONS_H
#include "llvm/ADT/Hashing.h"
#include <string>
#include <vector>
@@ -67,6 +69,26 @@ public:
/// Don't look in for compiler-provided modules.
bool SkipRuntimeLibraryImportPath = false;
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
using llvm::hash_value;
using llvm::hash_combine;
auto Code = hash_value(SDKPath);
for (auto Import : ImportSearchPaths) {
Code = hash_combine(Code, Import);
}
for (const auto &FrameworkPath : FrameworkSearchPaths) {
Code = hash_combine(Code, FrameworkPath.Path);
}
for (auto LibraryPath : LibrarySearchPaths) {
Code = hash_combine(Code, LibraryPath);
}
Code = hash_combine(Code, RuntimeResourcePath);
Code = hash_combine(Code, RuntimeLibraryImportPath);
return Code;
}
};
}

View File

@@ -49,6 +49,13 @@ public:
/// Treat all warnings as errors
bool WarningsAsErrors = false;
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
// Nothing here that contributes anything significant when emitting the PCH.
return llvm::hash_value(0);
}
};
} // end namespace swift

View File

@@ -22,9 +22,12 @@
#include "swift/Basic/Version.h"
#include "clang/Basic/VersionTuple.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
#include <vector>
@@ -278,6 +281,17 @@ namespace swift {
PlatformConditionKind Kind, StringRef Value,
std::vector<StringRef> &suggestions);
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
auto code = llvm::hash_value(Target.str());
SmallString<16> Scratch;
llvm::raw_svector_ostream OS(Scratch);
OS << EffectiveLanguageVersion;
code = llvm::hash_combine(code, OS.str());
return code;
}
private:
llvm::SmallVector<std::pair<PlatformConditionKind, std::string>,
NumPlatformConditionKind>

View File

@@ -31,6 +31,7 @@ namespace clang {
class CodeGenOptions;
class Decl;
class DependencyCollector;
class DiagnosticConsumer;
class EnumConstantDecl;
class EnumDecl;
class MacroInfo;
@@ -44,6 +45,7 @@ namespace clang {
namespace swift {
class ASTContext;
class CompilerInvocation;
class ClangImporterOptions;
class ClangModuleUnit;
class ClangNode;
@@ -78,14 +80,19 @@ public:
/// \param ctx The ASTContext into which the module will be imported.
/// The ASTContext's SearchPathOptions will be used for the Clang importer.
///
/// \param clangImporterOpts The options to use for the Clang importer.
/// \param importerOpts The options to use for the Clang importer.
///
/// \param swiftPCHHash A hash of Swift's various options in a compiler
/// invocation, used to create a unique Bridging PCH if requested.
///
/// \param tracker The object tracking files this compilation depends on.
///
/// \returns a new Clang module importer, or null (with a diagnostic) if
/// an error occurred.
static std::unique_ptr<ClangImporter>
create(ASTContext &ctx, const ClangImporterOptions &clangImporterOpts,
create(ASTContext &ctx,
const ClangImporterOptions &importerOpts,
std::string swiftPCHHash = "",
DependencyTracker *tracker = nullptr);
ClangImporter(const ClangImporter &) = delete;
@@ -234,7 +241,14 @@ public:
/// replica.
///
/// \sa clang::GeneratePCHAction
bool emitBridgingPCH(StringRef headerPath, StringRef outputPCHPath);
bool emitBridgingPCH(StringRef headerPath,
StringRef outputPCHPath,
clang::DiagnosticConsumer *Diags = nullptr);
/// Returns true if a clang CompilerInstance can successfully read in a PCH,
/// assuming it exists, with the current options. This can be used to find out
/// if we need to persist a PCH for later reuse.
bool canReadPCH(StringRef PCHFilename);
const clang::Module *getClangOwningModule(ClangNode Node) const;
bool hasTypedef(const clang::Decl *typeDecl) const;
@@ -291,6 +305,13 @@ public:
DeclName importName(const clang::NamedDecl *D,
clang::DeclarationName givenName);
Optional<std::string>
getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
const std::string &SwiftPCHHash);
Optional<std::string>
getPCHFilename(const ClangImporterOptions &ImporterOptions,
const std::string &SwiftPCHHash);
};
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,

View File

@@ -13,6 +13,8 @@
#ifndef SWIFT_CLANGIMPORTER_CLANGIMPORTEROPTIONS_H
#define SWIFT_CLANGIMPORTER_CLANGIMPORTEROPTIONS_H
#include "llvm/ADT/Hashing.h"
#include <string>
#include <vector>
@@ -43,7 +45,7 @@ public:
std::string PrecompiledHeaderOutputDir;
/// \see Mode
enum class Modes {
enum class Modes : uint8_t {
/// Set up Clang for importing modules into Swift and generating IR from
/// Swift code.
Normal,
@@ -84,6 +86,28 @@ public:
/// When set, don't look for or load adapter modules.
bool DisableAdapterModules = false;
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
using llvm::hash_value;
using llvm::hash_combine;
auto Code = hash_value(ModuleCachePath);
// ExtraArgs ignored - already considered in Clang's module hashing.
Code = hash_combine(Code, OverrideResourceDir);
Code = hash_combine(Code, TargetCPU);
Code = hash_combine(Code, BridgingHeader);
Code = hash_combine(Code, PrecompiledHeaderOutputDir);
Code = hash_combine(Code, static_cast<uint8_t>(Mode));
Code = hash_combine(Code, DetailedPreprocessingRecord);
Code = hash_combine(Code, ImportForwardDeclarations);
Code = hash_combine(Code, InferImportAsMember);
Code = hash_combine(Code, DisableSwiftBridgeAttr);
Code = hash_combine(Code, DisableModulesValidateSystemHeaders);
Code = hash_combine(Code, DisableAdapterModules);
return Code;
}
};
} // end namespace swift

View File

@@ -292,6 +292,11 @@ public:
bool isDelayedFunctionBodyParsing() const {
return FrontendOpts.DelayedFunctionBodyParsing;
}
/// Retrieve a module hash string that is suitable for uniquely
/// identifying the conditions under which the module was built, for use
/// in generating a cached PCH file for the bridging header.
std::string getPCHHash() const;
};
/// A class which manages the state and execution of the compiler.

View File

@@ -14,6 +14,7 @@
#define SWIFT_FRONTEND_FRONTENDOPTIONS_H
#include "swift/AST/Module.h"
#include "llvm/ADT/Hashing.h"
#include <string>
#include <vector>
@@ -305,6 +306,12 @@ public:
OutputFilenames.clear();
OutputFilenames.push_back(FileName);
}
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {
return llvm::hash_value(0);
}
};
}