LLVM 22.0.0git
BuiltinCAS.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_CAS_BUILTINCAS_H
10#define LLVM_LIB_CAS_BUILTINCAS_H
11
12#include "llvm/ADT/StringRef.h"
15
16namespace llvm::cas {
17class ActionCache;
18namespace ondisk {
20} // namespace ondisk
21namespace builtin {
22
23/// Common base class for builtin CAS implementations using the same CASContext.
24class BuiltinCAS : public ObjectStore {
25public:
26 BuiltinCAS() : ObjectStore(BuiltinCASContext::getDefaultContext()) {}
27
28 Expected<CASID> parseID(StringRef Reference) final;
29
31 ArrayRef<char> Data) final;
35
39 return storeImpl(ComputedHash, {}, ArrayRef(Map.data(), Map.size()));
40 }
41
42 /// Both builtin CAS implementations provide lifetime for free, so this can
43 /// be const, and readData() and getDataSize() can be implemented on top of
44 /// it.
46
48 bool RequiresNullTerminator) const final {
49 // BuiltinCAS Objects are always null terminated.
50 return getDataConst(Node);
51 }
53 return getDataConst(Node).size();
54 }
55
57 return createStringError(std::make_error_code(std::errc::invalid_argument),
58 "unknown object '" + ID.toString() + "'");
59 }
60
62 return createStringError(std::make_error_code(std::errc::invalid_argument),
63 "corrupt object '" + ID.toString() + "'");
64 }
65
67 return createStringError(std::make_error_code(std::errc::invalid_argument),
68 "corrupt storage");
69 }
70
71 Error validateObject(const CASID &ID) final;
72};
73
74/// Create a \p UnifiedOnDiskCache instance that uses \p BLAKE3 hashing.
77
78/// \param UniDB A \p UnifiedOnDiskCache instance from \p
79/// createBuiltinUnifiedOnDiskCache.
80std::unique_ptr<ObjectStore> createObjectStoreFromUnifiedOnDiskCache(
81 std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB);
82
83/// \param UniDB A \p UnifiedOnDiskCache instance from \p
84/// createBuiltinUnifiedOnDiskCache.
85std::unique_ptr<ActionCache> createActionCacheFromUnifiedOnDiskCache(
86 std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB);
87
88// FIXME: Proxy not portable. Maybe also error-prone?
89constexpr StringLiteral DefaultDirProxy = "/^llvm::cas::builtin::default";
90constexpr StringLiteral DefaultDir = "llvm.cas.builtin.default";
91
92} // end namespace builtin
93} // end namespace llvm::cas
94
95#endif // LLVM_LIB_CAS_BUILTINCAS_H
This file contains the declaration of the ObjectStore class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition ArrayRef.h:143
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:854
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A cache from a key (that describes an action) to the result of performing that action.
Definition ActionCache.h:49
Unique identifier for a CAS object.
Definition CASID.h:58
Handle to a loaded object in a ObjectStore instance.
ObjectStore(const CASContext &Context)
CASContext for LLVM builtin CAS using BLAKE3 hash type.
virtual Expected< ObjectRef > storeFromNullTerminatedRegion(ArrayRef< uint8_t > ComputedHash, sys::fs::mapped_file_region Map)
Definition BuiltinCAS.h:37
Error createUnknownObjectError(const CASID &ID) const
Definition BuiltinCAS.h:56
Error createCorruptStorageError() const
Definition BuiltinCAS.h:66
virtual ArrayRef< char > getDataConst(ObjectHandle Node) const =0
Both builtin CAS implementations provide lifetime for free, so this can be const, and readData() and ...
uint64_t getDataSize(ObjectHandle Node) const final
Get the size of some data.
Definition BuiltinCAS.h:52
Error validateObject(const CASID &ID) final
Validate the underlying object referred by CASID.
Expected< CASID > parseID(StringRef Reference) final
Get a CASID from a ID, which should have been generated by CASID::print().
Error createCorruptObjectError(const CASID &ID) const
Definition BuiltinCAS.h:61
Expected< ObjectRef > store(ArrayRef< ObjectRef > Refs, ArrayRef< char > Data) final
Store object into ObjectStore.
ArrayRef< char > getData(ObjectHandle Node, bool RequiresNullTerminator) const final
Definition BuiltinCAS.h:47
virtual Expected< ObjectRef > storeImpl(ArrayRef< uint8_t > ComputedHash, ArrayRef< ObjectRef > Refs, ArrayRef< char > Data)=0
A unified CAS nodes and key-value database, using on-disk storage for both.
This class represents a memory mapped file.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
constexpr StringLiteral DefaultDirProxy
Definition BuiltinCAS.h:89
std::unique_ptr< ObjectStore > createObjectStoreFromUnifiedOnDiskCache(std::shared_ptr< ondisk::UnifiedOnDiskCache > UniDB)
constexpr StringLiteral DefaultDir
Definition BuiltinCAS.h:90
std::unique_ptr< ActionCache > createActionCacheFromUnifiedOnDiskCache(std::shared_ptr< ondisk::UnifiedOnDiskCache > UniDB)
Expected< std::unique_ptr< ondisk::UnifiedOnDiskCache > > createBuiltinUnifiedOnDiskCache(StringRef Path)
Create a UnifiedOnDiskCache instance that uses BLAKE3 hashing.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
ArrayRef(const T &OneElt) -> ArrayRef< T >