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).
There's a juicy bug lurking here: if you don't insert into a region for this op (e.g., either func or module) you will get an assert fail at the end of the script:
If you dump the op after creation you get
So the op is built successfully and "uses" c0 but the bindings aren't aware (I guess liveOperations is skipping a beat somehow). Note, <<UNKNOWN SSA VALUE>> is because there's no enclosing region, not because it's actually a null SSA value (I should've made that print <<UNATTACHED SSA VALUE>>...)