coreblocks icon indicating copy to clipboard operation
coreblocks copied to clipboard

Better transformer API

Open tilk opened this issue 8 months ago • 1 comments

This PR utilizes def_helper mechanisms to create a nicer API for using transformers. Following changes in interpreting the function arguments of the transformer classes are made:

  • The module parameter is now optional.
  • Instead of taking a record of method inputs (arg) the functions can take individual record fields, just like methods defined via def_method.

Also, specializations of def_helper were moved closer to their use sites, so that the dependencies on types would resolve correctly. If someone has a better idea, I'd like to hear it.

To do:

  • [x] Update docstrings.

tilk avatar Oct 25 '23 14:10 tilk

But we are loosing consistency.

I think we are actually gaining consistency, as:

  • Keyword arguments allows to define functions just like method definitions.
  • The filter function can now be defined consistently with your validate_arguments feature. The validating function cannot get a TModule argument, because it's called outside of the transactional circuit (in the transaction scheduler).

Also:

  • The TModule argument was basically a hack to allow the use of methods as functions. I expect this argument will not be needed in most use cases.
  • The presence or lack of the TModule argument actually signals something meaningful: it says that the function can do method calls in the context of the transformer. (There is unfortunately no way to guarantee "purity", as a function might use an external TModule to do some stuff. I sure hope this use will be avoided though.)

tilk avatar Oct 29 '23 10:10 tilk