coreblocks
coreblocks copied to clipboard
Better transformer API
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 viadef_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.
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 aTModule
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 externalTModule
to do some stuff. I sure hope this use will be avoided though.)