Delphi-RAG-Lint
Delphi tooling · lint · index limits

Routines the Index Cannot See Into

Impact analysis, call trees and dead-code detection are only as good as the calls the index could resolve, and the new opaque-to-analysis rule lists the routines where most of them could not be. It is a fact about the index, not a defect in your code, and it tells you where to read the source yourself.

Availability

The rule is new in drag-lint 1.42.0-alpha and is off by default. Every output below is real output of the 1.42.0-alpha build, run on a scratch index of YADF 1.0.22.0, our Delphi formatter, freshly built by that engine.

Before you change a routine you ask who calls it, and before you delete one you ask whether anything does. Those answers come from the call edges in the index. We came to care about the gaps in them while building drag-lint on the code base of Micronite, our quality and production-control software for manufacturers: an empty “no callers” is only reassuring when you know the index could see the calls.

01 — The task

Which routines should I not trust the tools on?

The task: before a refactor, list the routines where call trees and impact analysis are weak, so you know where to read the source instead of trusting the report. The index records a call edge only when it can resolve the callee to a declaration. A call into a generic container, an unresolved library method or a dynamic call leaves no edge. One missing edge is normal. A routine where most calls have none is a hole in every report that passes through it.

02 — Step 1

Turn the rule on and run it

The rule is off by default, so an ordinary run does not mention it. Name it with --rule. The command reads the index and writes nothing; it exits 1 when there are findings.

drag-lint lint-all --db YADF.sqlite --project YADF.dproj --rule opaque-to-analysis --json

On the YADF project that is 12 findings, all severity info: 7 in YADF.Layout.pas, 2 in YADF.Guard.pas, 2 in a vendored lexer and 1 in YADF.Options.pas. Three of the messages:

YADF.Guard.pas:1168
YADF.Guard.CountScopeDecls.NoteInline: 3 of 4 calls that do not provably leave the project
could not be resolved (AddOrSetValue, Add) -- impact analysis, call trees and dead-code
detection are blind inside this routine

YADF.Layout.pas:7198
YADF.Layout.ReindentByDepth.StackPop: 3 of 3 calls that do not provably leave the project
could not be resolved (Delete) -- impact analysis, call trees and dead-code detection are
blind inside this routine

YADF.Layout.pas:8530
YADF.Layout.ApplyBlockEndLabels.Visit: 7 of 11 calls that do not provably leave the project
could not be resolved (Remove, Add) -- impact analysis, call trees and dead-code detection
are blind inside this routine

The message gives the ratio and the names of the first unresolved callees. “Do not provably leave the project” means calls shown to go to a library are not counted against the routine.

03 — Step 2

See what the index does know

Take NoteInline. Its body calls NameListEnd, IntToStr and MatchStr, then AddOrSetValue twice and BodyVars.Add once. Ask for the resolved outgoing calls:

drag-lint find-callees --qname YADF.Guard.CountScopeDecls.NoteInline --db YADF.sqlite
  YADF.Guard.NameListEnd  [certain]

One edge. The three container calls are not in the tree, so a call-tree report from NoteInline stops at NameListEnd. That is the 3-of-4 in the finding: one resolved call and three the index could not place, with IntToStr and MatchStr counted as leaving the project. The same query for the larger ApplyBlockEndLabels.Visit returns four edges (itself, EndLineTailIsMultiline, FindBlockLabel, TrailingCommentIdx) while the finding counts seven unresolved Add and Remove calls on the dictionaries Adds and Drops.

The opposite direction still works. drag-lint query find-callers --name NoteInline --db YADF.sqlite finds its one caller at YADF.Guard.pas:1370. The blind spot is inside the routine, looking out.

04 — What DL holds

Why it can say this

The index stores no opaque count. It holds the calls each routine makes and a call edge for those it resolved. The rule works the figure out when it runs: it sets aside intrinsics, type casts and calls that leave the project, asking the platform library index about each candidate. Whatever is left with no edge is opaque. A routine is reported at 3 or more opaque calls that make up at least 60 percent of its counted calls. That is why it needs a project index and the library index, and no new parse.

05 — Using the list

What to do with a finding

  • Before a refactor: read these routines by hand. Treat an impact report that reaches them as a lower bound.
  • Before deleting code: a routine reached only through an opaque routine can look dead. Check the opaque routine first.
  • Often not worth fixing: the YADF findings are mostly generic containers (TDictionary, TList). Nothing is wrong with them. The rule is info severity for that reason.
06 — Limits

Honest edges

  • It is a statement about the index, not the code. The same routine can be opaque on one index and clean after the resolver improves or the library index is rebuilt.
  • Needs the library index. Without it the rule reports nothing, because it could not tell a call that leaves the project from one it failed to resolve.
  • Index age matters. An index built by an older resolver can give different counts, and the engine says so when it reads one. Re-derive with index --project ... --resolve-only before relying on them. The index here was freshly built, so no such note appears.
  • Calls through an interface or procedure variable are static targets at best; which body runs is a run-time fact.
As of 2026-11-05, all command output above is real output of drag-lint 1.42.0-alpha, run on a scratch index of YADF 1.0.22.0 built by that engine. The rule is listed in drag-lint rules under opaque-to-analysis.