LLVM 22.0.0git
BuiltinCAS.h
Go to the documentation of this file.
1//===- BuiltinCAS.h ---------------------------------------------*- C++ -*-===//
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 builtin {
19
20/// Common base class for builtin CAS implementations using the same CASContext.
21class BuiltinCAS : public ObjectStore {
22public:
23 BuiltinCAS() : ObjectStore(BuiltinCASContext::getDefaultContext()) {}
24
25 Expected<CASID> parseID(StringRef Reference) final;
26
28 ArrayRef<char> Data) final;
32
36 return storeImpl(ComputedHash, {}, ArrayRef(Map.data(), Map.size()));
37 }
38
39 /// Both builtin CAS implementations provide lifetime for free, so this can
40 /// be const, and readData() and getDataSize() can be implemented on top of
41 /// it.
43
45 bool RequiresNullTerminator) const final {
46 // BuiltinCAS Objects are always null terminated.
47 return getDataConst(Node);
48 }
50 return getDataConst(Node).size();
51 }
52
54 return createStringError(std::make_error_code(std::errc::invalid_argument),
55 "unknown object '" + ID.toString() + "'");
56 }
57
59 return createStringError(std::make_error_code(std::errc::invalid_argument),
60 "corrupt object '" + ID.toString() + "'");
61 }
62
64 return createStringError(std::make_error_code(std::errc::invalid_argument),
65 "corrupt storage");
66 }
67
68 Error validate(const CASID &ID) final;
69};
70
71} // end namespace builtin
72} // end namespace llvm::cas
73
74#endif // LLVM_LIB_CAS_BUILTINCAS_H
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:147
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
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Unique identifier for a CAS object.
Definition: CASID.h:58
Handle to a loaded object in a ObjectStore instance.
Definition: CASReference.h:150
Content-addressable storage for objects.
Definition: ObjectStore.h:85
CASContext for LLVM builtin CAS using BLAKE3 hash type.
Common base class for builtin CAS implementations using the same CASContext.
Definition: BuiltinCAS.h:21
virtual Expected< ObjectRef > storeFromNullTerminatedRegion(ArrayRef< uint8_t > ComputedHash, sys::fs::mapped_file_region Map)
Definition: BuiltinCAS.h:34
Error createUnknownObjectError(const CASID &ID) const
Definition: BuiltinCAS.h:53
Error createCorruptStorageError() const
Definition: BuiltinCAS.h:63
virtual ArrayRef< char > getDataConst(ObjectHandle Node) const =0
Both builtin CAS implementations provide lifetime for free, so this can be const, and readData() and ...
Error validate(const CASID &ID) final
Validate the underlying object referred by CASID.
Definition: BuiltinCAS.cpp:71
uint64_t getDataSize(ObjectHandle Node) const final
Get the size of some data.
Definition: BuiltinCAS.h:49
Expected< CASID > parseID(StringRef Reference) final
Get a CASID from a ID, which should have been generated by CASID::print().
Definition: BuiltinCAS.cpp:42
Error createCorruptObjectError(const CASID &ID) const
Definition: BuiltinCAS.h:58
Expected< ObjectRef > store(ArrayRef< ObjectRef > Refs, ArrayRef< char > Data) final
Store object into ObjectStore.
Definition: BuiltinCAS.cpp:65
ArrayRef< char > getData(ObjectHandle Node, bool RequiresNullTerminator) const final
Definition: BuiltinCAS.h:44
virtual Expected< ObjectRef > storeImpl(ArrayRef< uint8_t > ComputedHash, ArrayRef< ObjectRef > Refs, ArrayRef< char > Data)=0
This class represents a memory mapped file.
Definition: FileSystem.h:1287
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1305