Commit 0eb0fff5
0eb0fff518a0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +1 added · ~3 modified
Description
refactor: extract nil-guard helpers + body-definitely-exits to compiler_helpers.rb
Five helpers were byte-for-byte duplicated between spinel_analyze.rb and spinel_codegen.rb after the #550 / #558 landings: parse_nil_predicate, body_definitely_exits?, infer_nil_guard_narrow_type, parse_nil_guard_var, and scan_back_writer_narrow_for. Both call sets depended only on node-table accessors and infer_type / get_stmts, which exist on both passes' Compiler class.
Move them to a new compiler_helpers.rb that reopens
class Compiler, require_relative'd from both
spinel_analyze.rb and spinel_codegen.rb just after the
existing require_relative "node_table_loader" line. Drift
between the two passes can't happen any more.
While here, body_definitely_exits? also recognizes
BreakNode / NextNode / throw (CallNode "throw") as scope-
exiting bodies. Pre-fix only return / raise counted, so
patterns like break if h.nil? / next if h.nil? /
throw :tag if h.nil? inside a loop didn't push the
nil-guard narrow. The narrow continues to apply only to the
rest of the enclosing block, matching break / next's
unwind-to-loop-boundary semantics.
Makefile gains a COMPILER_HELPERS_STAMP dep on both
spinel_analyze$(EXE) and spinel_codegen$(EXE) (plus the
test target) so editing the shared file triggers the right
rebuild. The generic build/stamps/%.stamp: % rule already
covers stamp creation; no new stamp rule needed.
Verified: 527 tests pass, optcarrot checksum 59662 preserved.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 0eb0fff518a0
- Parent
- 34ff4c895448
MakefilemodifiedView file
CODEGEN_STAMP := build/stamps/spinel_codegen.rb.stampANALYZE_STAMP := build/stamps/spinel_analyze.rb.stampNODE_TABLE_LOADER_STAMP := build/stamps/node_table_loader.rb.stampCOMPILER_HELPERS_STAMP := build/stamps/compiler_helpers.rb.stampPARSE_STAMP := build/stamps/spinel_parse.c.stamp.PHONY: all parse bootstrap codegen test retest clean-test-results regen-expected bench optcarrot clean install uninstall depscodegen: spinel_analyze$(EXE) spinel_codegen$(EXE)spinel_analyze$(EXE): $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) spinel_parse$(EXE)spinel_analyze$(EXE): $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP) spinel_parse$(EXE) ./spinel_parse$(EXE) spinel_analyze.rb build/analyze.ast ruby spinel_analyze.rb build/analyze.ast build/analyze.ir ruby spinel_codegen.rb build/analyze.ast build/analyze.ir build/analyze1.c $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/analyze1.c $(LDFLAGS) -lm -o spinel_analyze$(EXE)spinel_codegen$(EXE): $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) spinel_parse$(EXE)spinel_codegen$(EXE): $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP) spinel_parse$(EXE) ./spinel_parse$(EXE) spinel_codegen.rb build/codegen.ast ruby spinel_analyze.rb build/codegen.ast build/codegen.ir ruby spinel_codegen.rb build/codegen.ast build/codegen.ir build/codegen1.c# The .ok target is the test's stamp; mtime tracking gives per-test# caching for free. Order-only spinel_parse$(EXE) / spinel_analyze$(EXE)# / spinel_codegen$(EXE) stop a bootstrap relink from invalidating every test.build/test-results/%.ok: test/%.rb $(SP_RT_LIB) $(CODEGEN_STAMP) $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(PARSE_STAMP) | spinel_parse$(EXE) spinel_analyze$(EXE) spinel_codegen$(EXE)build/test-results/%.ok: test/%.rb $(SP_RT_LIB) $(CODEGEN_STAMP) $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP) $(PARSE_STAMP) | spinel_parse$(EXE) spinel_analyze$(EXE) spinel_codegen$(EXE) @mkdir -p build/test-results @tmpdir=$$(mktemp -d /tmp/spinel-test.XXXXXX); \ ast=$$tmpdir/test.ast; \compiler_helpers.rbaddedView file
Loading diff…
spinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…