Skip to content

Commit 3c26b8c

Browse files
[𝘀𝗽𝗿] initial version
Created using spr 1.3.7
1 parent 0c1e7cc commit 3c26b8c

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

llvm/include/llvm/CAS/OnDiskTrieRawHashMap.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,38 +133,38 @@ class OnDiskTrieRawHashMap {
133133
bool IsValue = false;
134134
};
135135

136-
class pointer;
137-
class const_pointer : public PointerImpl<ConstValueProxy> {
136+
class OnDiskPtr;
137+
class ConstOnDiskPtr : public PointerImpl<ConstValueProxy> {
138138
public:
139-
const_pointer() = default;
139+
ConstOnDiskPtr() = default;
140140

141141
private:
142-
friend class pointer;
142+
friend class OnDiskPtr;
143143
friend class OnDiskTrieRawHashMap;
144-
using const_pointer::PointerImpl::PointerImpl;
144+
using ConstOnDiskPtr::PointerImpl::PointerImpl;
145145
};
146146

147-
class pointer : public PointerImpl<ValueProxy> {
147+
class OnDiskPtr : public PointerImpl<ValueProxy> {
148148
public:
149-
operator const_pointer() const {
150-
return const_pointer(Value, getOffset(), IsValue);
149+
operator ConstOnDiskPtr() const {
150+
return ConstOnDiskPtr(Value, getOffset(), IsValue);
151151
}
152152

153-
pointer() = default;
153+
OnDiskPtr() = default;
154154

155155
private:
156156
friend class OnDiskTrieRawHashMap;
157-
using pointer::PointerImpl::PointerImpl;
157+
using OnDiskPtr::PointerImpl::PointerImpl;
158158
};
159159

160160
/// Find the value from hash.
161161
///
162162
/// \returns pointer to the value if exists, otherwise returns a non-value
163163
/// pointer that evaluates to `false` when convert to boolean.
164-
const_pointer find(ArrayRef<uint8_t> Hash) const;
164+
ConstOnDiskPtr find(ArrayRef<uint8_t> Hash) const;
165165

166166
/// Helper function to recover a pointer into the trie from file offset.
167-
Expected<const_pointer> recoverFromFileOffset(FileOffset Offset) const;
167+
Expected<ConstOnDiskPtr> recoverFromFileOffset(FileOffset Offset) const;
168168

169169
using LazyInsertOnConstructCB =
170170
function_ref<void(FileOffset TentativeOffset, ValueProxy TentativeValue)>;
@@ -186,11 +186,11 @@ class OnDiskTrieRawHashMap {
186186
/// The in-memory \a TrieRawHashMap uses LazyAtomicPointer to synchronize
187187
/// simultaneous writes, but that seems dangerous to use in a memory-mapped
188188
/// file in case a process crashes in the busy state.
189-
Expected<pointer> insertLazy(ArrayRef<uint8_t> Hash,
190-
LazyInsertOnConstructCB OnConstruct = nullptr,
191-
LazyInsertOnLeakCB OnLeak = nullptr);
189+
Expected<OnDiskPtr> insertLazy(ArrayRef<uint8_t> Hash,
190+
LazyInsertOnConstructCB OnConstruct = nullptr,
191+
LazyInsertOnLeakCB OnLeak = nullptr);
192192

193-
Expected<pointer> insert(const ConstValueProxy &Value) {
193+
Expected<OnDiskPtr> insert(const ConstValueProxy &Value) {
194194
return insertLazy(Value.Hash, [&](FileOffset, ValueProxy Allocated) {
195195
assert(Allocated.Hash == Value.Hash);
196196
assert(Allocated.Data.size() == Value.Data.size());

llvm/lib/CAS/OnDiskTrieRawHashMap.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ TrieRawHashMapHandle::createRecord(MappedFileRegionArena &Alloc,
426426
return Record;
427427
}
428428

429-
Expected<OnDiskTrieRawHashMap::const_pointer>
429+
Expected<OnDiskTrieRawHashMap::ConstOnDiskPtr>
430430
OnDiskTrieRawHashMap::recoverFromFileOffset(FileOffset Offset) const {
431431
// Check alignment.
432432
if (!isAligned(MappedFileRegionArena::getAlign(), Offset.get()))
@@ -447,31 +447,31 @@ OnDiskTrieRawHashMap::recoverFromFileOffset(FileOffset Offset) const {
447447
// Looks okay...
448448
TrieRawHashMapHandle::RecordData D =
449449
Impl->Trie.getRecord(SubtrieSlotValue::getDataOffset(Offset));
450-
return const_pointer(D.Proxy, D.getFileOffset());
450+
return ConstOnDiskPtr(D.Proxy, D.getFileOffset());
451451
}
452452

453-
OnDiskTrieRawHashMap::const_pointer
453+
OnDiskTrieRawHashMap::ConstOnDiskPtr
454454
OnDiskTrieRawHashMap::find(ArrayRef<uint8_t> Hash) const {
455455
TrieRawHashMapHandle Trie = Impl->Trie;
456456
assert(Hash.size() == Trie.getNumHashBytes() && "Invalid hash");
457457

458458
SubtrieHandle S = Trie.getRoot();
459459
if (!S)
460-
return const_pointer();
460+
return ConstOnDiskPtr();
461461

462462
TrieHashIndexGenerator IndexGen = Trie.getIndexGen(S, Hash);
463463
size_t Index = IndexGen.next();
464464
for (;;) {
465465
// Try to set the content.
466466
SubtrieSlotValue V = S.load(Index);
467467
if (!V)
468-
return const_pointer();
468+
return ConstOnDiskPtr();
469469

470470
// Check for an exact match.
471471
if (V.isData()) {
472472
TrieRawHashMapHandle::RecordData D = Trie.getRecord(V);
473-
return D.Proxy.Hash == Hash ? const_pointer(D.Proxy, D.getFileOffset())
474-
: const_pointer();
473+
return D.Proxy.Hash == Hash ? ConstOnDiskPtr(D.Proxy, D.getFileOffset())
474+
: ConstOnDiskPtr();
475475
}
476476

477477
Index = IndexGen.next();
@@ -489,7 +489,7 @@ void SubtrieHandle::reinitialize(uint32_t StartBit, uint32_t NumBits) {
489489
H->NumBits = NumBits;
490490
}
491491

492-
Expected<OnDiskTrieRawHashMap::pointer>
492+
Expected<OnDiskTrieRawHashMap::OnDiskPtr>
493493
OnDiskTrieRawHashMap::insertLazy(ArrayRef<uint8_t> Hash,
494494
LazyInsertOnConstructCB OnConstruct,
495495
LazyInsertOnLeakCB OnLeak) {
@@ -522,7 +522,8 @@ OnDiskTrieRawHashMap::insertLazy(ArrayRef<uint8_t> Hash,
522522
}
523523

524524
if (S->compare_exchange_strong(Index, Existing, NewRecord->Offset))
525-
return pointer(NewRecord->Proxy, NewRecord->Offset.asDataFileOffset());
525+
return OnDiskPtr(NewRecord->Proxy,
526+
NewRecord->Offset.asDataFileOffset());
526527

527528
// Race means that Existing is no longer empty; fall through...
528529
}
@@ -539,8 +540,8 @@ OnDiskTrieRawHashMap::insertLazy(ArrayRef<uint8_t> Hash,
539540
if (NewRecord && OnLeak)
540541
OnLeak(NewRecord->Offset.asDataFileOffset(), NewRecord->Proxy,
541542
ExistingRecord.Offset.asDataFileOffset(), ExistingRecord.Proxy);
542-
return pointer(ExistingRecord.Proxy,
543-
ExistingRecord.Offset.asDataFileOffset());
543+
return OnDiskPtr(ExistingRecord.Proxy,
544+
ExistingRecord.Offset.asDataFileOffset());
544545
}
545546

546547
// Sink the existing content as long as the indexes match.

llvm/unittests/CAS/OnDiskTrieRawHashMapTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ TEST_P(OnDiskTrieRawHashMapTestFixture, General) {
7171
std::optional<FileOffset> Offset;
7272
std::optional<MutableArrayRef<char>> Data;
7373
{
74-
std::optional<OnDiskTrieRawHashMap::pointer> Insertion;
74+
std::optional<OnDiskTrieRawHashMap::OnDiskPtr> Insertion;
7575
ASSERT_THAT_ERROR(Trie1->insert({Hash0, Data0v1}).moveInto(Insertion),
7676
Succeeded());
7777
EXPECT_EQ(Hash0, (*Insertion)->Hash);
@@ -128,7 +128,7 @@ TEST_P(OnDiskTrieRawHashMapTestFixture, General) {
128128

129129
// Recover from an offset.
130130
{
131-
OnDiskTrieRawHashMap::const_pointer Recovered;
131+
OnDiskTrieRawHashMap::ConstOnDiskPtr Recovered;
132132
ASSERT_THAT_ERROR(Trie1->recoverFromFileOffset(*Offset).moveInto(Recovered),
133133
Succeeded());
134134
ASSERT_TRUE(Recovered);
@@ -140,14 +140,14 @@ TEST_P(OnDiskTrieRawHashMapTestFixture, General) {
140140
// Recover from a bad offset.
141141
{
142142
FileOffset BadOffset(1);
143-
OnDiskTrieRawHashMap::const_pointer Recovered;
143+
OnDiskTrieRawHashMap::ConstOnDiskPtr Recovered;
144144
ASSERT_THAT_ERROR(
145145
Trie1->recoverFromFileOffset(BadOffset).moveInto(Recovered), Failed());
146146
}
147147

148148
// Insert another thing.
149149
{
150-
std::optional<OnDiskTrieRawHashMap::pointer> Insertion;
150+
std::optional<OnDiskTrieRawHashMap::OnDiskPtr> Insertion;
151151
ASSERT_THAT_ERROR(Trie1->insert({Hash1, Data1}).moveInto(Insertion),
152152
Succeeded());
153153
EXPECT_EQ(Hash1, (*Insertion)->Hash);
@@ -210,7 +210,7 @@ TEST(OnDiskTrieRawHashMapTest, OutOfSpace) {
210210
auto Hash0 = ArrayRef(Hash0Bytes);
211211
constexpr StringLiteral Data0v1Bytes = "data0.v1";
212212
ArrayRef<char> Data0v1 = ArrayRef(Data0v1Bytes.data(), Data0v1Bytes.size());
213-
std::optional<OnDiskTrieRawHashMap::pointer> Insertion;
213+
std::optional<OnDiskTrieRawHashMap::OnDiskPtr> Insertion;
214214
ASSERT_THAT_ERROR(Trie->insert({Hash0, Data0v1}).moveInto(Insertion),
215215
Failed());
216216
}

0 commit comments

Comments
 (0)