logoalt Hacker News

vbezhenarlast Thursday at 9:47 PM3 repliesview on HN

Is it possible to generate less junk? Sounds like compiler developers took a shortcuts, which could be improved over time.


Replies

LtdJorgeyesterday at 8:16 AM

Well, zero-cost abstractions are still abstractions. It’s not junk per-se, but things that will be optimized out if the IR has enough information to safely do so, so basically lots of extra metadata to actually prove to LLVM that these things are safe.

zozbot234last Thursday at 10:29 PM

You can address the junk problem manually by having generic functions delegate as much of their work as possible to non-generic or "less" generic functions (Where a "less" generic function is one that depends only on a known subset of type traits, such as size or alignment. Then delegating can help the compiler generate fewer redundant copies of your code, even if it can't avoid code monomorphization altogether.)

show 1 reply
rcxdudelast Thursday at 10:13 PM

Probably, but it's the kind of thing that needs a lot of fairly significant overhauls in the compiler architecture to really move the needle on, as far as I understand.