logoalt Hacker News

SkiFire13yesterday at 6:00 AM1 replyview on HN

> To me compilers should be content-addressed databases

Rustc already does something like this. The issues are:

- when you have to rehash everything to check that they indeed didn't change from the previous compilation. For big projects this takes _a lot_ of time.

- when small changes do indeed change the hash of a lot of seemingly unrelated code, which is more common than you might think.


Replies

tancopyesterday at 9:49 AM

You dont need to rehash everything if you do multi level hashing (file -> mod/impl block -> function). The expensive part is doing lots of hash passes over small parts of a file, so if you break as early as possible the moment you can guarantee that part is unchanged you save a lot of time. And if you assume (and document) that libraries need to be rebuilt manually you can completely skip checking them.

OP handles the small change problem by hashing IR instead of source text. If the new function compiles to the same IR as the old one its guaranteed to give the same machine code. You should repeat this after each lowering or optimization pass so functions with different HIR but same MIR are also marked as unchanged and dont cause items up the tree to rebuild.

show 1 reply