Repository navigation
fix(extract): keep the checkout path out of ObjC category ids - #4642
madhusudanpatnaik wants to merge 2 commits into
Conversation
An ObjC category (`@interface Foo (Cat)` in `Foo+Cat.h`) keys its class node and methods off the base stem `Foo`, so they fold into `Foo.h`'s class (Graphify-Labs#1556). extract() turns an id minted from an absolute input path into the repo-relative form only when it starts with its own file's stem prefix (`.../Foo+Cat`), so these ids kept the absolute form. A category on a class outside the corpus (`NSString (Extra)`) got a node id with the checkout path in it, and so did the methods of a category on an in-corpus class. graph.json then carried the path (Graphify-Labs#502), two checkouts of one repo gave different graphs, and an incremental rebuild in a moved or copied checkout added duplicate nodes. The remap now also registers a category file's base-stem prefix, after the file's own prefixes. On SDWebImage, AFNetworking and Kingfisher, 334 / 51 / 17 ids carried the checkout path; now 0, two checkouts give identical graphs, and absolute and relative input agree. Every edge, compared by label and file, is unchanged. Through the CLI, SDWebImage's graph drops 125 duplicate category nodes (a leaked copy beside the clean copy reached through its include/ symlink) and one false reference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the pull request, @madhusudanpatnaik. 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. |
There was a problem hiding this comment.
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 1 changed function(s) (1 sampled, not proven).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Fixes ObjC category node ids leaking the checkout path into the graph. Ids for a category's base class and its methods (e.g. NSString from NSString+Extra.h) now get rewritten from the absolute-path form to the repo-relative form, so the same repo checked out in two places yields the same graph. extract registers the base-stem prefix alongside the file's own prefixes, and the rewrite hinges on how that base stem is derived from a path that can itself contain +. New tests cover checkout-path leakage, category ids on in-corpus and external classes, two checkouts, and relative versus absolute input paths.
Worth a look
- Base-stem prefix may be mis-derived when a directory in the path contains '+' —
graphify/extract.py:9819· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3159 functions depend on the 333 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 989 callers, 60 callees
Verification — 3159 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: 2914 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
203 of 437 test file(s) selected (46%) via static blast radius.
tests/test_affected_overrides.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_c_include_resolution.py— impacttests/test_cache.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cpp_template_type_params.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_delegate_declarations.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_foreach_loop_variable.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_underscore_collisions.py— impacttests/test_csharp_var_call_return_type.py— impacttests/test_csharp_verbatim_interpolation.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_ejs_extractor.py— impacttests/test_elixir_defdelegate.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_keyword_def_calls.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_erlang_extractor.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impact- … and 153 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
No difference found (not proven): No behavior difference found in extract (not a proof).
The verifier ran both versions of extract 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.
· 1 more finding(s) on lines outside this diff (see the check run).
No code change. test (3.13) failed in test_watch_root_config_lifecycle_rebuilds_and_refreshes_event_mapping[create], the test-harness race fixed by Graphify-Labs#4620, which fails the same way on v8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Landed in 0.9.94, cherry-picked to preserve your authorship. Objective-c category node ids stay repo-relative instead of embedding the checkout path. Thanks @madhusudanpatnaik. Live on PyPI: https://pypi.org/project/graphifyy/0.9.94/ |
What does this PR do?
An Objective-C category's node ids carried the absolute checkout path. A category (
@interface Foo (Cat)inFoo+Cat.h) keys its class node and its methods off the base stemFoo, so they fold intoFoo.h's class (#1556). extract() turns an id minted from an absolute input path into the repo-relative form only when the id starts with its own file's stem prefix (…/Foo+Cat). These ids start with the base stem's prefix (…/Foo), so they stayed absolute:Effects on v8:
graph.jsoncarries the checkout path, including usernames, which graph.json edge endpoints still leak absolute-path-derived file ids #502 guards against for every other id.include/symlinks (SDWebImage), each category node is extracted twice and the leaked copy can't collapse with its symlink twin the way every other symbol does. That leaves a duplicate class node, and on SDWebImage one false reference: theCIImagetype in@property CIImage *CIImagebound to the duplicate's-CIImagegetter.The fix (
graphify/extract.py, id-remap registration): for a file whose name contains+and whose stem is a category stem (_objc_category_base_stem, the same rule the ObjC extractor uses), also register the base stem's prefix, in its input and resolved forms, after the file's own prefixes. The prefix pass issource_file-gated, so this only touches nodes from that category file. Because the rewrite also lands insym_remap, the call records and ObjC field tables follow. No cache-schema bump is needed: per-file extraction is unchanged, and the remap runs on cached results as well. Agraphify updateover a graph v8 built produces the fresh result.Type of change
Verification & Invariants
Invariant (#502): a node id never depends on where the repo is checked out; absolute and relative input give the same graph.
Real repos (v8 at 0.9.93 → this branch; each repo extracted from two checkout locations plus once with relative input):
The only change is that exactly the leaked ids are renamed (334 / 51 / 17). With SDWebImage's
include/symlinks in place, theextract()graph keeps the same node and edge counts and the same edges by label. 326 edge keys differ only in which symlink twin the source node is credited to. Through the CLI, SDWebImage's graph has 125 fewer nodes: each is a duplicate pair on v8 (a leaked-id copy beside the clean copy reached through the symlink). The one distinct edge v8 has and this branch doesn't is the falseNSImage → -CIImagereference above.Path variations: a checkout path with spaces and non-ASCII characters, a category file at the repo root, a nested directory, and a
.mmimplementation all give clean ids.NSArray+Many+More.h, which isn't a category stem by the existing rule, is left exactly as on v8.CLI (
graphify update, Kingfisher and SDWebImage):updateagain equals a fresh build.Determinism: identical graph under a different
PYTHONHASHSEED, parallel extraction, a warm cache, and a cache filled by v8 first (SDWebImage, AFNetworking, Kingfisher).Performance: the extra registration only runs for a file whose name contains
+. Isolated, it costs 0.125 ms perextract()on grpc-go (1,089 files, none with+) and 2.6 ms on SDWebImage (58 category files). Fullextract(), cold cache, 3 interleaved rounds, v8 vs this branch: SDWebImage 2.64/2.81/2.68 s vs 2.80/3.06/2.62 s, AFNetworking 1.28/1.38/1.16 s vs 1.30/1.12/1.27 s, Kingfisher 4.59/4.33/4.28 s vs 4.92/4.39/4.42 s, grpc-go 40.78/38.06/39.04 s vs 42.01/39.72/39.93 s; all within run-to-run noise, peak RSS identical.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.
Limitations:
NSData+Nocilla.h,NSData+Matcheable.h), they share one node by design (iOS Objective-C/Swift mixed-language: many expected edges missing (self-imports, .h↔.m linkage, cross-language calls, symbol fragmentation) #1556). A fresh build credits it to the first file, while the hook-style rebuild credits it to the re-extracted file. Ids and edges match; only that node'ssource_file/line differs. On v8 the hook path added a duplicate node there instead.Core/UIView+ZZ.h) isn't folded into a same-named class declared in another directory (include/…/UIView+WebCache.h), because the decl/def merge only sees the re-extracted file. v8 behaves the same.How was this tested?
tests/test_objc_category_portable_ids.py(4 tests): no id or edge endpoint carries the checkout path; a category class and methods get repo-relative ids (lib_nsstring_nsstring,lib_foo_foo_barbesidelib_foo_foo_base) with theirmethodedges; two checkouts give the same graph; relative input gives the same ids as absolute input. All 4 fail on v8 (0.9.93) and pass here. The existing ObjC tests (88 with the new ones) pass.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (No source fragments touched;--checkpasses.)