Repository navigation
Commit 630f851
committed
fix(elixir): extract a def head wrapped in a
extract_elixir_func_def reads the def's first argument directly and accepts
only a `call` or an `identifier` there. A guard makes that argument a
binary_operator, so the extractor found no name and returned. Every guarded
clause was dropped, and a function whose clauses ALL carry guards never reached
the graph at all. The loss is silent: a missing definition is not an error
anywhere in the pipeline.
Guards are ordinary Elixir. Measured by indexing one 970-file Elixir lib tree
with the binary built from this commit's parent and with this one, and diffing
the `nodes` and `edges` rows out of the two SQLite stores:
Function nodes 20,882 -> 21,941
new qualified names 1,059 (functions with no node at all before)
lost qualified names 0
CALLS edges 55,851 -> 57,129
USAGE edges 27,418 -> 28,223
Every one of those 1,059 is a function whose every clause carries a guard: a
clause without one already minted the node they collided on. An agent asking
"who calls this" about any of them got an empty answer that reads exactly like
dead code.
The unwrap goes in the shared helper. The calls, unified and usages walks read
the same node, and a private copy in one of them makes the rest disagree about
what a guarded clause is.
Two regressions come with the new node. Neither is minted here: both are
pre-existing phantoms that had nowhere to land while guarded clauses were
dropped, and now have a node.
1. A phantom CALLS edge onto the function being defined. The calls walk decides
a def head is a declaration by comparing the visited node against the def's
first argument, and a guard makes that argument the `when` operator, so the
inner `name(args)` call no longer compares equal. cbm.c flags self-recursion
by line containment, so the phantom lands inside the function's own span:
self_recursive Function nodes 129 -> 1,342
...with no self-call form in span 24 -> 1,241 (18.6% -> 92.5%)
(measured by reading each flagged node's own source span and looking for any
non-declaration line that names it as a call, a capture or a pipe target.)
2. A phantom WRITES edge onto it, from a paren-less guarded head. `def f when g`
has no inner call at all, so the `when` operator reaches the read/write
extractor and its first identifier is recorded as an assignment target.
Reproduced on `def bare_guarded when true, do: :ok`: one CBMReadWrite row,
var_name "bare_guarded", is_write true, scoped to the file's Module node
(the graph asserting that a module mutates a function). Corpus WRITES
11,220 -> 11,302 (+82).
Both become observable with this commit, and the guarded call-scope commit later
in this stack closes them, by different mechanisms. The CALLS phantom goes
because that commit admits the `when` operator to the definition-container
check, so a paren-less head is recognised as a declaration. The WRITES phantom
goes because that commit opens a function scope for the clause: the read/write
row is still recorded, but its enclosing_func_qn becomes the guarded clause
itself rather than the enclosing module, so resolve_rw_edges finds
src->id == tgt->id and drops the self-edge. They are stated here because a
stack that lands partially must not hide them.
tests/test_extraction.c: extract_elixir_guarded_def_head covers every guarded
shape (one guard, two guards, a `defp`, a paren-less `def bare when true`) and
both operator-definition forms that must NOT be unwrapped (`def a + b`,
`def c - d when is_integer(c)`, neither of which is extracted, as before). It
fails on the current tree for each of the guarded names.
Depends on the shared def-head helper commit.
Signed-off-by: Chad <4307099+BobbieBarker@users.noreply.github.com>when guard1 parent a5a836c commit 630f851
2 files changed
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5435 | 5435 | | |
5436 | 5436 | | |
5437 | 5437 | | |
| 5438 | + | |
| 5439 | + | |
| 5440 | + | |
| 5441 | + | |
| 5442 | + | |
| 5443 | + | |
| 5444 | + | |
| 5445 | + | |
| 5446 | + | |
| 5447 | + | |
5438 | 5448 | | |
5439 | 5449 | | |
5440 | 5450 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1409 | 1409 | | |
1410 | 1410 | | |
1411 | 1411 | | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
1412 | 1460 | | |
1413 | 1461 | | |
1414 | 1462 | | |
| |||
8651 | 8699 | | |
8652 | 8700 | | |
8653 | 8701 | | |
| 8702 | + | |
8654 | 8703 | | |
8655 | 8704 | | |
8656 | 8705 | | |
| |||
0 commit comments