Menu

1 / 4

How to Test a Compiler Against Itself: Thirteen Generators and 7,800 Programs

#hackernoon#technology#chuks#build#programs
Reading 0:00
15s threshold

When you build a language with two ways to run a program, comparing them catches disagreement but not shared mistakes. For Chuks v0.2.0-rc.3, we added tests that hold programs to a known answer, generated about 7,800 of them from every combination of three language features, and committed to shipping with no further release candidate.

The problem with checking a thing against its twin

Chuks runs programs two ways. A bytecode VM gives instant startup while you develop. A native compiler produces the binary you ship. The promise is simple: the same program prints the same thing in both.

The natural test is to run everything both ways and compare. It is also a trap. Imagine the two implementations share a front end, the part that reads your code and decides what it means. If that part makes a mistake, both back ends faithfully execute the mistake, agree with each other, and the test passes.

We hit this for real. Both back ends once agreed on a value that should have been a typed record and was not.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.