Commit 831c2911

831c2911d34eMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified

Description

Add fast-bootstrap path for incremental compiler rebuilds

make all rebuilt the compiler backend by running spinel_analyze.rb and spinel_codegen.rb under CRuby every time the sources changed. On a machine that already has working compiler binaries that round is the bottleneck: the type-inference pass dominates, and the interpreted inferencer is about 3.5x slower than the compiled one.

Add tools/fast-bootstrap, which rebuilds the compiler from the previous compiled binaries (stage0) instead of from CRuby, runs a cheap smoke check, and atomically promotes the result. make all now uses this by default (FAST_BOOTSTRAP=auto) and falls back to the CRuby authority path when stage0 is missing or cannot compile the current source, so a failed fast bootstrap never destroys the last working compiler.

make bootstrap is preserved as the authority: it forces FAST_BOOTSTRAP=0 and runs the CRuby-seeded round2/round3 self-host fixpoint, keeping CI and release semantics byte-canonical. See docs/fast-bootstrap.md.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
831c2911d34e
Parent
67bcec70ee8a

MakefilemodifiedView file

@@ -128,6 +128,14 @@
128128 BOOTSTRAP_RUBY := $(BOOTSTRAP_RUBY) --yjit
129129 endif
130130
131+# FAST_BOOTSTRAP: how `make all` rebuilds the compiler backend.
132+# auto (default) -- use the previous compiled binaries (stage0) via
133+# tools/fast-bootstrap (~3.5x faster than the CRuby round);
134+# falls back to CRuby when stage0 is missing/unusable.
135+# 0 -- always use the CRuby authority round.
136+# `make bootstrap` always forces the CRuby round regardless of this.
137+FAST_BOOTSTRAP ?= auto
138+
131139 # Prism library: prefer vendor/prism (fetched via `make deps`), then
132140 # fall back to the Prism gem if one is installed. Override by setting
133141 # PRISM_DIR=/path/to/prism on the command line.
@@ -160,7 +168,7 @@
160168 COMPILER_HELPERS_STAMP := build/stamps/compiler_helpers.rb.stamp
161169 PARSE_STAMP := build/stamps/spinel_parse.c.stamp
162170
163-.PHONY: all parse bootstrap codegen rbs_extract rbs-test regen-rbs-expected test retest fast-test clean-test-results regen-expected bench optcarrot clean install uninstall deps FORCE
171+.PHONY: all parse bootstrap bootstrap-fixpoint fast-bootstrap codegen rbs_extract rbs-test regen-rbs-expected test retest fast-test clean-test-results regen-expected bench optcarrot clean install uninstall deps FORCE
164172
165173 # `make all` includes spinel_rbs_extract when vendor/rbs has been
166174 # fetched (via `make deps`). Without vendor/rbs the extractor is
@@ -365,11 +373,20 @@
365373 build/codegen1.c: build/codegen.ast build/codegen.ir $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
366374 $(BOOTSTRAP_RUBY) spinel_codegen.rb build/codegen.ast build/codegen.ir build/codegen1.c
367375
376+ifeq ($(FAST_BOOTSTRAP),auto)
377+# Default: rebuild BOTH compiler binaries from the previous binaries (stage0)
378+# via tools/fast-bootstrap, gated on the source stamps. Grouped target (&:)
379+# runs the helper once for both. Helper falls back to the CRuby rules
380+# (FAST_BOOTSTRAP=0) when stage0 is missing or can't compile the source.
381+spinel_analyze$(EXE) spinel_codegen$(EXE) &: $(ANALYZE_STAMP) $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP) $(SP_RT_LIB) | spinel_parse$(EXE)
382+ @CC='$(CC)' EXE='$(EXE)' BOOTSTRAP_CFLAGS='$(BOOTSTRAP_CFLAGS)' SP_RT_LIB='$(SP_RT_LIB)' LDFLAGS='$(LDFLAGS)' sh tools/fast-bootstrap
383+else
368384 spinel_analyze$(EXE): build/analyze1.c $(SP_RT_LIB)
369385 $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/analyze1.c $(SP_RT_LIB) $(LDFLAGS) -lm -o spinel_analyze$(EXE)
370386
371387 spinel_codegen$(EXE): build/codegen1.c $(SP_RT_LIB)
372388 $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/codegen1.c $(SP_RT_LIB) $(LDFLAGS) -lm -o spinel_codegen$(EXE)
389+endif
373390
374391 # ---- Self-hosting verification ----
375392 # After CRuby builds spinel_{analyze,codegen}, run them on each
@@ -415,7 +432,13 @@
415432 build/codegen3.c: build/codegen.ast build/codegen3.ir build/bin2_codegen$(EXE)
416433 ./build/bin2_codegen$(EXE) build/codegen.ast build/codegen3.ir build/codegen3.c
417434
418-bootstrap: build/analyze3.c build/codegen3.c
435+# bootstrap: the CRuby-seeded self-host fixpoint AUTHORITY (CI/release). Always
436+# rebuilds the compiler via the CRuby round (forces FAST_BOOTSTRAP=0, never the
437+# fast path), then verifies round2 == round3 byte-for-byte.
438+bootstrap:
439+ @$(MAKE) --no-print-directory FAST_BOOTSTRAP=0 bootstrap-fixpoint
440+
441+bootstrap-fixpoint: build/analyze3.c build/codegen3.c
419442 @diff build/analyze2.ir build/analyze3.ir > /dev/null && echo "analyze.rb: IR fixpoint OK" || (echo "BOOTSTRAP FAILED: analyze.rb IR diverged" && exit 1)
420443 @diff build/analyze2.c build/analyze3.c > /dev/null && echo "analyze.rb: C fixpoint OK" || (echo "BOOTSTRAP FAILED: analyze.rb C diverged" && exit 1)
421444 @diff build/codegen2.ir build/codegen3.ir > /dev/null && echo "codegen.rb: IR fixpoint OK" || (echo "BOOTSTRAP FAILED: codegen.rb IR diverged" && exit 1)
@@ -423,6 +446,14 @@
423446 cp build/bin2_analyze$(EXE) spinel_analyze$(EXE)
424447 cp build/bin2_codegen$(EXE) spinel_codegen$(EXE)
425448
449+# fast-bootstrap: rebuild the compiler from the PREVIOUS compiled binaries
450+# (stage0) instead of the slow CRuby round, then atomically promote. Speed
451+# path: no self-host fixpoint (that is `make bootstrap`). Falls back to the
452+# CRuby authority path when stage0 is missing or can't compile the current
453+# source. See tools/fast-bootstrap.
454+fast-bootstrap: spinel_parse$(EXE) $(SP_RT_LIB)
455+ @CC='$(CC)' EXE='$(EXE)' BOOTSTRAP_CFLAGS='$(BOOTSTRAP_CFLAGS)' SP_RT_LIB='$(SP_RT_LIB)' LDFLAGS='$(LDFLAGS)' sh tools/fast-bootstrap
456+
426457 # ---- Test ----
427458
428459 TESTS := $(wildcard test/*.rb)