Open simeonschaub opened 3 years ago
This was probably to reduce the number of closures and make it easier on the compiler. Otherwise it has to re-analyze a significant amount of code for each comprehension.
Would you say that is something that's still as relevant nowadays, or would the additional consistency and extendability be worth it? A much more speculative proposal would be to lower comprehensions to opaque closures, since IIUC they would avoid recompiling the same code over and over again, but not sure if the slight semantic differences might lead to some odd edge cases.
It's probably still relevant now. If we still wanted everything inlined, I'm not sure opaque closures would be much better.
Here is an example where it seems relevant https://github.com/JuliaLang/julia/issues/40302#issuecomment-812525555
return_type
calculation, if I read that correctly. Since that shouldn't get called in the typed case, that might not be affected by this change.
Is there any reason we implement pretty much the whole functionality for typed comprehensions in lowering? Compare:
to the way untyped comprehensions are lowered:
This makes this syntax hard to extend for other array types and also prevents AD from making use of higher-level adjoints here. Is there a reason we do it this way or is it just historical baggage? Otherwise, I would propose lowering this just like untyped comprehensions, but using
collect(Int, %2)
, which is what I initially expected this to do.