Skip to content

Commit 4fdc085

Browse files
authored
Add ValueStore ctor template for Id to use for IdTag (#6226)
Based on review feedback on #6215 (comment) There are some intermediate commits with alternatives, finding other ways (non-templates) to address the layering boundaries between `ValueStore` construction and `CheckIRId` tagging. But, yeah, template seems like the way to go - certainly in terms of terseness and probably in terms of extensibility to other Id tagging as/when needed.
1 parent c7646b7 commit 4fdc085

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

toolchain/base/canonical_value_store.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class CanonicalValueStore {
3737
using ConstRefType = ValueStoreTypes<ValueT>::ConstRefType;
3838

3939
CanonicalValueStore() = default;
40-
explicit CanonicalValueStore(IdTag tag) : values_(tag) {}
40+
template <typename Id>
41+
explicit CanonicalValueStore(Id id, int32_t initial_reserved_ids = 0)
42+
: values_(id, initial_reserved_ids) {}
4143

4244
// Stores a canonical copy of the value and returns an ID to reference it. If
4345
// the value is already in the store, returns the ID of the existing value.

toolchain/base/value_store.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class ValueStore
177177

178178
ValueStore() = default;
179179
explicit ValueStore(IdTag tag) : tag_(tag) {}
180+
template <typename Id>
181+
explicit ValueStore(Id id, int32_t initial_reserved_ids = 0)
182+
: tag_(id.index, initial_reserved_ids) {}
180183

181184
// Stores the value and returns an ID to reference it.
182185
auto Add(ValueType value) -> IdType {

toolchain/sem_ir/file.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ File::File(const Parse::Tree* parse_tree, CheckIRId check_ir_id,
3535
: LibraryNameId::Default),
3636
value_stores_(&value_stores),
3737
filename_(std::move(filename)),
38-
functions_(IdTag(check_ir_id.index, 0)),
39-
cpp_overload_sets_(IdTag(check_ir_id.index, 0)),
40-
classes_(IdTag(check_ir_id.index, 0)),
41-
associated_constants_(IdTag(check_ir_id.index, 0)),
38+
functions_(check_ir_id),
39+
cpp_overload_sets_(check_ir_id),
40+
classes_(check_ir_id),
41+
associated_constants_(check_ir_id),
4242
impls_(*this),
43-
specific_interfaces_(IdTag(check_ir_id.index, 0)),
43+
specific_interfaces_(check_ir_id_),
4444
// The `+1` prevents adding a tag to the global `NameSpace::PackageInstId`
4545
// instruction. It's not a "singleton" instruction, but it's a unique
4646
// instruction id that comes right after the singletons.

toolchain/sem_ir/impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Carbon::SemIR {
1010

1111
ImplStore::ImplStore(File& sem_ir)
12-
: sem_ir_(sem_ir), values_(IdTag(sem_ir.check_ir_id().index, 0)) {}
12+
: sem_ir_(sem_ir), values_(sem_ir.check_ir_id()) {}
1313

1414
auto ImplStore::GetOrAddLookupBucket(const Impl& impl) -> LookupBucketRef {
1515
auto self_id = sem_ir_.constant_values().GetConstantInstId(impl.self_id);

toolchain/sem_ir/inst.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ const std::pair<IdKind, IdKind> Inst::ArgKindTable[] = {
5555
};
5656

5757
InstStore::InstStore(File* file, int32_t reserved_inst_ids)
58-
: file_(file),
59-
values_(IdTag(file->check_ir_id().index, reserved_inst_ids)) {}
58+
: file_(file), values_(file->check_ir_id(), reserved_inst_ids) {}
6059

6160
auto InstStore::GetUnattachedType(TypeId type_id) const -> TypeId {
6261
return file_->types().GetUnattachedType(type_id);

0 commit comments

Comments
 (0)