Files
swift-mirror/include/swift/AST/SearchPathOptions.h
David Farler 65668c9d82 Cache Code Completion results from PCH files
- 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
2017-04-04 20:44:33 -07:00

97 lines
3.0 KiB
C++

//===--- SearchPathOptions.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_AST_SEARCHPATHOPTIONS_H
#define SWIFT_AST_SEARCHPATHOPTIONS_H
#include "llvm/ADT/Hashing.h"
#include <string>
#include <vector>
namespace swift {
/// Options for controlling search path behavior.
class SearchPathOptions {
public:
/// Path to the SDK which is being built against.
std::string SDKPath;
/// Path(s) which should be searched for modules.
///
/// Do not add values to this directly. Instead, use
/// \c ASTContext::addSearchPath.
std::vector<std::string> ImportSearchPaths;
struct FrameworkSearchPath {
std::string Path;
bool IsSystem = false;
FrameworkSearchPath(StringRef path, bool isSystem)
: Path(path), IsSystem(isSystem) {}
friend bool operator ==(const FrameworkSearchPath &LHS,
const FrameworkSearchPath &RHS) {
return LHS.Path == RHS.Path && LHS.IsSystem == RHS.IsSystem;
}
friend bool operator !=(const FrameworkSearchPath &LHS,
const FrameworkSearchPath &RHS) {
return !(LHS == RHS);
}
};
/// Path(s) which should be searched for frameworks.
///
/// Do not add values to this directly. Instead, use
/// \c ASTContext::addSearchPath.
std::vector<FrameworkSearchPath> FrameworkSearchPaths;
/// Path(s) which should be searched for libraries.
///
/// This is used in immediate modes. It is safe to add paths to this directly.
std::vector<std::string> LibrarySearchPaths;
/// Path to search for compiler-relative header files.
std::string RuntimeResourcePath;
/// Path to search for compiler-relative stdlib dylibs.
std::string RuntimeLibraryPath;
/// Path to search for compiler-relative stdlib modules.
std::string RuntimeLibraryImportPath;
/// 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;
}
};
}
#endif