Commit 7ae3c481
7ae3c4810fedMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add --emit-symbol-map: export emitted-symbol -> Ruby-name map as JSON
Opt-in, output-neutral sidecar (sibling to --emit-rbs #1276 / --emit-types #1298) serializing the compiler's emitted C symbol -> Ruby method-name mapping, with kind and source position:
spinel app.rb --emit-symbol-map -o app.symbols.json { "symbols": [ { "c": "sp_Article_save", "ruby": "Article#save", "kind": "imeth", "file": "app.rb", "line": 42 }, ... ] }
Built in codegen (emit_symbol_map_json), where the name-mangling
(sanitize_name, the sp__ shape) lives, so the map can't drift
from what is emitted -- the point of the RFC for out-of-process tools,
kept true internally. The ruby field is the original method name, so
predicate/bang/operator methods are exact (save? / <=> / []), which the
runtime sp_bt_symbol demangler (#1300) cannot reverse from the one-way
sanitized C form. The class path demangles _ -> :: like sp_bt_symbol
(the one shared lossy case); position-less synthetic/builtin methods come
through with file/line null.
Gated by SPINEL_EMIT_SYMBOL_MAP; release builds unchanged. The launcher flag runs codegen (the mangling lives there) but emits no binary.
Refs #1334
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 7ae3c4810fed
- Parent
- 1f054fd8169c
spinelmodifiedView file
C_ONLY=0EMIT_RBS=0EMIT_TYPES=0EMIT_SYMBOL_MAP=0STDOUT_MODE=0RUN_MODE=0OPT_LEVEL="2" # diagnostics as JSON (for the ruby-lsp addon). Needs node # positions, so it turns on SPINEL_DEBUG below. EMIT_TYPES=1; DEBUG=1; shift ;; --emit-symbol-map) # Dump emitted-symbol -> Ruby-name map as JSON (#1334). # Runs codegen (the mangling lives there) but writes no # binary. DEBUG on so node positions (file/line) are stamped. EMIT_SYMBOL_MAP=1; DEBUG=1; shift ;; -S) STDOUT_MODE=1; shift ;; -E) RUN_MODE=1; shift ;; *.rb) exit 0fi# --emit-symbol-map needs codegen (the C name-mangling lives there) but emits# no binary: run codegen with SPINEL_EMIT_SYMBOL_MAP set, route the C output# to a temp, and stop.if [ "$EMIT_SYMBOL_MAP" -eq 1 ]; then SYM_OUT="${OUTPUT:-$BASENAME.symbols.json}" export SPINEL_EMIT_SYMBOL_MAP="$SYM_OUT" SYM_C_TMP="$(mktemp /tmp/spinel_symc.XXXXXX)" if [ -x "$CODEGEN_BIN" ]; then "$CODEGEN_BIN" "$AST_TMP" "$IR_TMP" "$SYM_C_TMP" else ruby "$CODEGEN_RB" "$AST_TMP" "$IR_TMP" "$SYM_C_TMP" fi cg_rc=$? rm -f "$SYM_C_TMP" if [ $cg_rc -ne 0 ]; then echo "spinel: codegen failed" >&2 exit 1 fi echo "Wrote $SYM_OUT" >&2 exit 0fi# Step 3: Codegenif [ $STDOUT_MODE -eq 1 ]; then if [ -x "$CODEGEN_BIN" ]; thenspinel_codegen.rbmodifiedView file
Loading diff…