abandoned in favor of D150927
This diff adds casting of MlirType to an instance of PyConcreteType<> (when possible) for returns from cpp. Note, only returns. Such casting greatly improves the APIs as the user then doesn't need to cast/wrap in Python. For example VectorType(Type.parse("vector<2x3xf32>")) becomes just Type.parse("vector<2x3xf32>").
More importantly, PyValue.type now returns a concrete type (when possible); e.g.,
cst = arith.ConstantOp(F32Type.get(), 0.0).result print(type(cst.type).__name__) print(repr(cst.type))
prints
F32Type F32Type(f32)
Attributes as well:
attr = DenseElementsAttr(Attribute.parse("dense<123> : tensor<i16>")) print(repr(attr.type)) print(repr(attr.type.element_type))
prints
RankedTensorType(tensor<i16>) IntegerType(i16)
This paves the way for writing code (both cpp and Python) that is "type conscious" (see this draft).
One current limitation is that mlir_type_subclass can't participate but I think I can make that work too (in a follow-up diff).
I think we'd really want something that works for downstream types too. Have you looked at how the opview downcasting works? There's an op name -> python class mapping maintained, and I imagine that could be generalized to a typeid -> python class map to work with attributes and types as well.