# Self-hosting (/docs/experiments/selfhost)

The probe builds marmot with itself on the Linux benchmark machine, at main cf0e9b27, through the job queue. MARMOT_PART_ORDER=1 (a fixed link order, for reproducible output) and MARMOT_TIER1=0 were set. Each stage has a private root with an empty build cache, so every build is cold.

## Stages [#stages]

| Stage | Result | Time | Size |
| --- | --- | --- | --- |
| stock Go builds marmot-1 (cmd/marmot, empty Go cache) | ok | 23.1 s | 25.8 MB (18.3 MB with -ldflags="-s -w", 2.1 s warm) |
| marmot-1 builds marmot-2, dev | ok | 17.4 s | 36.1 MB |
| marmot-1 builds marmot-2, -release | ok | 161.2 s | 16.6 MB |
| marmot-2 runs (version) | ok | 20 ms | |
| marmot-2 builds and runs hello with fmt | ok | 2.5 s | |
| marmot-2 builds marmot-3, -release | ok | 128.3 s | 16.6 MB |
| marmot-2 test ./internal/driver | ok (all pass) | 175.5 s | |
| MLIR of marmot-2 and marmot-3, the first 60 programs of tests/run/core (dev, -nocache) | 60 of 60 byte-identical | | |
| conform tests/run/core in dev mode with marmot-2 | 150 of 151 pass | 303 s | |

## Findings [#findings]

1. **marmot builds itself, and the stage test passes on its first criterion.** marmot-2 and marmot-3 emit byte-identical MLIR for all 60 programs compared. marmot-2 passes the driver tests and 150 of 151 core conformance tests.
2. **marmot-2 and marmot-3 are not byte-identical, but marmot-3 is a fixed point.** marmot-2 and marmot-3 have the same size (16648448 bytes) but differ in about 1.04 million bytes. The difference starts at byte 265, with the same values offset by 32 (a small layout shift). A follow-up run had marmot-3 build marmot-4 from an empty cache (158 s): marmot-4 is byte-identical to marmot-3. So from the second marmot-built compiler on, the output is stable. The difference is between the compiler built by Go (marmot-1) and the one built by marmot (marmot-2). For cmd/marmot they produce slightly different binaries. Their MLIR for the 60 conformance programs is identical. A repeat build with each compiler was not a test of determinism, because it was answered from the build cache in under 1 s.
3. **The one conformance failure was load.** run/core/bool_ops failed with "compile timeout" (20 s per test) at a load of 35 to 44. Built again on its own, it compiles in 1.3 s with marmot-1 and 1.0 s with marmot-2, and runs correctly.
4. **Size.** marmot -release builds marmot in 16.6 MB, 0.91x stock Go with -s -w (18.3 MB) and 0.65x Go without stripping (25.8 MB). A dev build is 36.1 MB (1.40x Go).
5. **Build time.** A cold -release self build takes 128 to 161 s, against 23 s for stock Go with an empty cache. A cold dev build takes 17.4 s (0.75x Go). The -release time is whole-program optimization of the whole compiler. It is the cost of the stage test, not of daily builds.

## Blockers [#blockers]

None stops the stage test. Open items:

1. The Go-built and the marmot-built compiler give slightly different binaries for cmd/marmot (a 32-byte layout shift). marmot-3 is a fixed point, so this does not block the stage test. To find it, compare the MLIR and the object files of cmd/marmot from marmot-1 and marmot-2.
2. The stage test as a gate: run it per release, and cover the whole conformance suite instead of 60 programs.