AIFeed

Marmot, an alternative Go compiler

Original text(via Lobsters)

Go, lowered to machine code

marmot is a Go compiler built on MLIR and LLVM. Keep your Go code and your go.mod, switch the compiler, and get small, fast native binaries and errors that show you the fix.

Experimental: marmot compiles real Go programs, including itself, and checks every test program against Go, but it is not ready for production.

  • GoYour code, unchanged.var s int32for _, x := range xs { s += x}return s

Go

Your code, unchanged.


        var s int32for _, x := range xs {    s += x}return s
      
  • MLIR, with the go dialectStill Go: an index into a slice, with its bounds check.%v9 = llvm.extractvalue %a0[0] : !llvm.struct<(ptr, i64, i64)>%v10 = llvm.extractvalue %a0[1] : !llvm.struct<(ptr, i64, i64)>%v11 = go.index %v9[%v7] len %v10, i32 : i64%v12 = llvm.load %v11 {alignment = 4 : i64, go.unsafe} : !llvm.ptr -> i32%v13 = llvm.add %v1, %v12 : i32

MLIR, with the go dialect

Still Go: an index into a slice, with its bounds check.


        %v9 = llvm.extractvalue %a0[0] : !llvm.struct<(ptr, i64, i64)>%v10 = llvm.extractvalue %a0[1] : !llvm.struct<(ptr, i64, i64)>%v11 = go.index %v9[%v7] len %v10, i32 : i64%v12 = llvm.load %v11 {alignment = 4 : i64, go.unsafe} : !llvm.ptr -> i32%v13 = llvm.add %v1, %v12 : i32
      
  • LLVM IRThe check is gone; four int32 values at a time.%wide.load = load <4 x i32>, ptr %5, align 4%wide.load12 = load <4 x i32>, ptr %6, align 4%wide.load13 = load <4 x i32>, ptr %7, align 4%wide.load14 = load <4 x i32>, ptr %8, align 4%9 = add <4 x i32> %wide.load, %vec.phi

LLVM IR

The check is gone; four int32 values at a time.


        %wide.load = load <4 x i32>, ptr %5, align 4%wide.load12 = load <4 x i32>, ptr %6, align 4%wide.load13 = load <4 x i32>, ptr %7, align 4%wide.load14 = load <4 x i32>, ptr %8, align 4%9 = add <4 x i32> %wide.load, %vec.phi
      
  • arm64 machine codeTwo 128 bit loads, four vector adds.ldp q4, q5, [x8, #-0x20]ldp q6, q7, [x8], #0x40add.4s v0, v4, v0add.4s v1, v5, v1add.4s v2, v6, v2add.4s v3, v7, v3

arm64 machine code

Two 128 bit loads, four vector adds.


        ldp q4, q5, [x8, #-0x20]ldp q6, q7, [x8], #0x40add.4s v0, v4, v0add.4s v1, v5, v1add.4s v2, v6, v2add.4s v3, v7, v3
      

Against go build

Measured on an Apple M3 Pro, newest measurement of each. Every program’s output is checked against Go. Shorter bars are better.

MeasurementmarmotgoTo scale
hello world with println, ‑release binary size201 KB1.83 MB
hello world with fmt.Println, ‑release binary size698 KB2.43 MB
run time, 45 programs, ‑release geometric mean; 37 faster than Go, 8 slower1.54x faster1x
first build of cmd/marmot, empty caches 325 packages, 2026-11-144.40 to 4.57 s6.14 to 6.18 s
rebuild, nothing changed 325 packages, 2026-11-140.05 s0.15 s
one line edit, leaf package 325 packages, 2026-11-140.59 s0.66 to 0.68 s
one line edit, deep package 325 packages, 2026-11-140.72 to 0.76 s1.18 to 1.23 s
  • hello world with println, ‑releasebinary sizemarmot201 KBgo1.83 MB
  • hello world with fmt.Println, ‑releasebinary sizemarmot698 KBgo2.43 MB
  • run time, 45 programs, ‑releasegeometric mean; 37 faster than Go, 8 slowermarmot1.54x fastergo1x
  • first build of cmd/marmot, empty caches325 packages, 2026-11-14marmot4.40 to 4.57 sgo6.14 to 6.18 s
  • rebuild, nothing changed325 packages, 2026-11-14marmot0.05 sgo0.15 s
  • one line edit, leaf package325 packages, 2026-11-14marmot0.59 sgo0.66 to 0.68 s
  • one line edit, deep package325 packages, 2026-11-14marmot0.72 to 0.76 sgo1.18 to 1.23 s

Every number and how it was measured

Errors that show the fix

Marmots stand guard and whistle when something is wrong. marmot’s errors show the source, mark the exact span, label every place involved, and suggest a fix that marmot fix can apply.

Off a terminal they are the plain lines the go tool prints. Under a coding agent they are JSON, with the spans, the source around them and the fixes as edits. Every error has a stable code, and all 44 are explained.

marmot build: error M0014, Square does not implement Shape, with labels on the interface and on the method with a pointer receiver, and a fix that adds &
marmot build: error M0014, Square does not implement Shape, with labels on the interface and on the method with a pointer receiver, and a fix that adds &
marmot build: error M0014, Square does not implement Shape, with labels on the interface and on the method with a pointer receiver, and a fix that adds &
marmot build: error M0014, Square does not implement Shape, with labels on the interface and on the method with a pointer receiver, and a fix that adds &

One command for the whole loop

marmot works like the go command, and does what people usually install next to it.

Go’s front end, MLIR and LLVM behind it

marmot keeps the parts of the Go toolchain that define the language: the type checker, the SSA builder and Go’s own standard library. It replaces the parts that generate code. A small go dialect keeps Go’s meaning in MLIR long enough to remove bounds checks, keep objects on the stack and call interface methods directly.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗