The pitfall is that I have to give a concrete function… Hence the question: Can I construct a FunctionType with a given Input and a given Output Type without actually providing an implementation?
It should make the following work
Relying on return_type is not advised. It might very well change behavior or disappear in the future. FunctionWrappers is a very lightweight dependency. I bet there are people much better then I that can tell you the pitfalls of using return_type.
I actually kind of fall in love with this programmatic type inference. I know it sometimes does not work, but I am fine with that.
The idea it should be gone in the future (without proper replacement) sounds actually quite frightening. Wouldn’t this mean that also @code_warning macro couldn’t work?
Do you know a link to a discussion where I can read more about return_type and its future?
I was searching for it on slack, but it seems it has disappeared du to the 10k message limit I think the conclusions were that code relying on return_type would potentially break in the future due to compiler latency optimizations
return_type is used internally by the compiler to infer types with the intent to generate good machine code within a “reasonable” compilation time budget. Pasting some stuff I said over on slack:
return_type approximates the return type of a function. The amount of approximation is tuneable and it can be helpful to return a more approximate (“wider”) type to reduce the amount of unproductive work type inference does. So this may be changed in the future.
If you use return_type in a way which can affect the meaning of your program, the program may break when the compiler team adjusts the inference heuristics.
Basically, the compiler team reserves the right to adjust return_type to balance the precision of type inference against the compilation cost. Less compilation cost means faster “time to first plot”, etc, which is great for the interactive user experience.
By the way, I can’t imagine @code_warntype going away, but if it did I’m sure the compiler team would be replacing it with some other mechanism to give you insight into compilation.