Skip to content

fix(cpp): resolve scoped aliases and inherited member receivers - #5118

Closed
xRedLeader wants to merge 9 commits into
Graphify-Labs:v8from
xRedLeader:codex/cpp-scoped-types-v105
Closed

xRedLeader wants to merge 9 commits into
Graphify-Labs:v8from
xRedLeader:codex/cpp-scoped-types-v105

Conversation

@xRedLeader

@xRedLeader xRedLeader commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

C++ member calls through ordinary aliases or inherited fields can lose their static receiver type, or fall through to an unrelated same-name method. This adds conservative scope- and include-aware lookup using persisted AST facts, shared by fresh extraction and incremental CLI/watch updates.

  • Resolve ordinary using/typedef aliases in their declaration scope, including raw pointers and supported std::unique_ptr/std::shared_ptr forms. Unknown aliases still shadow outer declarations.

  • Resolve inherited fields and methods only along an unambiguous static member path. Preserve name hiding and refuse ambiguous diamonds, unsupported bases and overload families.

  • Bind field spelling at its declaration, then require a unique complete type visible at the call site. This supports the normal forward-declared-pointee/header pattern without binding definitions from unrelated files or after the call.

  • Retain named enclosing lookup scopes inside anonymous namespaces for both receiver chains and scoped static calls. Keep anonymous type identities unknown and preserve shadowing barriers.

  • Bound alias and inheritance traversal, memoize repeated include/member lookup, and retain facts for changed-file CLI/watch updates.

  • Normalize C++ CRLF input to LF before parsing, so persisted lookup offsets and call sites use the same coordinates across Windows and Unix checkouts. Source files are not rewritten.

Verification

  • GitHub CI passed all seven jobs on d84b82bd, including Python 3.10, 3.12, 3.13, and 3.14.
  • Python 3.10.11 and 3.13.15: 359 targeted tests passed on each interpreter across all C++ modules, graph invariance, and the AST cache. The first sandboxed run passed 358 tests; its Windows junction test passed separately outside the sandbox.
  • Both CI-reported LF/CRLF graph-invariance failures reproduced before the fix. The complete 12-case invariance module now passes, including clustered/unclustered graphs, relocated checkouts, and rebuilds. No comparison fields were excluded.
  • Four new cases compare complete per-file extraction and resolved nodes/edges for CRLF and mixed newlines, with and without a final newline. They cover Unicode before stored positions, cold/warm caches, inherited fields, block aliases, rejected late includes, and unknown-alias shadowing. All four failed before the fix.
  • Python 3.13 encoding and grammar-cache checks: 45 passed, 1 skipped.
  • Scoped Ruff and whitespace checks pass. Required AST-only graph refresh completed.
  • Earlier committed evidence at f65022a7 included the 32-extraction determinism matrix and combined testing with fix(cpp): preserve template ownership and guarded initializer calls #5115/fix(cpp): reconcile proven declarations and definitions #5117. Those broader experiments were not repeated for this follow-up. The existing touched-source Pyright baseline and previously reproduced Windows CLI exclusion failure remain as documented in the prior review.

Focused PowerShell commands:

$cppTests = (Get-ChildItem tests -File -Filter 'test_cpp*.py').FullName
python -m pytest @cppTests tests/test_graph_invariance.py tests/test_cache.py -q
python -m pytest tests/test_source_file_encoding.py tests/test_grammar_cache_key.py -q
python -m graphify update . --no-cluster

The local full suite was not run. GitHub's existing CI completed successfully on the updated PR.

Boundaries

This independently targets v8 at 5eedffa8; it requires neither the template nor symbol-reconciliation PR. Shared-file overlaps and cache schema bumps need reconciliation when merging them together.

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

No compiler/build-configuration integration, arbitrary template instantiation, overload resolution, custom smart pointers or runtime virtual-dispatch inference is introduced. The new alias/inheritance paths decline dependent, cyclic, unknown or ambiguous targets. Alias and inheritance traversal are capped at 32. New guarantees apply to explicit receivers and field chains; unqualified bare calls retain the existing lexical resolver. Block-local class identity is not modeled; includes inside scopes are not used as global type-visibility proof.

Persist lexical type declarations and include positions so ordinary aliases resolve only in their declaring scope and reachable headers. Preserve case, declaration order and alias shadowing, and leave unsupported or ambiguous targets unresolved. Keep direct namespace imports working without the previous corpus-wide simple-name fallback.
Use literal base declarations and member-name barriers to resolve inherited fields and methods only through one reachable path. Reject unknown bases, diamonds, virtual-base paths and inherited overload families; bound alias and inheritance work with cached lookups. Preserve lexical alias blockers, standard-pointer spelling and parked foreign-type behavior. Forward persisted C++ facts and include locations through CLI and watcher incremental updates, and retire older AST caches.
Keep field spellings and aliases bound to their declaration scope while allowing a unique exact type definition from the caller's explicit include set. Persist definition completeness to enforce same-file order, and keep base-type completeness declaration-scoped. Cover raw, reference, alias and smart-pointer fields, call-site alias shadowing, absent and ambiguous definitions, and incremental context.
Count visible complete declaration records before accepting a type target, so same-file duplicate bodies cannot become unique merely because their graph IDs coalesce.
Exclude namespace, class and function scoped includes from global type visibility while retaining whole-file guards and linkage wrappers. Complete aliases at their original use point so an earlier complete body can satisfy a base specifier without accepting a later caller-only definition. Retire cached extraction facts that included scoped imports.
Keep named namespace ancestry through an internal anonymous lookup scope without assigning identities to anonymous classes. Preserve anonymous declarations as unknown shadowing barriers, including their implicit parent visibility, and leave qualified parent access available. Apply the scope consistently to typed receiver bindings and scoped static calls.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 9, 2026
@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.

@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 6 changed function(s) (6 not verified).

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

Not verified on this run: dispatch\_command (vacuous: never exercised), \_resolve\_cpp\_member\_calls (vacuous: never exercised), \_cpp\_class\_fields (unsupported), \_cpp\_local\_binding\_ranges (vacuous: never exercised), \_extract\_generic (unsupported), \_rebuild\_code (unsupported).


Graphify review — findings

Extends C++ receiver-type resolution to follow using/typedef aliases (including raw-pointer and supported std smart-pointer aliases), namespace and using directives, and explicit preceding includes, all respecting lexical scope and declaration order. It also resolves inherited fields and methods through literal, reachable base types, with a derived class hiding same-named members in its bases. Anything ambiguous or unsupported (diamonds, virtual or dependent bases, alias templates, cyclic aliases, walks over 32 classes, unincluded definitions) stays unresolved rather than guessed. File and class nodes now persist lexical type/alias facts, include offsets and field declaration offsets, so an unchanged header supports incremental receiver resolution. The AST cache schema bumps to 50 to retire older entries, and existing graphs need graphify extract . --code-only --force to populate those facts before relying on changed-file-only updates. ARCHITECTURE.md documents the new lookup rules.

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 — 5849 functions depend on the 1242 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1186 callers, 71 callees
  • worse: _extract_generic() — 20 callers, 55 callees
  • worse: extract_cpp() — 41 callers, 5 callees
  • worse: walk() — 1 callers, 86 callees
  • worse: walk_calls() — 1 callers, 41 callees
  • worse: _resolve_cpp_member_calls() — 2 callers, 10 callees

Verification — 5849 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: 5688 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

546 of 546 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 — 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 496 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.

Docs that may be stale (advisory)

…and 10 more.

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 \_resolve\_cpp\_member\_calls.

The verifier did not have enough to check \_resolve\_cpp\_member\_calls, 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: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

Could not verify: Could not verify \_cpp\_class\_fields.

The verifier did not have enough to check \_cpp\_class\_fields, 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: signature changed: no shared positional arity

Could not verify: Could not verify \_cpp\_local\_binding\_ranges.

The verifier did not have enough to check \_cpp\_local\_binding\_ranges, 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 \_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 \_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

· 6 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Nov 10, 2026
#5118 targeted an over-incremented schema (51) and its stale-cache test hardcoded
>= 45 with 43 as the 'old' sentinel. The combined C++ batch bump is 43, so floor
the assertion to >= 43 and use 42 as the genuinely-older sentinel.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
safishamsi added a commit that referenced this pull request Nov 10, 2026
Co-landing the scoped-alias/inherited-receiver work (#5118) with the template/
guarded-initializer work (#5115) required merging their _cpp_local_binding_ranges
tuple: #5118 appends the lexical lookup scope, #5115 appends the qualified name
and a dependent-type flag. Carry all three (receiver_type, lookup_scope,
qualified_name, dependent), widen the type annotations to the 6-tuple, and move
the dependent-flag read in the member-defer predicate to its new index. Full C++
suite (443 tests incl. #5098/#4916/#4946) green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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