Commit 3b53a628

3b53a628b217Merged

Ori Pekelman <[email protected]> · 5 months ago · 5 files · ~5 modified

Description

Add spinel --emit-types: position-keyed inferred types + degrade diagnostics

Part 2 of the typing arc — the data backend for the ruby-lsp addon. Emits JSON: every node with a concrete inferred type keyed by source position (1-based line / 0-based col, matching Prism's node.location), plus a focused list of degrade diagnostics — methods whose signature widened to the boxed poly slow path, positioned at the def.

  • spinel_parse.c: emit node_col alongside node_line/node_file (Prism's line/column helper; column is concatenation-stable across require splicing).
  • compiler_helpers.rb: load node_col into a dedicated @nd_col slot.
  • spinel_analyze.rb: emit_types_json — per-node {file,line,col,type,rbs} from @nd_inferred_type + the position slots; diagnostics by matching each DefNode to its method via body-node id (the degrade lives in the signature tables, not the per-node cache, which holds context-specialised concrete types). Hand-rolled JSON (self-hosted subset has no stdlib json). Gated by SPINEL_EMIT_TYPES; positions need SPINEL_DEBUG, which the wrapper turns on.
  • spinel: --emit-types analyze-only mode -> app.types.json.

Verified: types JSON is valid, positions line up with Prism node starts, a param that widens across call sites yields one diagnostic at its def, clean programs yield none. Normal compile unaffected. ori fork (feat/typing).

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
3b53a628b217
Parent
40eca6faf074

compiler_helpers.rbmodifiedView file

@@ -468,6 +468,7 @@
468468 @nd_value.push(0)
469469 @nd_line.push(0) # keep the source-map arrays parallel with the rest, so a
470470 @nd_file.push(0) # dynamically-allocated node can't drift them out of sync
471+ @nd_col.push(0) # (and the self-host inferencer needs the literal push here)
471472 @nd_content.push("")
472473 @nd_flags.push(0)
473474 @nd_operator.push("")
@@ -532,6 +533,7 @@
532533 @nd_value = Array.new(n, 0)
533534 @nd_line = Array.new(n, 0)
534535 @nd_file = Array.new(n, 0)
536+ @nd_col = Array.new(n, 0)
535537 @nd_content = Array.new(n, "")
536538 @nd_flags = Array.new(n, 0)
537539 @nd_operator = Array.new(n, "")
@@ -680,6 +682,10 @@
680682 if field == "node_file"
681683 @nd_file[nid] = val
682684 end
685+ # Debug/types export: 0-based source column for hover position keys.
686+ if field == "node_col"
687+ @nd_col[nid] = val
688+ end
683689 end
684690
685691 # Debug multi-file map: record a FILE <id> <path> table entry emitted by