Commit f325c842

f325c8422136Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

build: split spinel_codegen build from full bootstrap verification

make spinel_codegen (also make codegen, make all) now does a single-pass build: parse + CRuby-compile + cc, producing a working spinel_codegen binary. About 1m25s on a typical machine.

make bootstrap keeps the self-hosting fixed-point check — re-runs the binary on its own AST to make gen2.c, compiles bin2, re-runs bin2 to make gen3.c, asserts gen2.c == gen3.c. About 25s on top of an existing fast build.

Default flow:

  • make → fast build (uses gen1 via CRuby)
  • make bootstrap → fast build + self-host verify

Iterative dev (edit codegen.rb, retest) only pays the verify cost on demand instead of every rebuild.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
f325c8422136
Parent
cb1a53ccb854

MakefilemodifiedView file

@@ -86,9 +86,9 @@
8686 PRISM_OBJ = $(patsubst $(PRISM_DIR)/src/%.c,build/prism/%.o,$(PRISM_SRC))
8787 PRISM_LIB = build/libprism.a
8888
89-.PHONY: all parse bootstrap test bench clean install uninstall deps
89+.PHONY: all parse bootstrap codegen test bench clean install uninstall deps
9090
91-all: parse regexp bootstrap
91+all: parse regexp spinel_codegen$(EXE)
9292
9393 # ---- Dependencies ----
9494 # Clone Prism into vendor/prism at the pinned version. Run this once
@@ -112,7 +112,7 @@
112112 # If PRISM_DIR ended up empty (no vendor/prism, no gem), halt with a
113113 # clear message before trying to build anything that needs it.
114114 ifeq ($(PRISM_DIR),)
115-parse bootstrap regexp all: prism-missing
115+parse bootstrap codegen regexp all: prism-missing
116116 prism-missing:
117117 @echo "Error: Prism not found."; \
118118 echo " Run 'make deps' to fetch libprism into vendor/prism,"; \
@@ -158,20 +158,30 @@
158158
159159 regexp: $(SP_RT_LIB)
160160
161-# ---- Bootstrap ----
161+# ---- Build the codegen binary (fast path) ----
162+# `make spinel_codegen` (or the alias `make codegen`) compiles
163+# spinel_codegen.rb once via CRuby and links the result. This is
164+# enough to use the binary; for the full self-hosting fixed-point
165+# check (gen2.c == gen3.c), use `make bootstrap`.
162166
163-bootstrap: spinel_codegen$(EXE)
167+codegen: spinel_codegen$(EXE)
164168
165169 spinel_codegen$(EXE): spinel_codegen.rb spinel_parse$(EXE)
166- @echo "=== Bootstrap Step 1: parse ==="
167170 ./spinel_parse$(EXE) spinel_codegen.rb build/codegen.ast
168- @echo "=== Bootstrap Step 2: gen1 (CRuby) ==="
169171 ruby spinel_codegen.rb build/codegen.ast build/gen1.c
170- $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/gen1.c $(LDFLAGS) -lm -o build/bin1$(EXE)
171- @echo "=== Bootstrap Step 3: gen2 (bin1) ==="
172- ./build/bin1$(EXE) build/codegen.ast build/gen2.c
172+ $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/gen1.c $(LDFLAGS) -lm -o spinel_codegen$(EXE)
173+
174+# ---- Self-hosting verification (slow path) ----
175+# Re-runs the binary on its own AST to produce gen2.c, compiles bin2,
176+# re-runs bin2 to produce gen3.c, asserts gen2.c == gen3.c (the
177+# self-hosting fixed point). On success, replaces spinel_codegen with
178+# the verified bin2.
179+
180+bootstrap: spinel_codegen$(EXE)
181+ @echo "=== Bootstrap: gen2 (via spinel_codegen) ==="
182+ ./spinel_codegen$(EXE) build/codegen.ast build/gen2.c
173183 $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/gen2.c $(LDFLAGS) -lm -o build/bin2$(EXE)
174- @echo "=== Bootstrap Step 4: gen3 (bin2) - verify ==="
184+ @echo "=== Bootstrap: gen3 (via bin2) - verify ==="
175185 ./build/bin2$(EXE) build/codegen.ast build/gen3.c
176186 @diff build/gen2.c build/gen3.c > /dev/null && echo "gen2.c == gen3.c (bootstrap OK)" || (echo "BOOTSTRAP FAILED: gen2.c != gen3.c" && exit 1)
177187 cp build/bin2$(EXE) spinel_codegen$(EXE)
@@ -179,7 +189,7 @@
179189 # ---- Test ----
180190
181191 test: spinel_parse$(EXE) $(SP_RT_LIB)
182- @if [ ! -f spinel_codegen$(EXE) ]; then echo "Run 'make bootstrap' first"; exit 1; fi
192+ @if [ ! -f spinel_codegen$(EXE) ]; then echo "Run 'make' or 'make spinel_codegen' first"; exit 1; fi
183193 @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
184194 @pass=0; fail=0; err=0; \
185195 for f in test/*.rb; do \
@@ -211,7 +221,7 @@
211221 if [ $$fail -ne 0 ] || [ $$err -ne 0 ]; then exit 1; fi
212222
213223 bench: spinel_parse$(EXE) $(SP_RT_LIB)
214- @if [ ! -f spinel_codegen$(EXE) ]; then echo "Run 'make bootstrap' first"; exit 1; fi
224+ @if [ ! -f spinel_codegen$(EXE) ]; then echo "Run 'make' or 'make spinel_codegen' first"; exit 1; fi
215225 @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
216226 @pass=0; fail=0; err=0; skip=0; \
217227 for f in benchmark/*.rb; do \