views:

94

answers:

3

If you compile a new version of compiler, how many times should you recompile it iteratively?

First: compile the new version of compiler[1] using the old version[0].

Second: compile the new version[2] using the newly compiled one[1], to apply new optimizations and fix bugs to the binary, not present in old[0] compiler.

Now third? Compile again, using [2] to remove any potential bugs that could have resulted from bugs in [1] as result of faulty compilation by buggy [0]...?

...but if you're paranoid, maybe the bugs introduced by [0] into [1] caused [2] to be somewhat buggy too...?

Does going beyond [2] make sense at all?

+5  A: 

I'd stop when the result of compilation n is identical to the result of compilation n - 1; at that point you've reached steady state.

T.J. Crowder
Lol fixed point! :)
Dacav
That works, unless the binary contains timestamps ( `__DATE__` `__TIME__` ) or other variable stuff like auto-incremented build numbers.
SF.
If this doesn't happen on the third version, there's probably a bug. The new compiler should produce the same output on own sources regardless of the version it was compiled with.
Rafał Dowgird
@Rafal: Agreed. @SF: Yes, comparisons would need to handle that sort of thing; not an uncommon requirement.
T.J. Crowder
+2  A: 

The instructions for bootstrapping OCaml invite you to continue until you have reached a fixpoint, if you wish. Assuming the new compiler only fixes bugs and does not introduce new ones, you may need to bootstrap several times to make self-inducing compiler bugs disappear.

You may also reach a fixpoint without the bug you were trying to fix being fixed, because the presence of the bug in the bootstrap compiler perpetuates it in the bootstrapped version (a sort of involuntary Ken Thompson). This happened at least once in the history of OCaml. When they noticed this, the developers fixed the assembly code by hand in order to obtain a correct compiler that translated correct source into a correct compiler.

Pascal Cuoq
A: 

Typically you should compile once withouth the standard library and get a partially working version of the compiler. Subsequently you need to recompile with the standard library support: this enables you to get further functionality (like printf checking and libgcc stuff).

I didn't know about subsequent recompilations, but thanks for the info :)

Dacav