Repository navigation
fix(python): a per-callable graph must contain its self-loops - #353
Merged
Merged
Conversation
The Neo4j query for one callable's own cfg/cdg/ddg edges was written as two
containment patterns:
MATCH (c)-[:PY_HAS_BODY_NODE]->(s)-[r]->(d)<-[:PY_HAS_BODY_NODE]-(c)
When s and d are the same node — a data-dependence self-loop, i.e. a
statement that reads a variable it also redefines — both hops match the
same PY_HAS_BODY_NODE relationship, and Cypher's relationship-uniqueness
rule drops the row. There are 64,702 such edges on the odoo reference
graph; one callable returned 28,146 of its 28,394.
The defect was invisible from inside the result: total is counted from the
same match, so the short page agreed with its own count and reported
complete. Only a comparison against the graph reveals it.
The second hop becomes a pattern predicate, which does not bind the
relationship. Measured on the same callable, it is also faster: 13.1ms
against 18.8ms, since the planner tests containment rather than expanding
a second pattern.
TypeScript anchors these accessors on the callable's id prefix and was
never affected; Java's equivalent is being written the same way.
Closes #349
…self-loop-edges # Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #349.
get_cfg,get_cdgandget_ddgon the Python Neo4j backend silently dropped every self-loop edge. The query asked for a callable's own edges as two containment patterns:When
sanddare the same node — a data-dependence self-loop, which is what a statement that reads a variable it also redefines produces — both hops match the same relationship, and Cypher's relationship-uniqueness rule discards the row.Why it was invisible.
totalis counted from the same match, so the short page agreed with its own count and reportedcomplete. Nothing inside the result could reveal it; only a comparison against the graph does.Measured on the odoo reference graph: 64,702 self-loop
PY_DDGedges. OnAccountAccruedOrdersWizard._compute_move_vals, before and after:totalcompleteTrueTrueIt is faster because a pattern predicate lets the planner test containment instead of expanding a second pattern.
Tests. Two, both failing on the unfixed query and passing on the fix. One is a shape check needing no graph, asserting the second hop is a predicate — that is the durable guard, since it fails even where no corpus has a self-loop. The other runs against a live graph, picks the callable with the most self-loops, and asserts the page holds every one the graph holds.
Blast radius. Python only. TypeScript anchors these accessors on the callable's id prefix, a spelling chosen for speed that happens to sidestep this, and its leg verified self-loops are returned. Java's equivalent is being written the same way, with the same regression test.
Found while porting the accessors to Java, by asking whether the shape Python uses would be safe there.