Add lifetime comments to CanonicalValueStore and IdentifierStore (#8037)

Followup to https://github.com/carbon-language/carbon-lang/pull/8025.
It's easy to accidentally put a string into the `IdentifierStore` that
doesn't live long enough. Add some comments to document this pitfall.
This commit is contained in:
Nicholas Bishop authored and GitHub committed 2026-10-26 16:35:11 +00:00
1 parent c7de727575
commit e9d8d06f92
2 files changed
+6 -1

No files matched your search

+3 -1
View File
@@ -17,7 +17,9 @@ namespace Carbon {
// A wrapper for accumulating immutable values with deduplication, providing IDs
// to later retrieve the value.
//
// `ValueT` represents the type being stored.
// `ValueT` represents the type being stored. Be careful storing non-owned
// values (e.g. `llvm::StringRef`), as the store will not prevent the
// underlying data from being freed.
//
// `KeyT` can optionally be different from `ValueT`, and if so is used for the
// argument to `Lookup`. In this case, `ValueT` must provide a `GetAsKey` member
+3
View File
@@ -25,6 +25,9 @@ class SharedValueStores : public Yaml::Printable<SharedValueStores> {
using IntStore = IntStore;
using RealStore = ValueStore<RealId, Real>;
using FloatStore = CanonicalValueStore<FloatId, llvm::APFloat>;
// Note that this stores string references. The underlying string data must
// be stored somewhere more durable (e.g. a string literal or
// `clang::ASTContext::Idents`).
using IdentifierStore = CanonicalValueStore<IdentifierId, llvm::StringRef>;
using StringLiteralStore =
CanonicalValueStore<StringLiteralValueId, llvm::StringRef>;