Commit 5a899bc3
5a899bc3c3f8Merged
Ori Pekelman <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add spinel --emit-rbs: export inferred signatures as RBS
Roadmap item 3 of the typing arc. Makes the whole-program inference visible:
dump every method/class signature the analyzer inferred as RBS, feeding
Steep/Sorbet/ruby-lsp and doubling as a silent-miscompile diagnostic — you
can see where a slot came out untyped (the boxed poly slow path).
- spinel_analyze.rb: type_to_rbs (inverts spinel_rbs_extract's RBS->tag
mapping; recursive for
?, obj_ptr_array, tuple:) + emit_rbs, which walks the same signature tables emit_poly_report uses (@meth, @cls_*). Top-level defs wrap inclass Object(valid RBS); poly-degraded params /returns renderuntypedwith a trailing# spinel: widened to untyped (slow path)comment. Injected builtinMethodis filtered. Gated by SPINEL_EMIT_RBS (written after analyze_phase; IR still emitted). - spinel:
--emit-rbsanalyze-only mode -> app.rbs (or -o path), no binary.
Verified: emitted RBS passes rbs validate; a class + top-level methods
render correct signatures; a return that unifies int|string shows
-> untyped with the degrade comment. Normal compile unaffected (env-gated).
On the ori fork (feat/typing); no PR to matz/spinel.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 5a899bc3c3f8
- Parent
- 63f7f4505469
spinelmodifiedView file
@@ -43,6 +43,7 @@
4343
SOURCE=""4444
OUTPUT=""4545
C_ONLY=046+
EMIT_RBS=04647
STDOUT_MODE=04748
RUN_MODE=04849
OPT_LEVEL="2"@@ -107,6 +108,8 @@
107108
EVAL_USED=1108109
shift ;;109110
-c) C_ONLY=1; shift ;;111+
--emit-rbs) # Analyze-only: dump inferred signatures as RBS, no binary.112+
EMIT_RBS=1; shift ;;110113
-S) STDOUT_MODE=1; shift ;;111114
-E) RUN_MODE=1; shift ;;112115
*.rb)@@ -145,6 +148,23 @@
145148
fi146149
fi147150
151+
# --emit-rbs is analyze-only (stops before codegen), so the binary/C-output152+
# modes would be silently ignored alongside it — reject the conflict up front.153+
if [ "$EMIT_RBS" -eq 1 ]; then154+
if [ "$RUN_MODE" -eq 1 ]; then155+
echo "spinel: --emit-rbs cannot be combined with -E (run)" >&2156+
exit 2157+
fi158+
if [ "$C_ONLY" -eq 1 ]; then159+
echo "spinel: --emit-rbs cannot be combined with -c (C source only)" >&2160+
exit 2161+
fi162+
if [ "$STDOUT_MODE" -eq 1 ]; then163+
echo "spinel: --emit-rbs cannot be combined with -S (stdout)" >&2164+
exit 2165+
fi166+
fi167+
148168
# `-e` mode: write the accumulated inline script to a temp file and149169
# treat it as the source. Default output name is `a` since the150170
# inline form has no .rb basename to derive from. If both -e and a@@ -173,6 +193,7 @@
173193
echo "Options:" >&2174194
echo " -o FILE Output file" >&2175195
echo " -c C source only (don't compile)" >&2196+
echo " --emit-rbs Dump inferred type signatures as RBS (-> app.rbs), no binary" >&2176197
echo " -S Print C to stdout" >&2177198
echo " -E Run the compiled binary; leftover args become its ARGV" >&2178199
echo " -O LEVEL Optimization level (default: 2)" >&2@@ -239,6 +260,12 @@
239260
# int locals as bigint when mode == promote. Raise / wrap modes240261
# only care about the cc-time preprocessor switch added below.241262
export SPINEL_INT_OVERFLOW="$INT_OVERFLOW"263+
# RBS export mode: tell the analyzer to also dump inferred signatures.264+
# (Conflicting-mode checks are done up front with the other mode-conflict guards.)265+
if [ "$EMIT_RBS" -eq 1 ]; then266+
RBS_OUT="${OUTPUT:-$BASENAME.rbs}"267+
export SPINEL_EMIT_RBS="$RBS_OUT"268+
fi242269
if [ -x "$ANALYZE_BIN" ]; then243270
"$ANALYZE_BIN" "$AST_TMP" "$IR_TMP" $SEED_TMP244271
else@@ -249,6 +276,12 @@
249276
exit 1250277
fi251278
279+
# --emit-rbs is analyze-only: the signatures are written, stop before codegen.280+
if [ "$EMIT_RBS" -eq 1 ]; then281+
echo "Wrote $RBS_OUT" >&2282+
exit 0283+
fi284+
252285
# Step 3: Codegen253286
if [ $STDOUT_MODE -eq 1 ]; then254287
if [ -x "$CODEGEN_BIN" ]; thenspinel_analyze.rbmodifiedView file
Loading diff…