Skip to content

File tree

10 files changed

+16
-230
lines changed

10 files changed

+16
-230
lines changed

lldb/source/Core/DataFileCache.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ bool DataFileCache::SetCachedData(llvm::StringRef key,
132132
if (file_or_err) {
133133
llvm::CachedFileStream *cfs = file_or_err->get();
134134
cfs->OS->write((const char *)data.data(), data.size());
135-
if (llvm::Error err = cfs->commit()) {
136-
Log *log = GetLog(LLDBLog::Modules);
137-
LLDB_LOG_ERROR(log, std::move(err),
138-
"failed to commit to the cache for key: {0}");
139-
}
140135
return true;
141136
} else {
142137
Log *log = GetLog(LLDBLog::Modules);

llvm/include/llvm/Support/Caching.h

+2-19
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,15 @@ class MemoryBuffer;
2424
/// This class wraps an output stream for a file. Most clients should just be
2525
/// able to return an instance of this base class from the stream callback, but
2626
/// if a client needs to perform some action after the stream is written to,
27-
/// that can be done by deriving from this class and overriding the destructor
28-
/// or the commit() method.
27+
/// that can be done by deriving from this class and overriding the destructor.
2928
class CachedFileStream {
3029
public:
3130
CachedFileStream(std::unique_ptr<raw_pwrite_stream> OS,
3231
std::string OSPath = "")
3332
: OS(std::move(OS)), ObjectPathName(OSPath) {}
34-
35-
/// Must be called exactly once after the writes to OS have been completed
36-
/// but before the CachedFileStream object is destroyed.
37-
virtual Error commit() {
38-
if (Committed)
39-
return createStringError(make_error_code(std::errc::invalid_argument),
40-
Twine("CacheStream already committed."));
41-
Committed = true;
42-
43-
return Error::success();
44-
}
45-
46-
bool Committed = false;
4733
std::unique_ptr<raw_pwrite_stream> OS;
4834
std::string ObjectPathName;
49-
virtual ~CachedFileStream() {
50-
if (!Committed)
51-
report_fatal_error("CachedFileStream was not committed.\n");
52-
}
35+
virtual ~CachedFileStream() = default;
5336
};
5437

5538
/// This type defines the callback to add a file that is generated on the fly.

llvm/lib/CGData/CodeGenData.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
233233

234234
WriteBitcodeToFile(TheModule, *Stream->OS,
235235
/*ShouldPreserveUseListOrder=*/true);
236-
237-
if (Error Err = Stream->commit())
238-
report_fatal_error(std::move(Err));
239236
}
240237

241238
std::unique_ptr<Module> loadModuleForTwoRounds(BitcodeModule &OrigModule,

llvm/lib/Debuginfod/Debuginfod.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ class StreamedHTTPResponseHandler : public HTTPResponseHandler {
188188
public:
189189
StreamedHTTPResponseHandler(CreateStreamFn CreateStream, HTTPClient &Client)
190190
: CreateStream(CreateStream), Client(Client) {}
191-
192-
/// Must be called exactly once after the writes have been completed
193-
/// but before the StreamedHTTPResponseHandler object is destroyed.
194-
Error commit();
195-
196191
virtual ~StreamedHTTPResponseHandler() = default;
197192

198193
Error handleBodyChunk(StringRef BodyChunk) override;
@@ -215,12 +210,6 @@ Error StreamedHTTPResponseHandler::handleBodyChunk(StringRef BodyChunk) {
215210
return Error::success();
216211
}
217212

218-
Error StreamedHTTPResponseHandler::commit() {
219-
if (FileStream)
220-
return FileStream->commit();
221-
return Error::success();
222-
}
223-
224213
// An over-accepting simplification of the HTTP RFC 7230 spec.
225214
static bool isHeader(StringRef S) {
226215
StringRef Name;
@@ -309,8 +298,6 @@ Expected<std::string> getCachedOrDownloadArtifact(
309298
Error Err = Client.perform(Request, Handler);
310299
if (Err)
311300
return std::move(Err);
312-
if (Err = Handler.commit())
313-
return std::move(Err);
314301

315302
unsigned Code = Client.responseCode();
316303
if (Code && Code != 200)

llvm/lib/LTO/LTOBackend.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,6 @@ static void codegen(const Config &Conf, TargetMachine *TM,
460460

461461
if (DwoOut)
462462
DwoOut->keep();
463-
464-
if (Error Err = Stream->commit())
465-
report_fatal_error(std::move(Err));
466463
}
467464

468465
static void splitCodeGen(const Config &C, TargetMachine *TM,

llvm/lib/Support/Caching.cpp

+12-17
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
8888
AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)),
8989
ModuleName(ModuleName), Task(Task) {}
9090

91-
Error commit() override {
92-
Error E = CachedFileStream::commit();
93-
if (E)
94-
return E;
91+
~CacheStream() {
92+
// TODO: Manually commit rather than using non-trivial destructor,
93+
// allowing to replace report_fatal_errors with a return Error.
9594

9695
// Make sure the stream is closed before committing it.
9796
OS.reset();
@@ -101,12 +100,10 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
101100
MemoryBuffer::getOpenFile(
102101
sys::fs::convertFDToNativeFile(TempFile.FD), ObjectPathName,
103102
/*FileSize=*/-1, /*RequiresNullTerminator=*/false);
104-
if (!MBOrErr) {
105-
std::error_code EC = MBOrErr.getError();
106-
return createStringError(EC, Twine("Failed to open new cache file ") +
107-
TempFile.TmpName + ": " +
108-
EC.message() + "\n");
109-
}
103+
if (!MBOrErr)
104+
report_fatal_error(Twine("Failed to open new cache file ") +
105+
TempFile.TmpName + ": " +
106+
MBOrErr.getError().message() + "\n");
110107

111108
// On POSIX systems, this will atomically replace the destination if
112109
// it already exists. We try to emulate this on Windows, but this may
@@ -117,14 +114,11 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
117114
// AddBuffer a copy of the bytes we wrote in that case. We do this
118115
// instead of just using the existing file, because the pruner might
119116
// delete the file before we get a chance to use it.
120-
E = TempFile.keep(ObjectPathName);
117+
Error E = TempFile.keep(ObjectPathName);
121118
E = handleErrors(std::move(E), [&](const ECError &E) -> Error {
122119
std::error_code EC = E.convertToErrorCode();
123120
if (EC != errc::permission_denied)
124-
return createStringError(
125-
EC, Twine("Failed to rename temporary file ") +
126-
TempFile.TmpName + " to " + ObjectPathName + ": " +
127-
EC.message() + "\n");
121+
return errorCodeToError(EC);
128122

129123
auto MBCopy = MemoryBuffer::getMemBufferCopy((*MBOrErr)->getBuffer(),
130124
ObjectPathName);
@@ -137,10 +131,11 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
137131
});
138132

139133
if (E)
140-
return E;
134+
report_fatal_error(Twine("Failed to rename temporary file ") +
135+
TempFile.TmpName + " to " + ObjectPathName + ": " +
136+
toString(std::move(E)) + "\n");
141137

142138
AddBuffer(Task, ModuleName, std::move(*MBOrErr));
143-
return Error::success();
144139
}
145140
};
146141

llvm/tools/gold/gold-plugin.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,7 @@ static std::vector<std::pair<SmallString<128>, bool>> runLTO() {
11191119

11201120
auto AddBuffer = [&](size_t Task, const Twine &moduleName,
11211121
std::unique_ptr<MemoryBuffer> MB) {
1122-
auto Stream = *AddStream(Task, ModuleName);
1123-
Stream->OS << MB->getBuffer();
1124-
check(Stream->commit(), "Failed to commit cache");
1122+
*AddStream(Task, moduleName)->OS << MB->getBuffer();
11251123
};
11261124

11271125
FileCache Cache;

llvm/tools/llvm-lto2/llvm-lto2.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ static int run(int argc, char **argv) {
448448

449449
auto AddBuffer = [&](size_t Task, const Twine &ModuleName,
450450
std::unique_ptr<MemoryBuffer> MB) {
451-
auto Stream = AddStream(Task, ModuleName);
452-
*Stream->OS << MB->getBuffer();
453-
check(Stream->commit(), "Failed to commit cache");
451+
*AddStream(Task, ModuleName)->OS << MB->getBuffer();
454452
};
455453

456454
FileCache Cache;

llvm/unittests/Support/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ add_llvm_unittest(SupportTests
1818
BranchProbabilityTest.cpp
1919
CachePruningTest.cpp
2020
CrashRecoveryTest.cpp
21-
Caching.cpp
2221
Casting.cpp
2322
CheckedArithmeticTest.cpp
2423
Chrono.cpp

llvm/unittests/Support/Caching.cpp

-163
This file was deleted.

0 commit comments

Comments
 (0)