Skip to content

fix(c): resolve directory-qualified angle includes and keep standard headers off the alias index (#5218) - #5228

Open
Yi-111-a wants to merge 1 commit into
Graphify-Labs:v8from
Yi-111-a:fix/c-angle-includes
Open

Yi-111-a wants to merge 1 commit into
Graphify-Labs:v8from
Yi-111-a:fix/c-angle-includes

Conversation

@Yi-111-a

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5218. #include <...> edges carried no include metadata, so _resolve_c_include_edges skipped them and their bare-stem target went through the legacy alias index in build.py. On the repro from the issue this gives:

libb_src_user_cc -> liba_include_liba_bus_bus        # <liba/Bus.h>: lands on the Bus class, not liba/include/liba/Bus.h
libb_src_user_cc -> libc_include_libc_functional_h   # <functional>: bound to the project's functional.h
libb_src_user_cc -> chrono

Changes:

  • _import_c tags angle includes with include_kind: "angle" and raw_include, the same way quoted ones are tagged.
  • _resolve_c_include_edges accepts angle includes, but only when they have a directory component (<liba/Bus.h>). Those go through the existing path-suffix, case and tie-break rules. A bare <name> names no path, so the resolver leaves it alone.
  • build.py: a new _is_std_angle_include check keeps the alias lookup (in both build_from_json and finalize_raw_graph_endpoints) away from an angle include of a C/C++ standard header. The header names live in C_STANDARD_INCLUDE_NAMES in extractors/resolution.py, next to _PYTHON_STDLIB_MODULE_NAMES. This is option 2 from the issue, the C/C++ version of the Import builder resolves bare to a same-stem local module (captures stdlib) #4261 guard.

After the change:

libb_src_user_cc -> liba_include_liba_bus_h
libb_src_user_cc -> chrono
libb_src_user_cc -> functional      # external stub

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: an angle include binds to a corpus header only when its written path matches that header, and a standard header name never binds to a project file by stem alone.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Three tests were added to tests/test_c_include_resolution.py, and all three fail on v8 without the fix:

  • <liba/Bus.h> resolves to the Bus.h file node, both in extract() and after build().
  • <functional> stays an external functional stub when the corpus has exactly one functional.h, and <chrono> is unchanged.
  • a bare <config.h> is not path-resolved by the corpus resolver and carries the angle metadata.

The existing test_angle_bracket_system_includes_not_bound_locally (<stdio.h> with two local stdio.h) still passes.

Limitations:

  • A bare non-standard angle include (<config.h>) behaves as before: it can still heal through the alias index when exactly one project file claims the stem. I left this alone because projects often include their own headers this way through -I.
  • A directory-qualified angle include that is not in the corpus (<boost/asio.hpp>, <sys/types.h>) still falls back to its bare stem like before. Only standard header names are guarded.
  • The ObjC #import <...> path in extractors/objc.py is not changed.
  • This changes per-file C/C++ extractor output (the new metadata on angle edges), so it needs the next AST cache schema bump. I did not touch cache.py, to avoid conflicts with the schema note.

How was this tested?

uv run pytest -q tests/test_c_include_resolution.py
# 16 passed (the 3 new tests fail on v8 without the fix)
uv run pytest -q tests/test_*cpp*.py tests/test_c_*.py tests/test_*objc*.py tests/test_*cache*.py tests/test_*alias*.py tests/test_build*.py
# 919 passed, 2 skipped
uv run pytest -q tests
# 13 failed, 10995 passed, 304 skipped. The same 13 fail on v8 without this change
# (test_security safe_fetch, test_sql_tsql_procedures, test_terraform_modules parallel cache, test_multilang escaped SQL quote)
uv run ruff check graphify/build.py graphify/extract.py graphify/extractors/resolution.py tests/test_c_include_resolution.py
# All checks passed
uv run pyright graphify/build.py graphify/extract.py graphify/extractors/resolution.py
# 203 errors, the same count as v8 (none new)

…headers off the alias index (Graphify-Labs#5218)

Angle includes (#include <...>) carried no include metadata, so
_resolve_c_include_edges never looked at them and their bare-stem target
went through the legacy alias index. <liba/Bus.h> then missed
liba/include/liba/Bus.h, and <functional> bound to a unique project
header named functional.h.

Angle includes are now tagged include_kind "angle". The corpus resolver
handles them with the existing path-suffix rule when they have a
directory component, and the alias lookup skips an angle include that
names a C/C++ standard header, like the Python stdlib guard (Graphify-Labs#4261).
@Yi-111-a
Yi-111-a requested a review from safishamsi as a code owner November 15, 2026 17:05
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 15, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Yi-111-a. 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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

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

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

Not verified on this run: build\_from\_json (vacuous: never exercised), \_import\_c (vacuous: never exercised).


Graphify review — findings

Fixes C/C++ angle includes binding to the wrong project header: <functional> no longer resolves to a same-named libc/functional.h, because _is_std_angle_include now keeps standard-header targets out of the bare-stem alias index in both finalize_raw_graph_endpoints and build_from_json. Only standard names from the new C_STANDARD_INCLUDE_NAMES set get that treatment, so a bare non-standard <name> can still alias to a same-named project header. Tags angle includes with include_kind: "angle" in _import_c, and _resolve_c_include_edges now resolves directory-qualified ones like <liba/Bus.h> to the matching corpus header by path suffix. Bare <name> angle includes are skipped there, so they stay unresolved external stubs.

Worth a look

  • Bare non-standard angle includes still alias to same-named project headers — graphify/build.py:2052 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 6122 functions depend on the 765 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1241 callers, 78 callees
  • worse: build_from_json() — 319 callers, 26 callees
  • worse: build() — 94 callers, 6 callees
  • worse: finalize_raw_graph_endpoints() — 12 callers, 6 callees

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

Test selection

Test selection

397 of 575 test file(s) selected (69%) via static blast radius.

  • tests/test_4874_jvm_resolution.py — impact
  • tests/test_4909_reference_binding_scale.py — impact
  • tests/test_4978_reconcile_cost.py — impact
  • tests/test_4992_ts_import_types.py — impact
  • tests/test_5072_splittable_under_cap_retry.py — impact
  • tests/test_affected_cli.py — impact
  • tests/test_affected_overrides.py — impact
  • tests/test_affected_path_file_node.py — impact
  • tests/test_affected_seed_reference_forms.py — impact
  • tests/test_alias_folding.py — impact
  • tests/test_analyze.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_atomic_canvas_export.py — impact
  • tests/test_atomic_writes.py — impact
  • tests/test_backend_opt_in.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_build_located_semantic_identity.py — impact
  • tests/test_build_merge_dedup_scope.py — impact
  • tests/test_build_merge_ghost_fold_4955.py — impact
  • tests/test_build_merge_hyperedges_and_prune.py — impact
  • tests/test_build_merge_shrink_guard.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact, changed-test
  • tests/test_cache.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_case_only_decl_ids_4904.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_claude_cli_backend.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cluster.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_community_labels_skill.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_confidence.py — impact
  • tests/test_confidence_score_output.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_cpp_alias_member_resolution.py — impact
  • tests/test_cpp_anonymous_namespace_receivers.py — impact
  • tests/test_cpp_conditional_initializers.py — impact
  • tests/test_cpp_forward_declarations.py — impact
  • tests/test_cpp_forward_receiver_completion.py — impact
  • tests/test_cpp_inherited_member_resolution.py — impact
  • … and 347 more

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 build\_from\_json.

The verifier did not have enough to check build\_from\_json, 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 11 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous

No difference found (not proven): No behavior difference found in finalize\_raw\_graph\_endpoints (not a proof).

The verifier ran both versions of finalize\_raw\_graph\_endpoints 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 \_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)

No difference found (not proven): No behavior difference found in \_resolve\_c\_include\_edges (not a proof).

The verifier ran both versions of \_resolve\_c\_include\_edges 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.

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

This branch has not been deployed

No deployments
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.

C/C++: angle-bracket includes are never resolved to corpus headers; a standard header name can bind to a same-named project file

1 participant