mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-05 02:43:32 +00:00
Merge 4de4eb7379 into 6bb99767ff
This commit is contained in:
commit
0a1982cc27
3 changed files with 82 additions and 19 deletions
|
|
@ -36,7 +36,7 @@ All three are `BasicBlock → BasicBlock` edges in the single `CodeRelation` tab
|
|||
|
||||
- `pdg_query({ mode: 'controls', target })` — CDG. For the anchored function,
|
||||
each edge: controlling predicate block → dependent block + branch sense in
|
||||
`label` (`'T'` = predicate's true/taken arm, `'F'` = false/fall-through). An
|
||||
`reason` (`'T'` = predicate's true/taken arm, `'F'` = false/fall-through). An
|
||||
edge into an early-return/throw block is flagged `guard: true`.
|
||||
- `pdg_query({ mode: 'flows', target, variable? })` — REACHING_DEF def→use
|
||||
edges; `variable` filters to one binding.
|
||||
|
|
@ -44,16 +44,37 @@ All three are `BasicBlock → BasicBlock` edges in the single `CodeRelation` tab
|
|||
`target` is **required** — a file path or a symbol/function name (resolved like
|
||||
`context()`). There is no anchorless mode (see below).
|
||||
|
||||
## The corrected guard-clause Cypher
|
||||
## Guard-clause queries
|
||||
|
||||
The RFC #567 §2 form (`[:CDG {label:'F'}]`) does **not** run as written. Edges
|
||||
are values of the single `CodeRelation` table's `type` property, and the branch
|
||||
sense is in `reason`, NOT a `label` column:
|
||||
Prefer the dedicated, bounded `pdg_query` surface for guard discovery:
|
||||
|
||||
```text
|
||||
pdg_query({ mode: 'controls', target: '<function-or-file>' })
|
||||
```
|
||||
|
||||
Filter the returned rows for `guard: true` when you only need early-return or
|
||||
throw guards. The tool requires an explicit target and applies its own bounded
|
||||
result limit, so it cannot accidentally turn a local guard lookup into a
|
||||
repository-wide CDG scan.
|
||||
|
||||
If you are debugging the graph and truly need raw Cypher, keep the same two
|
||||
constraints explicit: anchor the blocks to one known function/file span **and**
|
||||
add a deterministic `LIMIT`. CDG edges are values of the single `CodeRelation`
|
||||
table's `type` property, and the branch sense is in `reason`, not a `label`
|
||||
column. For example, after resolving a function to its file and line span:
|
||||
|
||||
```cypher
|
||||
MATCH (pred:BasicBlock)-[r:CodeRelation {type: 'CDG'}]->(dep:BasicBlock)
|
||||
WHERE dep.text STARTS WITH 'return' OR dep.text STARTS WITH 'throw'
|
||||
WHERE pred.filePath = $filePath
|
||||
AND dep.filePath = $filePath
|
||||
AND pred.startLine >= $startLine
|
||||
AND pred.startLine <= $endLine
|
||||
AND dep.startLine >= $startLine
|
||||
AND dep.startLine <= $endLine
|
||||
AND (dep.text STARTS WITH 'return' OR dep.text STARTS WITH 'throw')
|
||||
RETURN pred.startLine, r.reason AS branch, dep.startLine, dep.text
|
||||
ORDER BY dep.startLine, pred.startLine
|
||||
LIMIT 100
|
||||
```
|
||||
|
||||
`r.reason` is the sense the predicate took to reach the early exit. For
|
||||
|
|
@ -66,7 +87,7 @@ so don't hard-code one sense.
|
|||
- **Always anchored + LIMIT-bounded.** LadybugDB has no rel-property index, so
|
||||
an unanchored `[:CDG*]`/`[:REACHING_DEF*]` path scan is unbounded. `pdg_query`
|
||||
requires `target` and bounds the page; raw `cypher` callers must anchor on a
|
||||
file id-prefix or symbol span themselves.
|
||||
file id-prefix or symbol span themselves and include a deterministic `LIMIT`.
|
||||
- **BasicBlock↔symbol join is reconstructed.** No `Function→BasicBlock` edge:
|
||||
the block is matched by its id-prefix (`BasicBlock:<file>:<fnStartLine>:…`)
|
||||
plus `startLine` within the symbol's span. BasicBlock `startLine` is **1-based**
|
||||
|
|
|
|||
|
|
@ -44,16 +44,37 @@ All three are `BasicBlock → BasicBlock` edges in the single `CodeRelation` tab
|
|||
`target` is **required** — a file path or a symbol/function name (resolved like
|
||||
`context()`). There is no anchorless mode (see below).
|
||||
|
||||
## The corrected guard-clause Cypher
|
||||
## Guard-clause queries
|
||||
|
||||
The RFC #567 §2 form (`[:CDG {label:'F'}]`) does **not** run as written. Edges
|
||||
are values of the single `CodeRelation` table's `type` property, and the branch
|
||||
sense is in `reason`, NOT a `label` column:
|
||||
Prefer the dedicated, bounded `pdg_query` surface for guard discovery:
|
||||
|
||||
```text
|
||||
pdg_query({ mode: 'controls', target: '<function-or-file>' })
|
||||
```
|
||||
|
||||
Filter the returned rows for `guard: true` when you only need early-return or
|
||||
throw guards. The tool requires an explicit target and applies its own bounded
|
||||
result limit, so it cannot accidentally turn a local guard lookup into a
|
||||
repository-wide CDG scan.
|
||||
|
||||
If you are debugging the graph and truly need raw Cypher, keep the same two
|
||||
constraints explicit: anchor the blocks to one known function/file span **and**
|
||||
add a deterministic `LIMIT`. CDG edges are values of the single `CodeRelation`
|
||||
table's `type` property, and the branch sense is in `reason`, not a `label`
|
||||
column. For example, after resolving a function to its file and line span:
|
||||
|
||||
```cypher
|
||||
MATCH (pred:BasicBlock)-[r:CodeRelation {type: 'CDG'}]->(dep:BasicBlock)
|
||||
WHERE dep.text STARTS WITH 'return' OR dep.text STARTS WITH 'throw'
|
||||
WHERE pred.filePath = $filePath
|
||||
AND dep.filePath = $filePath
|
||||
AND pred.startLine >= $startLine
|
||||
AND pred.startLine <= $endLine
|
||||
AND dep.startLine >= $startLine
|
||||
AND dep.startLine <= $endLine
|
||||
AND (dep.text STARTS WITH 'return' OR dep.text STARTS WITH 'throw')
|
||||
RETURN pred.startLine, r.reason AS branch, dep.startLine, dep.text
|
||||
ORDER BY dep.startLine, pred.startLine
|
||||
LIMIT 100
|
||||
```
|
||||
|
||||
`r.reason` is the sense the predicate took to reach the early exit. For
|
||||
|
|
@ -66,7 +87,7 @@ so don't hard-code one sense.
|
|||
- **Always anchored + LIMIT-bounded.** LadybugDB has no rel-property index, so
|
||||
an unanchored `[:CDG*]`/`[:REACHING_DEF*]` path scan is unbounded. `pdg_query`
|
||||
requires `target` and bounds the page; raw `cypher` callers must anchor on a
|
||||
file id-prefix or symbol span themselves.
|
||||
file id-prefix or symbol span themselves and include a deterministic `LIMIT`.
|
||||
- **BasicBlock↔symbol join is reconstructed.** No `Function→BasicBlock` edge:
|
||||
the block is matched by its id-prefix (`BasicBlock:<file>:<fnStartLine>:…`)
|
||||
plus `startLine` within the symbol's span. BasicBlock `startLine` is **1-based**
|
||||
|
|
|
|||
|
|
@ -44,16 +44,37 @@ All three are `BasicBlock → BasicBlock` edges in the single `CodeRelation` tab
|
|||
`target` is **required** — a file path or a symbol/function name (resolved like
|
||||
`context()`). There is no anchorless mode (see below).
|
||||
|
||||
## The corrected guard-clause Cypher
|
||||
## Guard-clause queries
|
||||
|
||||
The RFC #567 §2 form (`[:CDG {label:'F'}]`) does **not** run as written. Edges
|
||||
are values of the single `CodeRelation` table's `type` property, and the branch
|
||||
sense is in `reason`, NOT a `label` column:
|
||||
Prefer the dedicated, bounded `pdg_query` surface for guard discovery:
|
||||
|
||||
```text
|
||||
pdg_query({ mode: 'controls', target: '<function-or-file>' })
|
||||
```
|
||||
|
||||
Filter the returned rows for `guard: true` when you only need early-return or
|
||||
throw guards. The tool requires an explicit target and applies its own bounded
|
||||
result limit, so it cannot accidentally turn a local guard lookup into a
|
||||
repository-wide CDG scan.
|
||||
|
||||
If you are debugging the graph and truly need raw Cypher, keep the same two
|
||||
constraints explicit: anchor the blocks to one known function/file span **and**
|
||||
add a deterministic `LIMIT`. CDG edges are values of the single `CodeRelation`
|
||||
table's `type` property, and the branch sense is in `reason`, not a `label`
|
||||
column. For example, after resolving a function to its file and line span:
|
||||
|
||||
```cypher
|
||||
MATCH (pred:BasicBlock)-[r:CodeRelation {type: 'CDG'}]->(dep:BasicBlock)
|
||||
WHERE dep.text STARTS WITH 'return' OR dep.text STARTS WITH 'throw'
|
||||
WHERE pred.filePath = $filePath
|
||||
AND dep.filePath = $filePath
|
||||
AND pred.startLine >= $startLine
|
||||
AND pred.startLine <= $endLine
|
||||
AND dep.startLine >= $startLine
|
||||
AND dep.startLine <= $endLine
|
||||
AND (dep.text STARTS WITH 'return' OR dep.text STARTS WITH 'throw')
|
||||
RETURN pred.startLine, r.reason AS branch, dep.startLine, dep.text
|
||||
ORDER BY dep.startLine, pred.startLine
|
||||
LIMIT 100
|
||||
```
|
||||
|
||||
`r.reason` is the sense the predicate took to reach the early exit. For
|
||||
|
|
@ -66,7 +87,7 @@ so don't hard-code one sense.
|
|||
- **Always anchored + LIMIT-bounded.** LadybugDB has no rel-property index, so
|
||||
an unanchored `[:CDG*]`/`[:REACHING_DEF*]` path scan is unbounded. `pdg_query`
|
||||
requires `target` and bounds the page; raw `cypher` callers must anchor on a
|
||||
file id-prefix or symbol span themselves.
|
||||
file id-prefix or symbol span themselves and include a deterministic `LIMIT`.
|
||||
- **BasicBlock↔symbol join is reconstructed.** No `Function→BasicBlock` edge:
|
||||
the block is matched by its id-prefix (`BasicBlock:<file>:<fnStartLine>:…`)
|
||||
plus `startLine` within the symbol's span. BasicBlock `startLine` is **1-based**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue