Skip to content

Commit bd8b02e

Browse files
committed
Document lifetimes of StringRef
1 parent 17c9aa7 commit bd8b02e

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

mlir/include/mlir/IR/AttributeSupport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class AbstractAttribute {
150150
/// The unique identifier of the derived Attribute class.
151151
const TypeID typeID;
152152

153-
/// The unique name of this type.
153+
/// The unique name of this attribute. The string is not owned by the context,
154+
/// so the lifetime of this string should outlive the MLIR context.
154155
const StringRef name;
155156
};
156157

mlir/include/mlir/IR/TypeSupport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class AbstractType {
149149
/// The unique identifier of the derived Type class.
150150
const TypeID typeID;
151151

152-
/// The unique name of this type.
152+
/// The unique name of this type. The string is not owned by the context, so
153+
/// The lifetime of this string should outlive the MLIR context.
153154
const StringRef name;
154155
};
155156

mlir/lib/IR/MLIRContext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ class MLIRContextImpl {
215215
/// This is a mapping from type name to the abstract type describing it.
216216
/// It is used by `AbstractType::lookup` to get an `AbstractType` from a name.
217217
/// As this map needs to be populated before `StringAttr` is loaded, we
218-
/// cannot use `StringAttr` as the key.
218+
/// cannot use `StringAttr` as the key. The context does not take ownership
219+
/// of the key, so the `StringRef` must outlive the context.
219220
llvm::DenseMap<StringRef, AbstractType *> nameToType;
220221

221222
/// Cached Type Instances.
@@ -246,7 +247,8 @@ class MLIRContextImpl {
246247
/// it. It is used by `AbstractType::lookup` to get an `AbstractType` from a
247248
/// name.
248249
/// As this map needs to be populated before `StringAttr` is loaded, we
249-
/// cannot use `StringAttr` as the key.
250+
/// cannot use `StringAttr` as the key. The context does not take ownership
251+
/// of the key, so the `StringRef` must outlive the context.
250252
llvm::DenseMap<StringRef, AbstractAttribute *> nameToAttribute;
251253

252254
/// Cached Attribute Instances.

0 commit comments

Comments
 (0)