Skip to content

feat(call-graph): improve Tcl call extraction and namespace resolution (69.3% -> 95.2% precision, 90.0% recall) - #8915

Merged
squid-protocol merged 5 commits into
mainfrom
feat/tcl-call-graph-accuracy
Nov 22, 2026
Merged

squid-protocol merged 5 commits into
mainfrom
feat/tcl-call-graph-accuracy

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Comprehensive audit and improvement of the Tcl call graph (both Level 1 callee extraction and Level 2 namespace-qualified call resolution) across all 32 Tcl files (369 matched functions) in language-crucible/data/tcl.

Measured Accuracy & Resolution Impact (language-crucible/data/tcl)

Metric Before After Delta
Level 1 Precision 69.3% (684 FP) 95.2% (100 FP) +25.9 pp (-584 FP)
Level 1 Recall 69.3% (685 FN) 90.0% (219 FN) +20.7 pp (-466 FN)
Level 1 True Positives 1,546 1,980 +434 TP
Level 2 qualified edges 0 24 +24
Level 2 import edges 18 33 +15
Unresolved calls matching defined procs 42 1 -41 (97.6% resolved)

All 100 remaining FPs in the tree-sitter comparison are tree-sitter-tcl parse errors (ERROR nodes and misparsed foreach / ; statements); all remaining FNs are tree-sitter-tcl false parses of SQL queries, regexes, and switch pattern labels inside {...}.

Root Causes & Fixes

  1. Quoted command substitutions & multi-line strings (gitgalaxy/standards/language_standards/languages/tcl.py)
    • Added _expose_tcl_quoted_substitutions (_calls_out_pre_shield) to expose unescaped [...] command substitutions inside "..." strings (including nested "..." inside [...], e.g. ui_warn "[format [msgcat::mc \"...\"] $x]") before _apply_literal_shield blanks literals, while respecting \" / \[ / \\ escapes and cleanly blanking multi-line quoted strings (macports_registry/common.tcl).
  2. Structural Tcl call-extraction rewrite (gitgalaxy/standards/language_standards/languages/tcl.py)
    • Expanded _expose_switch_arms into _rewrite_tcl_calls (_calls_out_rewrite):
      • Joins \ + \n line continuations so continuation lines of global / set / commands are not scanned as new commands.
      • Blanks proc <name> {<args>} parameter lists (preventing default-value braces {version ""} {revision ""} from triggering } {) and exposes one-line proc bodies (proc puts {args} { uplevel ... }).
      • Fixes switch arm scanning when regex labels contain ] (e.g. portdepends.tcl).
      • Exposes one-line {body} blocks for foreach, lmap, after <ms|idle>, and uplevel <level>, while blanking braced data lists in foreach/lmap and braced data values in set.
    • Updated calls_out regex to support inline ; command separators, remove the overly broad (?<=[0-9]) lookbehind (which fired on calc_md5 {file}), tighten the trailing word boundary against :.$=,, and extract leaf callee names from ns::cmd / ::cmd (Contract C6).
  3. Namespace-qualified call resolution (gitgalaxy/core/detector.py, gitgalaxy/core/call_resolver.py)
    • Added calls_out_namespace_qualifiers handling in detector.py so Tcl emits leaf callees with ::ns qualifiers (and drops own-leaf recursion for qualified proc names).
    • Added "tcl" to _NAMESPACE_QUALIFIED_LANGS in call_resolver.py so portfetch::fetchfiles, receipt_flat::installed, and registry::run_target resolve accurately via qualified / import.
  4. Contract alignment & Golden Masters (tests/tools/call_graph_accuracy.py, tests/call_graph_accuracy_baseline.json, tests/golden_master_*)
    • Added "tcl" to CONTRACT_NON_CALLS (matching tcl.py's _calls_out_ignore + _CALLS_OUT_GLOBAL_IGNORE) and mapped Tcl's dedicated built-in AST nodes (set, expr_cmd, regexp) strictly for lang == "tcl".
    • Updated tests/call_graph_accuracy_baseline.json (tcl: 95.2% precision / 90.0% recall) and regenerated both tests/golden_master_audit/ and tests/golden_master_zero_dep_audit/ via tests/tools/box/golden-lock.sh python3.11 tests/tools/crucible_check.py --update --yes. All golden master diffs are strictly scoped to Tcl call-graph outputs (calls_out_to, fan_in, fan_out, import_edges, pagerank).
  5. Regression tests (tests/extraction/languages/test_calls_out_tcl.py)
    • Added 7 unit/integration tests covering all extracted Tcl shapes, namespace-qualified resolution, and ReDoS immunity.

Verification

  • pytest tests/extraction/languages/test_calls_out_tcl.py tests/extraction/languages/test_tcl.py tests/extraction/languages/test_tcl_strict.py tests/extraction/languages/test_calls_out_rewrite_5909.py tests/extraction/languages/test_calls_out_small_shapes_5640.py tests/extraction/languages/test_calls_out_keywords_3359.py tests/core_engine/test_call_resolver.py: 414 passed
  • pytest tests/test_source_reads.py: 3 passed
  • python3.11 tests/ruff_audit.py --ci: 0 new findings
  • python3.11 tests/tools/tree_sitter_accuracy_audit.py --ci --lang tcl: OK (matches baseline)
  • python3.11 tests/tools/call_graph_accuracy.py --ci: OK (0 regressions across all 25 languages)
  • tests/tools/box/golden-lock.sh python3.11 tests/tools/crucible_check.py --update --yes: Both full-precision and zero-dep Golden Masters updated cleanly

…ace resolution (69.3% -> 95.2% precision, 90.0% recall)
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol squid-protocol added the rosetta:rebless-owed Intentionally moves keyword-rosetta counts; audit warns, corpus re-blesses after merge label Nov 21, 2026
@squid-protocol
squid-protocol merged commit 4efbff0 into main Nov 22, 2026
72 checks passed
@squid-protocol
squid-protocol deleted the feat/tcl-call-graph-accuracy branch November 22, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rosetta:rebless-owed Intentionally moves keyword-rosetta counts; audit warns, corpus re-blesses after merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant