Commit 62575f90

62575f90e417Merged

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

Description

spinelc: --emit-types (position-keyed types + diagnostics JSON)

Restores the legacy backend's ruby-lsp export in the C driver. Gated on SPINEL_EMIT_TYPES (set by spinel --emit-types), codegen emits

{"types":[{file,line,col,type,rbs}...], "diagnostics":[{file,line,col,severity,message}...]}

after analyze_program, then short-circuits codegen. types lists every node with a concrete inferred type keyed by its parser-stamped position (SPINEL_DEBUG, which the driver enables); type is the legacy tag (objects spelled obj_) and rbs its RBS form. diagnostics warns once per method whose signature widened to the boxed poly slow path -- detected directly off each Scope (its def_node gives the position), so the C path skips the legacy body-id matching dance.

make check: 846 pass, 0 fail.

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

Details

Commit
62575f90e417
Parent
0041e8f094af

spinelmodifiedView file

@@ -19,6 +19,7 @@
1919 # -o FILE Output file (binary, or C when combined with -c)
2020 # -c Generate C source only, don't compile
2121 # --emit-rbs Dump inferred type signatures as RBS (-> app.rbs), no binary
22+# --emit-types Dump per-position inferred types + diagnostics as JSON, no binary
2223 # --emit-symbol-map Dump emitted-symbol -> Ruby-name map as JSON, no binary
2324 # -S Print generated C to stdout
2425 # -E Run the compiled binary instead of saving it; the
@@ -54,6 +55,7 @@
5455 STDOUT_MODE=0
5556 RUN_MODE=0
5657 EMIT_RBS=0
58+EMIT_TYPES=0
5759 EMIT_SYMBOL_MAP=0
5860 OPT_LEVEL="2"
5961 CC_CMD="cc"
@@ -122,6 +124,9 @@
122124 --emit-rbs) # Dump inferred type signatures as RBS (-> app.rbs).
123125 # Analyze-only; writes no binary.
124126 EMIT_RBS=1; shift ;;
127+ --emit-types) # Dump per-position inferred types + degrade diagnostics as
128+ # JSON (for the ruby-lsp addon). Analyze-only; writes no binary.
129+ EMIT_TYPES=1; shift ;;
125130 --emit-symbol-map) # Dump emitted-C-symbol -> Ruby-name map as JSON
126131 # (-> app.symbols.json). Analyze-only; writes no binary.
127132 EMIT_SYMBOL_MAP=1; shift ;;
@@ -186,6 +191,7 @@
186191 echo " -o FILE Output file" >&2
187192 echo " -c C source only (don't compile)" >&2
188193 echo " --emit-rbs Dump inferred type signatures as RBS (-> app.rbs), no binary" >&2
194+ echo " --emit-types Dump per-position inferred types + diagnostics as JSON" >&2
189195 echo " --emit-symbol-map Dump emitted-symbol -> Ruby-name map as JSON, no binary" >&2
190196 echo " -S Print C to stdout" >&2
191197 echo " -E Run the compiled binary; leftover args become its ARGV" >&2
@@ -249,6 +255,21 @@
249255 exit 0
250256 fi
251257
258+# --emit-types: analyze-only. Per-node types are keyed by source position, so
259+# SPINEL_DEBUG makes the parser stamp node line/col/file. spinelc writes the
260+# JSON (driven by SPINEL_EMIT_TYPES) and emits an empty translation unit.
261+if [ "$EMIT_TYPES" -eq 1 ]; then
262+ TYPES_OUT="${OUTPUT:-$BASENAME.types.json}"
263+ export SPINEL_DEBUG=1
264+ export SPINEL_EMIT_TYPES="$TYPES_OUT"
265+ if ! "$SPINELC" "$SOURCE" >/dev/null; then
266+ echo "spinel: emit-types failed" >&2
267+ exit 1
268+ fi
269+ echo "Wrote $TYPES_OUT" >&2
270+ exit 0
271+fi
272+
252273 # --emit-symbol-map: analyze-only. spinelc writes the JSON itself (driven by
253274 # SPINEL_EMIT_SYMBOL_MAP) and emits an empty translation unit; SPINEL_DEBUG
254275 # makes the parser stamp node positions so each symbol carries its file/line.