Skip to content

C/C++ call-graph oracle: tree-sitter body oracle + family consensus, 20-port baseline (Part of #5630) - #5690

Merged
squid-protocol merged 2 commits into
mainfrom
feat/5630-callgraph-oracle
Oct 20, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
feat/5630-callgraph-oracle

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #5630

What

tests/tools/doom_speedrun/callgraph_oracle.py is a validation tool for C/C++ calls_out_to. Until now these edges had no independent check: the Graph Accuracy Audit covers only Python, TypeScript and Java. It reads the scans that doom_speedrun.py scan leaves and runs on licensed ports only (the LICENSED set refuses any other port). It is built from the doom-study prototypes (consensus.py, callcheck.py, cxx_cats2.py).

  1. Body oracle (tree-sitter). Each engine function is matched to the function_definition at its start line. Every call_expression whose callee the port defines counts as an oracle call.
    • Misses are named by the call's shape: statement, nested-argument, condition/return, assignment-rhs, after-cast, after-operator, subscript, unparsed.
    • Engine-only edges are named by how the callee appears in the body: function-pointer, type (a C++ class used as a type: new T, T x(...)), macro, comment/string, absent.
    • Fallbacks for tree-sitter's preprocessor misparses:
      • an #ifdef-split else if is read by a text fallback;
      • a function swallowed by a macro table is read by brace matching;
      • a body closed early by error recovery is read by brace matching when it holds an ERROR node.
  2. Family consensus. The nine vanilla-lineage ports vote on each other's edges (quorum 75%, at least 3 holders). A missing edge is looked up in the port's body: if the call is there, it is an engine miss; otherwise it is a real divergence. A lone edge whose callee is not in the body is a false-edge suspect.
  3. Gate. --only all --baseline tests/tools/doom_speedrun/callgraph_baseline.json --fail-on-regression exits 1 in any of these cases:
    • a port's recall or precision drops by more than 0.001;
    • a baseline port is missing;
    • the consensus engine-miss count or false-edge count grows.

Baseline (engine 4248895, 20 licensed C/C++ ports)

Port Recall Precision Oracle calls Misses by shape Engine-only by kind Text fallback
chocolate-doom 1.0000 1.0000 12132 - - 13
crispy-doom 1.0000 1.0000 14043 - - 13
doom-ascii 1.0000 1.0000 1980 - - 0
doom-wasm 1.0000 1.0000 4069 - - 5
doom3-bfg 0.9995 0.9772 47954 statement 1, unparsed 21 absent 339, comment/string 1, function-pointer 21, macro 4, type 754 590
doomgeneric 1.0000 1.0000 2163 - - 0
doomretro 0.9996 1.0000 6871 statement 3 - 19
dsda-doom 0.9978 0.9992 10775 assignment-rhs 4, nested-argument 1, statement 19 absent 2, function-pointer 3, type 4 3
edge-classic 0.9844 0.9747 10702 after-cast 1, after-operator 10, assignment-rhs 27, condition/return 10, nested-argument 6, other 2, statement 48, unparsed 63 absent 144, function-pointer 3, type 127 29
eternity 0.9982 0.9769 15826 statement 10, unparsed 18 absent 174, comment/string 1, function-pointer 65, type 134 485
fastdoom 0.9997 0.9997 2885 nested-argument 1 function-pointer 1 0
gzdoom 0.9865 0.9483 43247 after-cast 1, after-operator 12, assignment-rhs 84, condition/return 39, nested-argument 15, other 5, statement 261, unparsed 165 absent 810, function-pointer 238, type 1280 579
inter-doom 1.0000 1.0000 13640 - - 8
linuxdoom 1.0000 1.0000 1597 - - 0
nugget-doom 1.0000 0.9977 8967 - macro 21 10
odamex 0.9981 0.9673 20129 after-operator 13, assignment-rhs 6, nested-argument 7, other 2, statement 10 absent 310, comment/string 1, function-pointer 58, macro 9, type 302 288
prboom-plus 1.0000 0.9993 4603 - absent 2, type 1 1
puredoom 1.0000 1.0000 3733 - - 0
sdl-doom 1.0000 1.0000 2083 - - 0
woof 1.0000 0.9990 8148 - function-pointer 7, macro 1 4

Family consensus (9 vanilla-lineage ports, quorum 75%): holes 321, engine missed 2 (crispy-doom 1, inter-doom 1; shape function-pointer 2), real divergence 319, false-edge suspects 0.

The run takes about 60 s over all 20 ports. Three back-to-back runs gave byte-identical output.

Class sweep

The class is C/C++ call edges with no independent reference. Findings at 4248895:

Shape Where (licensed ports) Status
Callee passed as a function pointer is not an edge R_PointToAngle -> SlopeDiv in crispy-doom, inter-doom (the 2 consensus engine misses) engine miss, open
Destructor head counted as a call to its own class prboom-plus scanner.cpp:81 ~Scanner -> Scanner, scanner.h:66 ~ParserState -> ParserState, the same in gzdoom engine false edge, open
Function end truncated in a ~1950-line switch function dsda-doom p_spec.c:5788 P_ExecuteZDoomLineSpecial: engine loc is 1427, the span has 1786 non-blank lines, and every call after line ~7215 is missed (EV_Light*, P_SpawnProjectile, ...) engine miss, open (cause not yet read)
Macro-like callees missed in C++ gzdoom IFVIRTUALPTRNAME / IFVM bodies, MOODYCAMEL_CONSTEXPR_IF to triage
C++ class used as a type (new T, T x(...)) emitted as a call doom3-bfg, gzdoom, eternity, odamex, edge-classic (the type column) engine design choice: constructor edges. Reported, not scored as wrong
absent engine-only edges C++ ports above to triage; mostly constructor and overload names

Sibling gaps

No burned-estate program needs any of these: the burned estates are COBOL/CICS, and none of these touch the mainframe proofs.

Remaining slices

  1. Nightly wiring (needs DOOM-rosetta: golden-gated CI regression test over the DOOM port corpus (measurements-only golden, zero drift, sharded, nightly oracles) #5619): scan the baseline's ports, then the gate command.
  2. Triage the C++ absent / unparsed buckets in gzdoom, doom3-bfg, eternity and odamex. The text-fallback counts there (290 to 590 functions) are the oracle's own weak spot.
  3. Engine fixes for the three open shapes, each re-blessing the baseline with the drift explained.
  4. Extend the oracle beyond C/C++ (sibling gaps).

Gates

  • pr_gates.py --fast: 6/6 pass, with CI ruff 0.16.10 and mypy 2.4.0.
  • pr_gates.py --ratchets: 8/8 pass, including time.
  • audit_check.py: ruff, dead-key and ast-accuracy pass. The selfscan venv's mypy reports 16 findings, all in files this PR does not touch. The CI mypy (pr_gates audits) passes.
  • New tests: 11 in tests/tools/test_callgraph_oracle.py, synthetic sources only. They pass under plain pytest from /tmp. test_source_reads.py and test_doom_speedrun.py pass.
  • No parsing code changed, so no golden bless.

Lessons for agents

  • tree-sitter 0.26 Python bindings: read a position as node.start_point[0], never node.start_point.row. The attribute read on the temporary Point corrupts the heap. The crash surfaces later in an unrelated allocation (PyObject_Malloc via PyLong_FromVoidPtr) and disappears under PYTHONMALLOC=debug, so it looks like a flake. A/B on the same harness: .row segfaulted 3 of 3 runs, [0] passed 3 of 3. Swapping Node.text for slicing, caching the parser and changing the decoder did not help.
  • A tree-sitter body can close early. Error recovery around a bare macro statement with no ; closes the function_definition before its real }, which silently drops calls. Check for an ERROR node and compare with brace matching.

🤖 Generated with Claude Code

squid-protocol and others added 2 commits October 19, 2026 22:31
…ine (Part of #5630)

tests/tools/doom_speedrun/callgraph_oracle.py checks calls_out_to on the licensed
DOOM C/C++ ports two ways: a tree-sitter body oracle (misses by call shape, engine-only
edges by how the callee appears: function-pointer / type / macro / comment-string /
absent) with text and brace fallbacks for preprocessor misparses, and vanilla-family
consensus. --only all, --write-baseline and --baseline --fail-on-regression are the
hook for the DOOM-rosetta nightly (#5619). The baseline covers 20 ports at 4248895.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@squid-protocol

Copy link
Copy Markdown
Owner Author

No description provided.

@squid-protocol
squid-protocol marked this pull request as ready for review October 20, 2026 03:07
@squid-protocol
squid-protocol merged commit 350f452 into main Oct 20, 2026
47 checks passed
@squid-protocol
squid-protocol deleted the feat/5630-callgraph-oracle branch October 20, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant