Commit 9bf8f486

9bf8f4862012Merged

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

Description

build: split bootstrap AST/IR/C1 into proper Make targets

The spinel_{analyze,codegen}$(EXE) recipes produced build/.ast, build/.ir, and build/*1.c as side effects, leaving those files without their own Make rules. Under default-parallel make, the verification round-2 targets that depend on build/codegen.ast could be scheduled before the spinel_codegen recipe had finished refreshing the AST, so they read a stale AST while later steps used the freshly rebuilt one.

That race only manifested when spinel_codegen.rb actually changed: any node-count shift in the rebuilt AST landed in build/codegen.ast while build/codegen2.ir still encoded the previous numbering. codegen then looked up per-method scope tables at bids that no longer pointed at the right method, producing build/codegen2.c where adjacent methods borrowed each other's locals (push_redo_label returning lv_old, emit_setjmp_depth_unwind returning lv_saved_setjmp_depth, etc.) and string-returning calls got wrapped with sp_int_to_s. The same probe under -j1 always passed.

Give every produced file its own rule: build/{analyze,codegen}.ast, build/{analyze,codegen}.ir, build/{analyze,codegen}1.c. Each spinel_$(EXE) now only links its build/1.c. No side-effect outputs remain, so the dependency DAG matches what parallel make actually schedules.

Fixes #620

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

Details

Commit
9bf8f4862012
Parent
12838d1f308a

MakefilemodifiedView file

@@ -287,16 +287,37 @@
287287
288288 codegen: spinel_analyze$(EXE) spinel_codegen$(EXE)
289289
290-spinel_analyze$(EXE): $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP) spinel_parse$(EXE)
290+# Round 1 pipeline split into per-stage rules. Previously the
291+# `spinel_<phase>$(EXE)` recipe produced its AST/IR/C1 outputs as
292+# side effects, which left those files without proper Make rules.
293+# Under parallel make that races: `build/codegen2.ir` (declared to
294+# depend on `build/codegen.ast`) could be scheduled before the
295+# spinel_codegen recipe had refreshed the AST, so it read a stale
296+# AST while later steps used the fresh one. The bid mismatch then
297+# corrupted scope tables in the bootstrap fixpoint output. See #620.
298+
299+build/analyze.ast: $(ANALYZE_STAMP) spinel_parse$(EXE)
291300 ./spinel_parse$(EXE) spinel_analyze.rb build/analyze.ast
292- ruby spinel_analyze.rb build/analyze.ast build/analyze.ir
293- ruby spinel_codegen.rb build/analyze.ast build/analyze.ir build/analyze1.c
294- $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/analyze1.c $(LDFLAGS) -lm -o spinel_analyze$(EXE)
295301
296-spinel_codegen$(EXE): $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP) spinel_parse$(EXE)
302+build/codegen.ast: $(CODEGEN_STAMP) spinel_parse$(EXE)
297303 ./spinel_parse$(EXE) spinel_codegen.rb build/codegen.ast
304+
305+build/analyze.ir: build/analyze.ast $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
306+ ruby spinel_analyze.rb build/analyze.ast build/analyze.ir
307+
308+build/codegen.ir: build/codegen.ast $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
298309 ruby spinel_analyze.rb build/codegen.ast build/codegen.ir
310+
311+build/analyze1.c: build/analyze.ast build/analyze.ir $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
312+ ruby spinel_codegen.rb build/analyze.ast build/analyze.ir build/analyze1.c
313+
314+build/codegen1.c: build/codegen.ast build/codegen.ir $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
299315 ruby spinel_codegen.rb build/codegen.ast build/codegen.ir build/codegen1.c
316+
317+spinel_analyze$(EXE): build/analyze1.c $(SP_RT_LIB)
318+ $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/analyze1.c $(LDFLAGS) -lm -o spinel_analyze$(EXE)
319+
320+spinel_codegen$(EXE): build/codegen1.c $(SP_RT_LIB)
300321 $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/codegen1.c $(LDFLAGS) -lm -o spinel_codegen$(EXE)
301322
302323 # ---- Self-hosting verification ----