codemap icon indicating copy to clipboard operation
codemap copied to clipboard

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

Open JordanCoin opened this issue 1 month ago • 1 comments

Part of #237.

Starting estimate: 50-70% recall. This is an unmeasured guess.

Measure

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

  • Suggested ground truth: swiftc dependency output or indexstore.
  • Report: recall, precision, and whether the coverage status was honest for each file.

Likely gaps to check

extensions, same-name types, protocol and generic references, SwiftPM targets.

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

Swift import graph accuracy (#251)

Repos: apple/swift-argument-parser @ 38ca4eceb349155836701b88da3e0986eb9d1e1c (171 .swift), apple/swift-log @ d0f784af9ea2bc75e557c3d2bb628a68248605f3 (42 .swift) Method: git clone --depth 1, static reading only (no scripts, builds or tests executed). Sample: 30 files per repo via shuf -n 30 with a fixed seed (a sample, not the whole repo). For each sampled file F, codemap --json --importers F (codemap 4.6.3) was compared to a ground-truth importer set. Because 9 s per call ruled out querying every file, the unit is incoming edges to the sampled file. Truth was built by a regex resolver I wrote (tools/truth.py in the local scratch dir) and the disagreements were reviewed by hand. Intra-project edges only. Recall = TP/(TP+FN), precision = TP/(TP+FP) over edges. Honesty = whether coverage_status for a sampled file with a miss was something other than complete. Auto-written .codemap/config.json only lists were checked and include the target language. Swift truth = same-module type reference, or cross-module reference when the file has import <Module> (access-modified imports included); comments stripped.

repo sampled TP FP FN recall precision sampled files with a miss miss under complete
swift-argument-parser 30 457 98 0 1.00 0.82 0 0
swift-log 30 57 14 5 0.92 0.80 1 0

Honesty: all sampled files report partial (symbol-imports/swift, "mixed"), so the label is true. No miss was reported as complete.

Root causes, ranked by edges lost or wrongly added:

  1. FP, module-blind name matching (37 of 98 edges in argument-parser, 7 of 14 in swift-log). Example: Tests/ArgumentParserToolInfoTests/ArgumentParserToolInfoTests.swift gets an edge to Sources/ArgumentParser/Parsing/SplitArguments.swift through the nested name Value, with no import ArgumentParser. Code: scanner/filegraph.go addSwiftTypeReferenceEdges (declaredBy map has no module or import scoping). Fix: medium (use Sources/ and import lines to scope).
  2. FP, mentions in comments and strings (39 of 98; 7 of 14). Example: Sources/ArgumentParserToolInfo/ToolInfo.swift line 150 style doc comments naming SplitArguments.Element. Code: same function, scans raw bytes (the ponytail comment admits it). Fix: small (strip comments/strings before the identifier scan).
  3. FP, unclassified (22 of 98), e.g. Examples/count-lines/CountLines.swift -> Sources/ArgumentParser/Utilities/Foundation.swift. Not diagnosed.
  4. FN, package access modifier not accepted (swift-log, 5 edges, all FN in the sample). Example: Sources/Logging/Locks.swift:57 package final class Lock is never recorded as a type, so LockTest.swift, CompatibilityTest.swift, LoggingTest.swift and InMemoryLogHandler.swift lose their edge. Code: scanner/astgrep.go:754 typeDeclarationName modifier list lacks package (also nonisolated, typealias is not a declared kind). Fix: small.

Caveats: recall is against a name-match style truth, so 1.00 in argument-parser is partly structural (codemap is a superset of the module-scoped truth). Edges through extensions and protocol-only use were not separately measured. Sample covers 60 of 213 files.


Measured with codemap 4.6.3. Sampled numbers are samples, not a census.

JordanCoin avatar Nov 01 '26 11:11 JordanCoin