Skip to content

fix(cpp): reconcile proven declarations and definitions - #5117

Closed
xRedLeader wants to merge 6 commits into
Graphify-Labs:v8from
xRedLeader:codex/cpp-symbol-reconciliation-v105
Closed

xRedLeader wants to merge 6 commits into
Graphify-Labs:v8from
xRedLeader:codex/cpp-symbol-reconciliation-v105

Conversation

@xRedLeader

@xRedLeader xRedLeader commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

C++ forward declarations and out-of-line member definitions can appear as separate graph identities even when scanned headers establish that they refer to the same symbol. This reconciles only proven pairs and retains both source sites.

  • Fold a plain class/struct forward into its unique exactly qualified definition using unconditional, exactly resolved quoted-include evidence. Preserve folded locations in cpp_declaration_sites.
  • Fold matching, non-template zero-argument member declarations/definitions under a proven owner. Preserve the declaration ID, definition provenance and body calls. Retain unsupported syntax records so overloads and normalized-name collisions cannot accidentally qualify.
  • Keep CLI/watch updates correct after edits, exclusions, deletions and newly formed pairs. Support explicitly supplied files outside the cache anchor without discovering additional source files.

Verification

  • Python 3.10.11 and 3.13.15: 871 passed, 22 skipped each across the targeted C++, Objective-C, language-fixture, cross-repository and architecture tests. This includes a separately run fixed-path Swift test requiring filesystem permission.
  • Final typing-only follow-up: 78 passed on each version. Scoped Ruff and whitespace checks pass.
  • Targeted Pyright matches the upstream baseline of 238 existing diagnostics, with no additions; this is not a clean type-check claim.
  • A local 32-extraction matrix compared complete graph records across both Python versions, hash seeds, input order, worker count and cold/warm caches. Caller-ordered source inventories were checked separately.
  • Required graph self-update completed. The full suite was not run.

Focused commands:

python -m pytest tests/test_cpp_forward_declarations.py tests/test_cpp_member_declaration_identity.py -q
python -m pytest tests/test_languages.py tests/test_cross_repo_member_calls.py tests/test_architecture_doc.py -q
python -m pyright --pythonpath <venv-python> graphify/cli.py graphify/extract.py graphify/extractors/engine.py graphify/extractors/resolution.py graphify/watch.py --outputjson
python -m graphify update . --no-cluster

The broader run also enumerated all tests/test_cpp*.py and tests/test_objc*.py modules.

Boundaries

This independently targets v8 at 5eedffa8; it does not require the template or scoped-type PR. Shared-file overlaps and cache schema bumps need reconciliation when merging them together.

AST cache schema 47 retires stale records; rebuild existing graphs with graphify extract . --code-only --force.

Parameter-bearing members, templates/specializations, ambiguous definitions, conditional declarations, arbitrary include search paths and equivalent type spellings remain unresolved. A common third file including both class declarations alone does not establish equivalence. No compiler preprocessing or general overload resolution is introduced.

Review follow-up

  • 4d7d9487 strengthens the flagged incremental test to require the exact Use() -> Service.Run() call and source location, unchanged caller attributes, the correct class/method owner, and no empty endpoints. An unrelated surviving call can no longer satisfy acceptance.
  • Fresh targeted forward/member acceptance: 78 passed on Python 3.10 and 78 on 3.13. Four in-memory negative controls (wrong call target, wrong owner, changed caller, empty endpoint) are all rejected. Scoped Ruff, whitespace validation and the required graph refresh pass; no full suite was run locally.
  • The coupling scores identify maintenance cost but do not establish an incorrect dependency. _merge_cpp_forward_classes uses the existing exact-include, path and source-identity helpers for its proof and rewiring; its production behavior is unchanged. The integration test intentionally spans extraction, serialization and incremental merge. No forwarding abstractions, weakened checks or threshold changes were added to suppress the warnings.

Preserve all declaration sites and stable definition identities while keeping ambiguous scopes, definitions and conditions separate. Refresh the bounded source/proof group during CLI and watcher updates, including newly formed pairs.
Keep the declaration identity and both source sites when one owner, exact include evidence, and literal return, cv/ref and noexcept facts prove a unique pair. Rewire body calls and refresh member proof groups during incremental updates; retain overload and conditional uncertainty.
Reuse an existing member family only when its literal qualified identity matches the out-of-line definition. Keep both syntax records so return, const and noexcept mismatches remain visible without inferred definition provenance.
Keep distinct portable identities for explicitly supplied source files even when cache_root is elsewhere. Reject empty include-proof endpoints so unknown paths cannot establish symbol equivalence, and retain the permitted-corpus refresh gate.
Narrow the already-required parameter list before reading its byte range, and reflect nullable edge IDs in internal collection annotations. This removes the three introduced type diagnostics without changing reconciliation behavior.
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Thanks for the pull request, @xRedLeader. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 9, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 8 changed function(s) (1 sampled, not proven, 7 not verified).

Formal verification. PR-changed functions: 1/8 verified (0 proven, 1 may-equivalent, 0 distinguished) · 7 not verified (4 vacuous, 3 unsupported).

Not verified on this run: dispatch\_command (vacuous: never exercised), \_import\_c (vacuous: never exercised), extract (vacuous: never exercised), \_extract\_generic (unsupported), \_get\_cpp\_func\_name (vacuous: never exercised), \_merge\_decl\_def\_classes (unsupported), \_rebuild\_code (unsupported).


Graphify review — findings

Adds a C++ reconciliation pass that folds plain class/struct forward declarations into a unique, exactly qualified definition, and folds empty-parameter non-template member declaration/body pairs under one proven owner. Both folds need an exact, unconditional quoted-include proof (whole-file #ifndef/#define guards count) between the two files. The definition or declaration keeps its ID and source site, and the folded sites stay in metadata.cpp_declaration_sites or definition_file/definition_location. Ambiguous cases (multiple definitions or bodies, templates, overloads, conditional members, unrelated same-name files) stay separate. CLI and watch updates now track the source and include-proof files for each group, so editing, deleting or excluding one re-extracts the whole live group. New pairs refresh candidates from the unchanged corpus before the proof checks run. Bumps the AST cache schema to 47, which retires cached records without the class/member facts and include proofs. Existing graphs need graphify extract . --code-only --force to repopulate unchanged headers before changed-file-only updates can be relied on.

Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 6083 functions depend on the 1374 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1182 callers, 77 callees
  • worse: _rebuild_code() — 273 callers, 75 callees
  • worse: build_from_json() — 314 callers, 25 callees
  • worse: build_merge() — 118 callers, 18 callees
  • worse: dispatch_command() — 8 callers, 149 callees
  • worse: walk() — 1 callers, 87 callees
  • new: _merge_cpp_forward_classes() — 4 callers, 3 callees
  • new: test_changed_forward_rebuilds_only_its_group_and_preserves_incoming_edges() — 0 callers, 6 callees

Verification — 6083 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 5922 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

543 of 543 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety (noncode-change, uncovered-code) — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/pi.test.ts — full-run-safety
  • tests/test_4874_jvm_resolution.py — impact, full-run-safety
  • tests/test_4909_reference_binding_scale.py — impact, full-run-safety
  • tests/test_4978_reconcile_cost.py — impact, full-run-safety
  • tests/test_4992_ts_import_types.py — impact, full-run-safety
  • tests/test_5072_splittable_under_cap_retry.py — full-run-safety
  • tests/test_affected_cli.py — impact, full-run-safety
  • tests/test_affected_defines.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_affected_overrides.py — impact, full-run-safety
  • tests/test_affected_path_file_node.py — full-run-safety
  • tests/test_affected_seed_reference_forms.py — impact, full-run-safety
  • tests/test_agents_platform.py — impact, full-run-safety
  • tests/test_alias_folding.py — impact, full-run-safety
  • tests/test_analyze.py — impact, full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — impact, full-run-safety
  • tests/test_astro_import_ids.py — impact, full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_backend_opt_in.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_benchmark_real_query.py — full-run-safety
  • tests/test_binary_media_words.py — impact, full-run-safety
  • tests/test_blade_extractor.py — impact, full-run-safety
  • tests/test_build.py — impact, full-run-safety
  • tests/test_build_located_semantic_identity.py — impact, full-run-safety
  • tests/test_build_merge_dedup_scope.py — impact, full-run-safety
  • tests/test_build_merge_ghost_fold_4955.py — impact, full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — impact, full-run-safety
  • tests/test_build_merge_shrink_guard.py — impact, full-run-safety
  • tests/test_builtin_global_type_refs.py — impact, full-run-safety
  • tests/test_c_include_resolution.py — impact, full-run-safety
  • tests/test_cache.py — impact, full-run-safety
  • tests/test_cache_long_paths.py — impact, full-run-safety
  • tests/test_cache_stale_import_target.py — impact, full-run-safety
  • tests/test_cache_windows_case_4925.py — impact, full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — impact, full-run-safety
  • tests/test_case_only_decl_ids_4904.py — impact, full-run-safety
  • tests/test_case_sensitive_resolution.py — impact, full-run-safety
  • … and 493 more

non-code file(s) changed (ARCHITECTURE.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (ARCHITECTURE.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_import\_c.

The verifier did not have enough to check \_import\_c, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 264 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify extract.

The verifier did not have enough to check extract, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 90 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_get\_cpp\_func\_name.

The verifier did not have enough to check \_get\_cpp\_func\_name, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 230 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_merge\_decl\_def\_classes.

The verifier did not have enough to check \_merge\_decl\_def\_classes, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: the input domain has 81 values but only 11 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)

No difference found (not proven): No behavior difference found in \_rebase\_relative\_source\_files (not a proof).

The verifier ran both versions of \_rebase\_relative\_source\_files on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify \_rebuild\_code.

The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function

· 2 grounded finding(s) anchored inline below; 6 more finding(s) on lines outside this diff (see the check run).

return []


def _merge_cpp_forward_classes(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — _merge_cpp_forward_classes()

high coupling complexity (Ca·Ce = 12).

Grounded coupling-delta finding (deterministic), not an LLM guess.

assert len(_classes(result)) == 2


def test_changed_forward_rebuilds_only_its_group_and_preserves_incoming_edges(tmp_path):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — test_changed_forward_rebuilds_only_its_group_and_preserves_incoming_edges()

fans out to 6 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

safishamsi added a commit that referenced this pull request Nov 10, 2026
… trio

#5113 (Python subscript generic-arg count) and #5117/#5118/#5115 (C++ decl/def
reconcile, scoped aliases + inherited receivers, template ownership + guarded
initializers) all change per-file extractor output and land in one window, so
they share a single bump to 43 chained over prior (42).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 and shipped in 0.9.106 (now on PyPI), cherry-picked with -x so your commits keep their authorship. This C++ trio co-landed in order #5117 -> #5118 -> #5115; merge-time adjustments were the shared schema bump to 43 (your branch targeted a higher number) and, where the three overlapped, a reconciliation of the engine binding core: the _cpp_local_binding_ranges tuple now carries both #5118's lexical lookup scope and #5115's qualified name + dependent flag, with the readers updated, plus a dedupe of _cpp_is_header_guard and a union of the persisted C++ marker lists. Verified green afterward: the full C++ suite (443 tests, including the #5098/#4916/#4946 regression files) passes. Thanks @xRedLeader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants