Просмотр исходного кода

Add unit tagging to IdentifiedFacetTypeIds (#6267)

I don't /think/ these ids can appear in the raw SemIR dump, so this
change doesn't show up in any test updates - but it should still be
valuable for identifying bugs in the future.
David Blaikie 6 месяцев назад
Родитель
Сommit
c0879b2200
2 измененных файлов с 10 добавлено и 8 удалено
  1. 2 0
      toolchain/base/canonical_value_store.h
  2. 8 8
      toolchain/base/relational_value_store.h

+ 2 - 0
toolchain/base/canonical_value_store.h

@@ -71,6 +71,8 @@ class CanonicalValueStore {
 
   auto GetRawIndex(IdT id) const -> int32_t { return values_.GetRawIndex(id); }
 
+  auto GetIdTag() const -> IdTag { return values_.GetIdTag(); }
+
  private:
   class KeyContext;
 

+ 8 - 8
toolchain/base/relational_value_store.h

@@ -46,15 +46,14 @@ class RelationalValueStore {
   // to reference it in the store.
   auto Add(RelatedIdType related_id, ValueType value) -> IdT {
     auto related_index = related_store_->GetRawIndex(related_id);
-    IdT id(related_index);
-    if (static_cast<size_t>(id.index) >= values_.size()) {
-      values_.resize(id.index + 1);
+    if (static_cast<size_t>(related_index) >= values_.size()) {
+      values_.resize(related_index + 1);
     }
-    auto& opt = values_[id.index];
+    auto& opt = values_[related_index];
     CARBON_CHECK(!opt.has_value(),
                  "Add with `related_id` that was already added to the store");
     opt.emplace(std::move(value));
-    return id;
+    return IdT(related_store_->GetIdTag().Apply(related_index));
   }
 
   // Returns the ID of a value in the store if the `related_id` was previously
@@ -68,13 +67,14 @@ class RelationalValueStore {
     if (!opt.has_value()) {
       return IdT::None;
     }
-    return IdT(related_index);
+    return IdT(related_store_->GetIdTag().Apply(related_index));
   }
 
   // Returns a value for an ID.
   auto Get(IdT id) const -> ConstRefType {
-    CARBON_DCHECK(id.index >= 0, "{0}", id);
-    return *values_[id.index];
+    auto index = related_store_->GetIdTag().Remove(id.index);
+    CARBON_DCHECK(index >= 0, "{0}", id);
+    return *values_[index];
   }
 
  private: