mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
- Add CompilerInvocation::getPCHHash
This will be used when creating a unique filename for a persistent
precompiled bridging header.
- Automatically generate and use a precompiled briding header
When we're given both -import-objc-header and -pch-output-dir
arguments, we will try to:
- Validate what we think the PCH filename should be for the bridging
header, based on the Swift PCH hash and the clang module hash.
- If we're successful, we'll just use it.
- If it's out of date or something else is wrong, we'll try to
emit it.
- This gives us a single filename which we can `stat` to check for the
validity of our code completion cache, which is keyed off of module
name, module filename, and module file age.
- Cache code completion results from imported modules
If we just have a single .PCH file imported, we can use that file as
part of the key used to cache declarations in a module. Because
multiple files can contribute to the __ObjC module, we've always given
it the phony filename "<imports>", which never exists, so `stat`-ing it
always fails and we never cache declarations in it.
This is extremely problematic for projects with huge bridging headers.
In the case where we have a single PCH import, this can bring warm code
completion times down to about 500ms from over 2-3s, so it can provide a
nice performance win for IDEs.
- Add a new test that performs two code-completion requests with a bridging header.
- Add some -pch-output-dir flags to existing SourceKit tests that import a bridging
header.
rdar://problem/31198982
116 lines
3.9 KiB
C++
116 lines
3.9 KiB
C++
//===--- ClangImporterOptions.h ---------------------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_CLANGIMPORTER_CLANGIMPORTEROPTIONS_H
|
|
#define SWIFT_CLANGIMPORTER_CLANGIMPORTEROPTIONS_H
|
|
|
|
#include "llvm/ADT/Hashing.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace swift {
|
|
|
|
/// Options for controlling the behavior of the Clang importer.
|
|
class ClangImporterOptions {
|
|
public:
|
|
/// The module cache path which the Clang importer should use.
|
|
std::string ModuleCachePath;
|
|
|
|
/// Extra arguments which should be passed to the Clang importer.
|
|
std::vector<std::string> ExtraArgs;
|
|
|
|
/// A directory for overriding Clang's resource directory.
|
|
std::string OverrideResourceDir;
|
|
|
|
/// The target CPU to compile for.
|
|
///
|
|
/// Equivalent to Clang's -mcpu=.
|
|
std::string TargetCPU;
|
|
|
|
/// The bridging header or PCH that will be imported.
|
|
std::string BridgingHeader;
|
|
|
|
/// When automatically generating a precompiled header from the bridging
|
|
/// header, place it in this directory.
|
|
std::string PrecompiledHeaderOutputDir;
|
|
|
|
/// \see Mode
|
|
enum class Modes : uint8_t {
|
|
/// Set up Clang for importing modules into Swift and generating IR from
|
|
/// Swift code.
|
|
Normal,
|
|
/// Set up Clang for backend compilation only.
|
|
EmbedBitcode
|
|
};
|
|
|
|
/// Controls how Clang is initially set up.
|
|
Modes Mode = Modes::Normal;
|
|
|
|
/// When set, preserves more information during import.
|
|
///
|
|
/// Also \em disables some information that is only needed for object file
|
|
/// generation.
|
|
bool DetailedPreprocessingRecord = false;
|
|
|
|
/// If true, Clang diagnostics will be dumped to stderr using Clang's
|
|
/// diagnostic printer as well as being passed to Swift's diagnostic engine.
|
|
bool DumpClangDiagnostics = false;
|
|
|
|
/// If true, forward declarations will be imported using unavailable types
|
|
/// instead of dropped altogether when possible.
|
|
bool ImportForwardDeclarations = false;
|
|
|
|
/// Whether to use the import as member inference system
|
|
///
|
|
/// When importing a global, try to infer whether we can import it as a
|
|
/// member of some type instead. This includes inits, computed properties,
|
|
/// and methods.
|
|
bool InferImportAsMember = false;
|
|
|
|
/// If true ignore the swift bridged attribute.
|
|
bool DisableSwiftBridgeAttr = false;
|
|
|
|
/// When set, don't validate module system headers. If a header is modified
|
|
/// and this is not set, clang will rebuild the module.
|
|
bool DisableModulesValidateSystemHeaders = false;
|
|
|
|
/// 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
|
|
|
|
#endif
|