Repository navigation
fix(elixir): emit calls edges for keyword-form def bodies #4210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
rtmalikian
wants to merge
1
commit into
Graphify-Labs:v8
from
rtmalikian:fix/4207-elixir-keyword-def-calls
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Keyword-form Elixir definitions keep their calls edges (#4207). | ||
|
|
||
| A one-line definition (`def a(x), do: b(x)`) has no `do_block` node: the | ||
| body is the value of the `do:` pair in the `arguments` keywords. The | ||
| extractor only registered `do_block` bodies for the call-walk pass, so every | ||
| call inside a keyword-form body was silently dropped from the graph. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from graphify.extract import extract | ||
|
|
||
| _CORPUS = { | ||
| "lib/short.ex": ( | ||
| "defmodule App.Short do\n" | ||
| " def a(x), do: b(x)\n" | ||
| "\n" | ||
| " def b(x) do\n" | ||
| " x\n" | ||
| " end\n" | ||
| "\n" | ||
| " defp c(x), do: d(x) |> e(x)\n" | ||
| "\n" | ||
| " def g(x) when is_list(x), do: b(x)\n" | ||
| "end\n" | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def _calls(tmp_path: Path) -> set[tuple[str, str]]: | ||
| paths = [] | ||
| for name, body in _CORPUS.items(): | ||
| path = tmp_path / name | ||
| path.parent.mkdir(parents=True, exist_ok=True) | ||
| path.write_text(body, encoding="utf-8") | ||
| paths.append(path) | ||
| result = extract(paths, cache_root=tmp_path / "graphify-out") | ||
| label = {n["id"]: n["label"] for n in result["nodes"]} | ||
| return { | ||
| (label[e["source"]], label[e["target"]]) | ||
| for e in result["edges"] | ||
| if e["relation"] == "calls" and e["source"] in label and e["target"] in label | ||
| } | ||
|
|
||
|
|
||
| def test_keyword_def_body_calls_are_extracted(tmp_path: Path): | ||
| """`def a(x), do: b(x)` must emit a calls edge a() -> b().""" | ||
| calls = _calls(tmp_path) | ||
| assert ("a()", "b()") in calls | ||
|
|
||
|
|
||
| def test_guarded_keyword_def_body_calls_are_extracted(tmp_path: Path): | ||
| """A `when`-guarded keyword head keeps its keyword body walkable.""" | ||
| calls = _calls(tmp_path) | ||
| assert ("g()", "b()") in calls | ||
|
|
||
|
|
||
| def test_keyword_def_without_local_targets_emits_no_dangling_edges(tmp_path: Path): | ||
| """`defp c(x), do: d(x) |> e(x)` references undefined functions: the walk | ||
| must not mint calls edges to non-existent nodes.""" | ||
| calls = _calls(tmp_path) | ||
| assert not any(src == "c()" for src, _ in calls) | ||
|
|
||
|
|
||
| def test_block_def_behavior_is_unchanged(tmp_path: Path): | ||
| """The block form still registers its function node exactly once.""" | ||
| calls = _calls(tmp_path) | ||
| assert ("b()", "b()") not in calls # no self-edge invented |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
walk()fans out to 7 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.