codemap icon indicating copy to clipboard operation
codemap copied to clipboard

accuracy(Scala): 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 Scala repositories at pinned commits and compare it to ground truth.

  • Suggested ground truth: SemanticDB or a symbol-reference sample.
  • Report: recall, precision, and whether the coverage status was honest for each file.

Likely gaps to check

same-package references, implicits, wildcard imports.

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

Scala: file-to-file import graph measurement (#254)

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)

  • typelevel/cats @ e28985fe2a0d7123a8fb84cbb70c72b5e3d935ca (835 Scala source files)
  • http4s/http4s @ d1c4e6b13344ebe0e94c5ce82692275a091e5a71 (670 Scala 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
s-cats 835 183 12 7% 30/30
s-http4s 670 101 24 24% 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
s-cats 183 67 37% 10 173 95% 656 21% 96 52% 166
s-http4s 101 31 31% 0 90 89% 276 25% 66 65% 167

What blocks 90%

  • Scala already resolves a few edges: cats 12 of 183 (7%), http4s 24 of 101 (24%). The current note still says edges are "not represented" (inference: the note text is the same for non-Swift languages).
  • Blocker 1: package-chained package a / package b clauses and braces, import x.{A, B => C} selectors, import x._ wildcards, package objects. Needs a real import parser. Medium.
  • Blocker 2: implicits and syntax extension imports (cats.syntax.all._) bring edges to files via members, not types. Not fully closable by names; the proxy G only counts the object file.
  • Blocker 3: many types per file and many files per package (cats), so name-only (b) gives 656 false edges for 173 true. Package-scoped index required.
  • 90% reachable: only partly; implicit-scope edges plus cross-version source dirs (scala-2/scala-3) make this medium-to-large.

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