The problem here is that TypesMatchWith doesn’t allow the predicate to fail. I hacked this a bit by having the transform function return a null type, which causes a static error, but this isn’t really right. Is there a better way to get a nice error message out? You can see a testcase at the bottom of the patch.
One other random question for @jdd: the generated InOutType::get() creation method is synthesized with both a context argument as well as an element type. Is it possible to teach tblgen to know that the context can always be obtained from the element type with element.getContext(), eliminating the need for the context argument?
In the general case, no. Non-parameterized types and types with only primitive parameters don’t get passed anything which has a .getContext() method. It would be possible to detect the conditions under which the context can be omitted, though the ODS code currently doesn’t look at the type string and adding that functionality would add significant complexity. I also appreciate the consistency.
I’d appreciate handling the case when there are subtypes that get passed in, since that is something that is already known by the pattern and is extremely common. While consistency can sometimes be helpful, in this case it is just boilerplate which requires me to find a way to specify a custom builder/get.
If I need to specify a custom get method, how do I do that?
The way to do this is to ensure that the argument/result types are properly constrained in ODS. The LHS side of TypesMatchWith is verified before it is used in the autogenerated parser, so if you’ve properly constrained the LHS it shouldn’t be possible for it to fail. It seems that in your patch, you still have the input/result type marked as AnyType. If you move isRTLValueType to a TypeConstraint and attach it to result, you should get proper errors/no crashes.
I agree here that this is a somewhat common use case. I plan to try moving over the builtin types to ODS soonish, which means that these types of things will need to be addressed as those types get moved over.