Commit 69b25d85

69b25d852c5dMerged

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

Description

Add opt-in YJIT for the bootstrap Ruby

The bootstrap stage runs spinel_analyze.rb / spinel_codegen.rb under CRuby to interpret the compiler on its own source. Those are long-running, hot-loop-heavy processes, exactly where YJIT amortizes its warmup, so YJIT=1 make now adds --yjit to just those four invocations via a BOOTSTRAP_RUBY variable.

It is opt-in because it needs a Ruby built with YJIT (default-on in 3.3+, a YJIT-enabled build on 3.1/3.2). The per-test REF_RUBY stays on plain ruby: each test spawns a fresh short-lived process, so YJIT warmup never pays off before exit. YJIT does not change semantics, so the emitted IR / C is byte-identical with or without it.

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

Details

Commit
69b25d852c5d
Parent
6c6d900864e8

MakefilemodifiedView file

@@ -105,6 +105,20 @@
105105 # which the bootstrap miniruby can't load.
106106 REF_RUBY ?= ruby
107107
108+# Ruby used to run the bootstrap compiler (spinel_analyze.rb /
109+# spinel_codegen.rb interpret the compiler on its own source). These
110+# are long-running, hot-loop-heavy processes — exactly where YJIT
111+# amortizes its warmup — so `YJIT=1 make` adds `--yjit` here only.
112+# Opt-in because it requires a Ruby built with YJIT (3.3+ default-on,
113+# 3.1/3.2 need a YJIT-enabled build). The per-test REF_RUBY is left on
114+# plain `ruby`: those spawn a fresh short-lived process per file, so
115+# YJIT warmup never pays off before the process exits. YJIT does not
116+# change semantics, so the emitted IR / C is identical either way.
117+BOOTSTRAP_RUBY ?= ruby
118+ifeq ($(YJIT),1)
119+ BOOTSTRAP_RUBY := $(BOOTSTRAP_RUBY) --yjit
120+endif
121+
108122 # Prism library: prefer vendor/prism (fetched via `make deps`), then
109123 # fall back to the Prism gem if one is installed. Override by setting
110124 # PRISM_DIR=/path/to/prism on the command line.
@@ -331,16 +345,16 @@
331345 ./spinel_parse$(EXE) spinel_codegen.rb build/codegen.ast
332346
333347 build/analyze.ir: build/analyze.ast $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
334- ruby spinel_analyze.rb build/analyze.ast build/analyze.ir
348+ $(BOOTSTRAP_RUBY) spinel_analyze.rb build/analyze.ast build/analyze.ir
335349
336350 build/codegen.ir: build/codegen.ast $(ANALYZE_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
337- ruby spinel_analyze.rb build/codegen.ast build/codegen.ir
351+ $(BOOTSTRAP_RUBY) spinel_analyze.rb build/codegen.ast build/codegen.ir
338352
339353 build/analyze1.c: build/analyze.ast build/analyze.ir $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
340- ruby spinel_codegen.rb build/analyze.ast build/analyze.ir build/analyze1.c
354+ $(BOOTSTRAP_RUBY) spinel_codegen.rb build/analyze.ast build/analyze.ir build/analyze1.c
341355
342356 build/codegen1.c: build/codegen.ast build/codegen.ir $(CODEGEN_STAMP) $(NODE_TABLE_LOADER_STAMP) $(COMPILER_HELPERS_STAMP)
343- ruby spinel_codegen.rb build/codegen.ast build/codegen.ir build/codegen1.c
357+ $(BOOTSTRAP_RUBY) spinel_codegen.rb build/codegen.ast build/codegen.ir build/codegen1.c
344358
345359 spinel_analyze$(EXE): build/analyze1.c $(SP_RT_LIB)
346360 $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/analyze1.c $(SP_RT_LIB) $(LDFLAGS) -lm -o spinel_analyze$(EXE)