Commit 0041e8f0

0041e8f094afMerged

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

Description

spinelc: --emit-rbs (inferred type signatures as RBS)

Restores the legacy backend's RBS dump in the C driver. Gated on SPINEL_EMIT_RBS (set by spinel --emit-rbs), codegen walks the analyzed scopes/classes after analyze_program and writes a .rbs: top-level methods wrapped in class Object, then a class C < Parent block per user class with its @ivar: Type declarations and instance / self. method signatures, then short-circuits codegen (no binary).

ty_to_rbs_into maps the TyKind lattice to RBS (containers recurse via ty_array_elem / ty_hash_key/val; the boxed poly family and unknowns become untyped), and a method whose params/return widened to untyped gets the legacy "# spinel: widened to untyped (slow path)" comment.

make check: 846 pass, 0 fail.

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

Details

Commit
0041e8f094af
Parent
0c73e84ffa0e

spinelmodifiedView file

@@ -18,6 +18,7 @@
1818 # Options:
1919 # -o FILE Output file (binary, or C when combined with -c)
2020 # -c Generate C source only, don't compile
21+# --emit-rbs Dump inferred type signatures as RBS (-> app.rbs), no binary
2122 # --emit-symbol-map Dump emitted-symbol -> Ruby-name map as JSON, no binary
2223 # -S Print generated C to stdout
2324 # -E Run the compiled binary instead of saving it; the
@@ -52,6 +53,7 @@
5253 C_ONLY=0
5354 STDOUT_MODE=0
5455 RUN_MODE=0
56+EMIT_RBS=0
5557 EMIT_SYMBOL_MAP=0
5658 OPT_LEVEL="2"
5759 CC_CMD="cc"
@@ -117,6 +119,9 @@
117119 EVAL_USED=1
118120 shift ;;
119121 -c) C_ONLY=1; shift ;;
122+ --emit-rbs) # Dump inferred type signatures as RBS (-> app.rbs).
123+ # Analyze-only; writes no binary.
124+ EMIT_RBS=1; shift ;;
120125 --emit-symbol-map) # Dump emitted-C-symbol -> Ruby-name map as JSON
121126 # (-> app.symbols.json). Analyze-only; writes no binary.
122127 EMIT_SYMBOL_MAP=1; shift ;;
@@ -180,6 +185,7 @@
180185 echo "Options:" >&2
181186 echo " -o FILE Output file" >&2
182187 echo " -c C source only (don't compile)" >&2
188+ echo " --emit-rbs Dump inferred type signatures as RBS (-> app.rbs), no binary" >&2
183189 echo " --emit-symbol-map Dump emitted-symbol -> Ruby-name map as JSON, no binary" >&2
184190 echo " -S Print C to stdout" >&2
185191 echo " -E Run the compiled binary; leftover args become its ARGV" >&2
@@ -229,6 +235,20 @@
229235 export SPINEL_LINE_MAP=1
230236 fi
231237
238+# --emit-rbs: analyze-only. spinelc writes the .rbs itself (driven by
239+# SPINEL_EMIT_RBS) and emits an empty translation unit. No source positions
240+# needed, so the parser stays in its normal (fast) mode.
241+if [ "$EMIT_RBS" -eq 1 ]; then
242+ RBS_OUT="${OUTPUT:-$BASENAME.rbs}"
243+ export SPINEL_EMIT_RBS="$RBS_OUT"
244+ if ! "$SPINELC" "$SOURCE" >/dev/null; then
245+ echo "spinel: emit-rbs failed" >&2
246+ exit 1
247+ fi
248+ echo "Wrote $RBS_OUT" >&2
249+ exit 0
250+fi
251+
232252 # --emit-symbol-map: analyze-only. spinelc writes the JSON itself (driven by
233253 # SPINEL_EMIT_SYMBOL_MAP) and emits an empty translation unit; SPINEL_DEBUG
234254 # makes the parser stamp node positions so each symbol carries its file/line.