[Mlir-commits] [mlir] [mlir] Refactor opaque properties to make them type-safe (PR #185157)

Fabian Mora llvmlistbot at llvm.org
Sat Mar 21 04:00:56 PDT 2026


================
@@ -63,22 +63,34 @@ template <typename ValueRangeT>
 class ValueTypeRange;
 
 //===----------------------------------------------------------------------===//
-// OpaqueProperties
+// PropertyRef
 //===----------------------------------------------------------------------===//
 
-/// Simple wrapper around a void* in order to express generically how to pass
-/// in op properties through APIs.
-class OpaqueProperties {
+/// Type-safe wrapper around a void* for passing properties, including the
+/// properties structs of operations, generically through APIs. Pairs data with
+/// a TypeID for assert-based type checking. Note that the type in the type ID
+/// is the **storage** type of the property, and that the default object has a
+/// null data pointer and a type ID equal to the type ID for `void`.
+class PropertyRef {
 public:
-  OpaqueProperties(void *prop) : properties(prop) {}
-  operator bool() const { return properties != nullptr; }
+  PropertyRef() = default;
+  PropertyRef(std::nullptr_t) {}
+  PropertyRef(TypeID typeID, void *data) : typeID(typeID), data(data) {}
+  operator bool() const { return data != nullptr; }
----------------
fabianmcg wrote:

Let's not have a void constructor, the premise of `PropRef` should include type safe construction.
Also, the `nullptr_t` constructor seems redundant given that we have the default constructor.

```suggestion
  PropertyRef() = default;
  template <typename PropTy>
  PropertyRef(PropTy& props) : typeID(TypeID::get<PropTy>()), data(&props) {}
```

https://github.com/llvm/llvm-project/pull/185157


More information about the Mlir-commits mailing list