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

Krzysztof Drewniak llvmlistbot at llvm.org
Sat Mar 14 23:13:01 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; }
   template <typename Dest>
   Dest as() const {
-    return static_cast<Dest>(const_cast<void *>(properties));
+    static_assert(std::is_pointer_v<Dest>,
+                  "PropertyRef::as<T>() requires T to be a pointer type");
+    using RawType = std::remove_cv_t<std::remove_pointer_t<Dest>>;
+    assert((!data || typeID == TypeID::get<RawType>()) &&
----------------
krzysz00 wrote:

Doesn't look like it's needed and I don't have a good argument for why it's allowed, so removed.

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


More information about the Mlir-commits mailing list