Skip to content

Commit 63640c0

Browse files
committed
simplify
Created using spr 1.3.4
2 parents 8267e8c + 3a0d0c6 commit 63640c0

File tree

24 files changed

+268
-339
lines changed

24 files changed

+268
-339
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Implemented Papers
4141
- N4258: Cleaning-up noexcept in the Library (`Github <https://github.com/llvm/llvm-project/issues/99937>`__)
4242
- P0767R1: Deprecate POD (`Github <https://github.com/llvm/llvm-project/issues/104013>`__)
4343
- P1361R2: Integration of chrono with text formatting (`Github <https://github.com/llvm/llvm-project/issues/100014>`__)
44-
- P2255R2: A type trait to detect reference binding to temporary (implemented the type traits only) (`Github <https://github.com/llvm/llvm-project/issues/105180>`)
44+
- P2255R2: A type trait to detect reference binding to temporary (implemented the type traits only) (`Github <https://github.com/llvm/llvm-project/issues/105180>`__)
4545

4646
Improvements and New Features
4747
-----------------------------

lldb/source/Core/DataFileCache.cpp

Lines changed: 0 additions & 5 deletions
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/IR/ModuleSummaryIndex.h

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,66 +1311,17 @@ class CfiFunctionIndex {
13111311
GlobalValue::GUID operator*() const { return this->wrapped()->first; }
13121312
};
13131313

1314-
// Iterates merged values of the DenseMap.
1315-
class SymbolIterator
1316-
: public iterator_facade_base<SymbolIterator, std::forward_iterator_tag,
1317-
std::string> {
1318-
using base = SymbolIterator::iterator_facade_base;
1319-
1320-
IndexIterator Outer;
1321-
IndexIterator OuterEnd;
1322-
NestedIterator Inner;
1323-
1324-
public:
1325-
SymbolIterator() = default;
1326-
SymbolIterator(IndexIterator Outer, IndexIterator OuterEnd)
1327-
: Outer(Outer), OuterEnd(OuterEnd),
1328-
Inner(Outer != OuterEnd ? Outer->second.begin() : NestedIterator{}) {}
1329-
SymbolIterator(SymbolIterator &R) = default;
1330-
1331-
const std::string &operator*() const { return *Inner; }
1332-
1333-
SymbolIterator &operator++() {
1334-
// `DenseMap` never contains empty sets. So:
1335-
// 1. `Outer` points to non-empty set, if `Outer` != `OuterEnd`.
1336-
// 2. `Inner` always is valid and dereferenceable, if `Outer` !=
1337-
// `OuterEnd`.
1338-
assert(Outer != OuterEnd);
1339-
assert(!Outer->second.empty());
1340-
++Inner;
1341-
if (Inner == Outer->second.end()) {
1342-
++Outer;
1343-
Inner = Outer != OuterEnd ? Outer->second.begin() : NestedIterator{};
1344-
}
1345-
return *this;
1346-
}
1347-
1348-
SymbolIterator &operator=(const SymbolIterator &R) {
1349-
if (this != &R) {
1350-
Outer = R.Outer;
1351-
OuterEnd = R.OuterEnd;
1352-
Inner = R.Inner;
1353-
}
1354-
return *this;
1355-
}
1356-
1357-
bool operator==(const SymbolIterator &R) const {
1358-
return Outer == R.Outer && Inner == R.Inner;
1359-
}
1360-
};
1361-
13621314
CfiFunctionIndex() = default;
13631315
template <typename It> CfiFunctionIndex(It B, It E) {
13641316
for (; B != E; ++B)
13651317
emplace(*B);
13661318
}
13671319

1368-
SymbolIterator begin() const {
1369-
return SymbolIterator(Index.begin(), Index.end());
1370-
}
1371-
1372-
SymbolIterator end() const {
1373-
return SymbolIterator(Index.end(), Index.end());
1320+
std::vector<StringRef> symbols() const {
1321+
std::vector<StringRef> Symbols;
1322+
for (auto &[GUID, Syms] : Index)
1323+
Symbols.insert(Symbols.end(), Syms.begin(), Syms.end());
1324+
return Symbols;
13741325
}
13751326

13761327
GUIDIterator guid_begin() const { return GUIDIterator(Index.begin()); }

llvm/include/llvm/IR/ModuleSummaryIndexYAML.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@ template <> struct MappingTraits<ModuleSummaryIndex> {
349349
if (io.outputting()) {
350350
std::vector<StringRef> CfiFunctionDefs(index.CfiFunctionDefs.begin(),
351351
index.CfiFunctionDefs.end());
352-
std::sort(CfiFunctionDefs.begin(), CfiFunctionDefs.end());
352+
llvm::sort(CfiFunctionDefs);
353353
io.mapOptional("CfiFunctionDefs", CfiFunctionDefs);
354354
std::vector<StringRef> CfiFunctionDecls(index.CfiFunctionDecls.begin(),
355355
index.CfiFunctionDecls.end());
356-
std::sort(CfiFunctionDecls.begin(), CfiFunctionDecls.end());
356+
llvm::sort(CfiFunctionDecls);
357357
io.mapOptional("CfiFunctionDecls", CfiFunctionDecls);
358358
} else {
359359
std::vector<std::string> CfiFunctionDefs;

llvm/include/llvm/Support/Caching.h

Lines changed: 2 additions & 19 deletions
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/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5070,7 +5070,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
50705070
Functions.insert(Functions.end(), Defs.begin(), Defs.end());
50715071
}
50725072
if (!Functions.empty()) {
5073-
std::sort(Functions.begin(), Functions.end());
5073+
llvm::sort(Functions);
50745074
for (const auto &S : Functions) {
50755075
NameVals.push_back(StrtabBuilder.add(S));
50765076
NameVals.push_back(S.size());
@@ -5085,7 +5085,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
50855085
Functions.insert(Functions.end(), Decls.begin(), Decls.end());
50865086
}
50875087
if (!Functions.empty()) {
5088-
std::sort(Functions.begin(), Functions.end());
5088+
llvm::sort(Functions);
50895089
for (const auto &S : Functions) {
50905090
NameVals.push_back(StrtabBuilder.add(S));
50915091
NameVals.push_back(S.size());

llvm/lib/CGData/CodeGenData.cpp

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 13 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 12 additions & 17 deletions
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

0 commit comments

Comments
 (0)