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
# generated C, not the Ruby source)# --cc=CMD C compiler command (default: cc)# -e STR Inline Ruby source (repeatable; multiple -e join with \n)# --rbs DIR Seed the analyzer with advisory RBS signatures from DIR# --int-overflow=MODE Int +/-/* overflow handling (default: raise)# raise | wrap | promote ;;esac# RBS seed extractor (built by `make`); used by --rbs to turn a dir of *.rbs# into advisory type seeds for the analyzer.RBS_EXTRACT_BIN="$DIR/spinel_rbs_extract"case "$(uname -s 2>/dev/null)" in MINGW*|MSYS*|CYGWIN*) [ ! -x "$RBS_EXTRACT_BIN" ] && [ -x "$RBS_EXTRACT_BIN.exe" ] && RBS_EXTRACT_BIN="$RBS_EXTRACT_BIN.exe" ;;esacSOURCE=""OUTPUT=""C_ONLY=0EVAL_SCRIPT=""EVAL_USED=0EVAL_TMP=""RBS_DIR=""SEED_TMP=""INT_OVERFLOW="raise"DEBUG=0# #line directives are on by default: they cost nothing at runtime (the binary --source=*) SOURCE="${1#--source=}"; shift ;; --output=*) OUTPUT="${1#--output=}"; shift ;; --cc=*) CC_CMD="${1#--cc=}"; shift ;; --rbs=*) RBS_DIR="${1#--rbs=}"; shift ;; --rbs) shift; RBS_DIR="$1"; shift ;; --int-overflow=*) INT_OVERFLOW="${1#--int-overflow=}"; shift ;; --int-overflow) shift; INT_OVERFLOW="$1"; shift ;; --) # `--` ends spinel-flag parsing. echo " against generated C, not the Ruby source)" >&2 echo " --cc=CMD C compiler (default: cc)" >&2 echo " -e STR Inline Ruby source (repeatable; joined with newlines)" >&2 echo " --rbs DIR Seed analyzer with RBS signatures from DIR (advisory)" >&2 echo " --int-overflow=MODE Int +/-/* overflow handling (default: raise)" >&2 exit 1fielse BASENAME="$(basename "$SOURCE" .rb)"fitrap 'rm -f "$EVAL_TMP"; [ -n "$C_TMP_DIR" ] && rm -rf "$C_TMP_DIR"; [ -n "$RUN_TMP_DIR" ] && rm -rf "$RUN_TMP_DIR"' EXITtrap '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# --rbs DIR: extract advisory type seeds from *.rbs in DIR and hand them to# spinelc via SPINEL_RBS_SEED. A missing dir / unbuilt extractor / empty result# is a silent no-op (spinel still compiles, just without seeds); the seeded# types are advisory -- inference pins them but unseeded slots infer normally.if [ -n "$RBS_DIR" ] && [ -x "$RBS_EXTRACT_BIN" ] && [ -d "$RBS_DIR" ]; then SEED_TMP="$(mktemp /tmp/spinel_seed.XXXXXX)" if "$RBS_EXTRACT_BIN" "$RBS_DIR" > "$SEED_TMP" && [ -s "$SEED_TMP" ]; then export SPINEL_RBS_SEED="$SEED_TMP" else rm -f "$SEED_TMP"; SEED_TMP="" fifi# Source mapping: spinelc's parser stamps per-node source lines and codegen# emits `#line N "file"` when SPINEL_DEBUG / SPINEL_LINE_MAP is set, so a Csrc/analyze.cmodifiedView file
Loading diff…
src/analyze_internal.hmodifiedView file
Loading diff…
src/analyze_pass.cmodifiedView file
Loading diff…
src/analyze_scope.cmodifiedView file
Loading diff…
src/compiler.cmodifiedView file
Loading diff…
src/compiler.hmodifiedView file
Loading diff…