Commit 164ce350
164ce35025dbMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Map C compile errors back to Ruby source lines via #line, on by default
When the generated C was ill-typed, the C compiler's error referenced the
generated out.c (e.g. out.c:72: invalid operands to binary <<) with no
path back to the user's Ruby. Emit #line N "src.rb" directives in normal
optimized builds so the toolchain attributes any compile error to the Ruby
source line instead:
before: out.c:72:19: error: invalid operands to binary << (have 'sp_Set' ...) after: app.rb:6:19: error: invalid operands to binary << (have 'sp_Set' ...)
This reuses the same #line machinery --debug already emits, decoupled from --debug's -O0 / non-inlined / -g cost: the directives are a front-end-only diagnostic, so the optimizer never sees them and the binary is identical modulo line attribution. On by default (no runtime cost, only larger generated C); opt out with --no-line-map.
Coverage: #line reaches the statement stream, so it maps expression-level errors. Errors emitted in the hoisted struct/typedef region (unknown stdlib type, builtin struct redefinition) still report against the generated C and want emit-time guards instead. The line is exact; the column is the C column relabeled onto the Ruby line (approximate in Ruby terms).
Validated: make check (844 pass), optcarrot (checksum 59662), make bench (57 pass); generated C is byte-identical modulo #line lines.
Refs #1338
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 164ce35025db
- Parent
- 1f054fd8169c
spinelmodifiedView file
EMIT_TYPES=0STDOUT_MODE=0RUN_MODE=0# #line directives are on by default: they cost nothing at runtime (purely a# diagnostic directive; the binary is identical modulo line attribution) and# let the C toolchain report any compile error on the generated C against the# Ruby source line. Opt out with --no-line-map.LINE_MAP=1OPT_LEVEL="2"CC_CMD="cc"EXTRA_FLAGS="" # the default -O2 gives lossy DWARF; use --debug for # faithful stepping). DEBUG=1; shift ;; --line-map) # Emit `#line` directives so a compile error on the # generated C is reported against the Ruby source line, # without --debug's -O0 / non-inlined / -g cost. On by # default; this flag is kept for explicitness. LINE_MAP=1; shift ;; --no-line-map) # Suppress #line directives (smaller generated C; compile # errors report against out.c instead of the Ruby source). LINE_MAP=0; shift ;; -e) shift if [ "$EVAL_USED" -eq 0 ]; then EVAL_SCRIPT="$1" echo " --debug Debug build: step through the .rb in gdb/lldb" >&2 echo " (emits #line, keeps methods non-inlined, -g -O0)" >&2 echo " -g Add debug info + #line without forcing -O0" >&2 echo " --no-line-map Suppress #line directives (smaller C; compile errors" >&2 echo " report 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# Debug mode signal, read by the parser (per-node line stamps) and the# codegen (#line emission + non-inlined methods). Must be exported# before the parse step below since spinel_parse reads it at init.# --line-map: stamp #line directives (parser + codegen) for Ruby-mapped# compile errors, but keep the normal optimized build (no -O0/-g/-rdynamic).# --debug implies it; SPINEL_DEBUG already turns on the same #line path.if [ "$LINE_MAP" -eq 1 ] && [ "$DEBUG" -eq 0 ]; then export SPINEL_LINE_MAP=1fiif [ "$DEBUG" -eq 1 ]; then export SPINEL_DEBUG=1 EXTRA_FLAGS="$EXTRA_FLAGS -g"spinel_codegen.rbmodifiedView file
Loading diff…
spinel_parse.cmodifiedView file
Loading diff…