Rethinking constructors #234
georgebisbas
started this conversation in
Ideas
Replies: 1 comment 1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
One of the things I do not like is that you call different constructors depending on the args you want to use...
Think of this:
method a:
const_op = Constant.create([], [i64], attributes={"value": IntegerAttr.from_int_and_width(62, 64)})
method b:
const_op2 = Constant.from_attr(IntegerAttr.from_int_and_width(62, 64), i64)
...
in an ideal world you should only have:
const_a = Constant(62, i64)
Michel Weber
IMO, these are different things in terms of layers of abstraction. The create version only uses the ir.py files, so it is a very bare-bone way of creating a new operation. The build method goes through the irdl file, so it for example relies on the fields you give an operation (provided you have given it the irdl_op_definiton decorator). Lastly, from_attr are the builders we implement in the dialect files themselves. These are supposed to be something that a users can think about and define themselves. So, IMO, if you want Constant(62, i64) you should probably override init within the Constant operation ddefiniton in arith.py (edited)
Overall, all these things grew during development. Nice to see you asking the right questions in order to rethink/restructure ur design!
If you ask me, I think we could replace the create method by an override of init (assuming that I am not forgetting something crucial, that
[@mathieu Fehr]
knows about).
Beta Was this translation helpful? Give feedback.
All reactions