mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Caching] Encoding cache key for input file with index instead of path
Avoid path encoding difference (for example, real_path vs. path from symlink) by eliminating the path from cache key. Cache key is now encoded with the index of the input file from all the input files from the command-line, reguardless if those inputs will produce output or not. This is to ensure stable ordering even the batching is different. Add a new cache computation API that is preferred for using input index directly. Old API for cache key is deprecated but still updated to fallback to real_path comparsion if needed. As a result of swift scan API change, rename the feature in JSON file to avoid version confusion between swift-driver and libSwiftScan. rdar://119387650
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "llvm/CAS/ObjectStore.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/OptTable.h"
|
||||
#include "llvm/Support/EndianStream.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
@@ -84,13 +85,16 @@ llvm::Expected<llvm::cas::ObjectRef> swift::createCompileJobBaseCacheKey(
|
||||
return Out.takeError();
|
||||
}
|
||||
|
||||
llvm::Expected<llvm::cas::ObjectRef> swift::createCompileJobCacheKeyForOutput(
|
||||
llvm::cas::ObjectStore &CAS, llvm::cas::ObjectRef BaseKey,
|
||||
StringRef ProducingInput) {
|
||||
SmallString<256> OutputInfo;
|
||||
llvm::Expected<llvm::cas::ObjectRef>
|
||||
swift::createCompileJobCacheKeyForOutput(llvm::cas::ObjectStore &CAS,
|
||||
llvm::cas::ObjectRef BaseKey,
|
||||
unsigned InputIndex) {
|
||||
std::string InputInfo;
|
||||
llvm::raw_string_ostream OS(InputInfo);
|
||||
|
||||
// CacheKey is the producting input + the base key.
|
||||
OutputInfo.append(ProducingInput);
|
||||
// CacheKey is the index of the producting input + the base key.
|
||||
// Encode the unsigned value as little endian in the field.
|
||||
llvm::support::endian::write<uint32_t>(OS, InputIndex, llvm::support::little);
|
||||
|
||||
return CAS.storeFromString({BaseKey}, OutputInfo);
|
||||
return CAS.storeFromString({BaseKey}, OS.str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user