Skip to content

Commit c52de9a

Browse files
[CAS] Rename OnDiskTrieRawHashMap::pointer -> OnDiskPtr. NFC (#161548)
Rename the ondisk pointer type in OnDiskTrieRawHashMap to match OnDiskDataAllocator. NFC.
1 parent 134407d commit c52de9a

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
@@ -427,7 +427,7 @@ TrieRawHashMapHandle::createRecord(MappedFileRegionArena &Alloc,
427427
return Record;
428428
}
429429

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

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

459459
SubtrieHandle S = Trie.getRoot();
460460
if (!S)
461-
return const_pointer();
461+
return ConstOnDiskPtr();
462462

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

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

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

493-
Expected<OnDiskTrieRawHashMap::pointer>
493+
Expected<OnDiskTrieRawHashMap::OnDiskPtr>
494494
OnDiskTrieRawHashMap::insertLazy(ArrayRef<uint8_t> Hash,
495495
LazyInsertOnConstructCB OnConstruct,
496496
LazyInsertOnLeakCB OnLeak) {
@@ -523,7 +523,8 @@ OnDiskTrieRawHashMap::insertLazy(ArrayRef<uint8_t> Hash,
523523
}
524524

525525
if (S->compare_exchange_strong(Index, Existing, NewRecord->Offset))
526-
return pointer(NewRecord->Proxy, NewRecord->Offset.asDataFileOffset());
526+
return OnDiskPtr(NewRecord->Proxy,
527+
NewRecord->Offset.asDataFileOffset());
527528

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

547548
// 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)