Commit 3d35d4eb

3d35d4eb72b4Merged

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

Description

spinelc: --rbs advisory RBS type seeds (authoritative pin)

Restores the legacy backend's --rbs seeding in the C driver. spinel --rbs DIR runs spinel_rbs_extract over DIR's .rbs and hands the line-oriented seeds to spinelc via SPINEL_RBS_SEED. apply_rbs_seeds (run once, just before the inference fixpoint) pins each named parameter, return, and ivar to its seeded type; guards at every fixpoint write site keep a pinned slot from being widened (legacy "RBS wins" semantics). Type tokens with no precise C kind (poly, sym_array, obj_X_ptr_array, unknown classes) are skipped, so a seed never makes inference worse.

Pin storage: LocalVar.rbs_seeded (params), Scope.ret_rbs_seeded (returns), ClassInfo.rbs_pin_ivars (ivar name list + class_ivar_pinned). Guards added to infer_write_types, infer_ivar_types, bind_call_params, the default / prep / hash-value / array param passes, the param + reader ivar backstops, bigint promotion, transplant unification, and the nil->poly / strbuf post-passes. Every guard is if (... rbs_seeded ...), a strict no-op when no seed is loaded -- so the normal compile path is unchanged.

Also fix scope_local_intern to zero the new LocalVar.rbs_seeded (and the pre-existing init_guarded) on realloc-grown slots: leaving it uninitialized let the guards fire on garbage and broke unseeded inference (620/225 before, 846 after).

make gate: ALL GREEN (test 846, bench, optcarrot, self-host fixpoint).

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

Details

Commit
3d35d4eb72b4
Parent
62575f90e417

spinelmodifiedView file

@@ -34,6 +34,7 @@
3434 # generated C, not the Ruby source)
3535 # --cc=CMD C compiler command (default: cc)
3636 # -e STR Inline Ruby source (repeatable; multiple -e join with \n)
37+# --rbs DIR Seed the analyzer with advisory RBS signatures from DIR
3738 # --int-overflow=MODE Int +/-/* overflow handling (default: raise)
3839 # raise | wrap | promote
3940
@@ -49,6 +50,15 @@
4950 ;;
5051 esac
5152
53+# RBS seed extractor (built by `make`); used by --rbs to turn a dir of *.rbs
54+# into advisory type seeds for the analyzer.
55+RBS_EXTRACT_BIN="$DIR/spinel_rbs_extract"
56+case "$(uname -s 2>/dev/null)" in
57+ MINGW*|MSYS*|CYGWIN*)
58+ [ ! -x "$RBS_EXTRACT_BIN" ] && [ -x "$RBS_EXTRACT_BIN.exe" ] && RBS_EXTRACT_BIN="$RBS_EXTRACT_BIN.exe"
59+ ;;
60+esac
61+
5262 SOURCE=""
5363 OUTPUT=""
5464 C_ONLY=0
@@ -66,6 +76,8 @@
6676 EVAL_SCRIPT=""
6777 EVAL_USED=0
6878 EVAL_TMP=""
79+RBS_DIR=""
80+SEED_TMP=""
6981 INT_OVERFLOW="raise"
7082 DEBUG=0
7183 # #line directives are on by default: they cost nothing at runtime (the binary
@@ -82,6 +94,8 @@
8294 --source=*) SOURCE="${1#--source=}"; shift ;;
8395 --output=*) OUTPUT="${1#--output=}"; shift ;;
8496 --cc=*) CC_CMD="${1#--cc=}"; shift ;;
97+ --rbs=*) RBS_DIR="${1#--rbs=}"; shift ;;
98+ --rbs) shift; RBS_DIR="$1"; shift ;;
8599 --int-overflow=*) INT_OVERFLOW="${1#--int-overflow=}"; shift ;;
86100 --int-overflow) shift; INT_OVERFLOW="$1"; shift ;;
87101 --) # `--` ends spinel-flag parsing.
@@ -202,6 +216,7 @@
202216 echo " against generated C, not the Ruby source)" >&2
203217 echo " --cc=CMD C compiler (default: cc)" >&2
204218 echo " -e STR Inline Ruby source (repeatable; joined with newlines)" >&2
219+ echo " --rbs DIR Seed analyzer with RBS signatures from DIR (advisory)" >&2
205220 echo " --int-overflow=MODE Int +/-/* overflow handling (default: raise)" >&2
206221 exit 1
207222 fi
@@ -221,7 +236,20 @@
221236 else
222237 BASENAME="$(basename "$SOURCE" .rb)"
223238 fi
224-trap 'rm -f "$EVAL_TMP"; [ -n "$C_TMP_DIR" ] && rm -rf "$C_TMP_DIR"; [ -n "$RUN_TMP_DIR" ] && rm -rf "$RUN_TMP_DIR"' EXIT
239+trap 'rm -f "$EVAL_TMP" "$SEED_TMP"; [ -n "$C_TMP_DIR" ] && rm -rf "$C_TMP_DIR"; [ -n "$RUN_TMP_DIR" ] && rm -rf "$RUN_TMP_DIR"' EXIT
240+
241+# --rbs DIR: extract advisory type seeds from *.rbs in DIR and hand them to
242+# spinelc via SPINEL_RBS_SEED. A missing dir / unbuilt extractor / empty result
243+# is a silent no-op (spinel still compiles, just without seeds); the seeded
244+# types are advisory -- inference pins them but unseeded slots infer normally.
245+if [ -n "$RBS_DIR" ] && [ -x "$RBS_EXTRACT_BIN" ] && [ -d "$RBS_DIR" ]; then
246+ SEED_TMP="$(mktemp /tmp/spinel_seed.XXXXXX)"
247+ if "$RBS_EXTRACT_BIN" "$RBS_DIR" > "$SEED_TMP" && [ -s "$SEED_TMP" ]; then
248+ export SPINEL_RBS_SEED="$SEED_TMP"
249+ else
250+ rm -f "$SEED_TMP"; SEED_TMP=""
251+ fi
252+fi
225253
226254 # Source mapping: spinelc's parser stamps per-node source lines and codegen
227255 # emits `#line N "file"` when SPINEL_DEBUG / SPINEL_LINE_MAP is set, so a C