codemap icon indicating copy to clipboard operation
codemap copied to clipboard

accuracy(Elixir): measure import graph accuracy and close gaps below 90%

Open JordanCoin opened this issue 1 month ago • 1 comments

Part of #237.

Starting estimate: near 0% recall. This is an unmeasured guess.

Measure

Run codemap on real Elixir repositories at pinned commits and compare it to ground truth.

  • Suggested ground truth: mix xref graph.
  • Report: recall, precision, and whether the coverage status was honest for each file.

Likely gaps to check

alias, import and use, modules mapping to files.

Done when

  • Repositories, commits, method and numbers are recorded here.
  • Each miss has a root cause.
  • Recall is at or above 90%, or the remaining gap is one codemap cannot close and its coverage status says so.

JordanCoin avatar Nov 01 '26 11:11 JordanCoin

Elixir: file-to-file import graph measurement (#256)

Predictions below are predictions from a throwaway script, not measurements of a shipped resolver. Current-graph numbers are measured with codemap 4.6.3.

Repos (shallow clones)

  • phoenixframework/phoenix @ 84f2486ba6296a2b47bf97095a586f0408b37a0a (207 Elixir source files)
  • oban-bg/oban @ c5aa59b352b334c6559afc019e623dcd2e2eb041 (124 Elixir source files)

Method

  • Sample: 30 files per repo, seeded random sample (Python random.Random(42).sample over sorted tracked files; not shuf), tests included.
  • Ground truth G: NOT hand-built for all 300 files. G is a script-built proxy: explicit imports resolved to project files via a package/namespace/module index, plus same-package (C#: same and parent namespace, used namespaces; Elixir: alias-expanded dotted module references) type-name tokens in comment- and string-stripped code. I hand-checked 3 files (oban engine_bench.exs, MediatR Mediator.cs, cats FunctionK.scala) and they looked right; G may still contain token collisions (over-count) and miss top-level function use, macros, implicits (under-count). Treat G as a sample proxy.
  • Current graph: codemap --json --importers <T> for every G target and sample file plus 40 random files; an edge S->T counts as recovered if S is listed in importers(T). .codemap/config.json only list includes the language extension in every repo (not hiding it).
  • (a) fully qualified import mapped to path by convention (Java/Kotlin/Scala a.b.C to a/b/C.<ext> with prefix walk; C# namespace to directory suffix; Elixir Foo.BarBaz to foo/bar_baz.ex).
  • (b) Swift-style: any identifier (len>=3) in the file (import lines removed, comments and strings kept, as Swift does) equal to a type declared in another file, all declarers become targets. (b-uniq) same but only names declared in exactly one file.
  • False edge = predicted edge not in G. Because G is a proxy, some false edges may be real and vice versa.

Current graph (measured)

repo files G edges current recovered recall partial on sampled files
e-phoenix 207 62 0 0% 30/30
e-oban 124 101 0 0% 30/30

Precision of current edges: not measured (importers queries only reveal edges into queried files; every recovered edge I could see was in G). Honesty: coverage_status was partial with a symbol-imports note on 30 of 30 sampled files in every repo, so no sampled file claimed completeness.

Predicted recovery on the same sample (prediction)

repo G (a) true (a) recall (a) false (b) true (b) recall (b) false (b) precision (b-uniq) true (b-uniq) recall (b-uniq) false
e-phoenix 62 22 35% 29 44 71% 366 11% 28 45% 71
e-oban 101 22 22% 5 88 87% 147 37% 61 60% 58

What blocks 90%

  • Current Elixir graph is empty: 0 of 163 G edges recovered in both repos.
  • Blocker 1: references are by dotted module name in code (Oban.Registry.whereis()), not imports: most G edges are dotted-name references (phoenix 62 of 62, oban 101 of 101 ref-kind edges, alongside 33 and 35 alias/import/use edges), so alias expansion (alias Foo.{A, B}, alias X, as: Y) is required. Needs alias-aware module resolver. Medium.
  • Blocker 2: use Foo runs __using__ macros that inject imports/aliases invisibly. Not closable statically; recall ceiling below 90% for Phoenix-style code.
  • Blocker 3: convention (a) (module to snake_case path) fits lib/ but not .exs test/bench modules or nested defmodule in one file (phoenix a: 22 true, 29 false).
  • Name-only (b) uses last module segment, which collides heavily (phoenix: 366 false for 44 true).
  • 90% reachable: no for macro-heavy code; maybe for library code. Fix size: medium for alias-aware; ceiling not closable.

Scripts: (res.py, run.py, cur.py, gen.py); raw edges in out.json.


Measured with codemap 4.6.3. Ground truth here is a script-built proxy with three files hand-checked. Predicted numbers are predictions, not measurements.

JordanCoin avatar Nov 01 '26 11:11 JordanCoin