Delphi-RAG-Lint
Delphi tooling · the compile closure

Which File Does the Compiler Use

When a project names a unit twice, once in its own files and once on a search path, drag-lint now indexes the file the compiler uses and leaves the other one out. The change came from a bug report by an outside user on a real Delphi 10.3 project.

Availability

The fix is in drag-lint 1.43.0-alpha. Every output below is real output of that release (and, where marked, of the build just before the fix), run on the small fixture in section 01.

We need to know exactly which files make up a project, because every answer drag-lint gives (who calls this, what is unused, what a change breaks) is only as complete as that list. Micronite, the quality and production-control software we build for manufacturers, taught us the cost of a wrong list: a missing unit makes an answer short, a second copy of a unit makes it ambiguous, and neither says so. This time the report came from outside. Jonathas Paiva ran drag-lint on a real Delphi 10.3 project and posted the numbers in GitHub issue 13.

01 — The problem

Two files, one unit name

The index of a project is its compile closure: the files the compiler would read. drag-lint builds it by following uses. For each unit name it needs a file, and there are two sources for that file. The project says it (the .dpr uses X in 'path', and the DCCReference items in the .dproj), or a search path finds it by name.

The report measured a closure of 2,246 files against an expected 2,222. The extra 24 were one .inc and 23 files the project replaces with its own copies: 7 units and 8 base forms (16 .pas/.dfm files). In the case the report traced, the project names a shared unit with an in path, and a unit from another checkout, listed by absolute path, uses it. The closure walk searched the path, found the other checkout's copy first, and added it next to the file the .dpr names, so those units ended up with two files in the index.

We reproduced that shape from the description. It is small enough to build:

P.dpr
  program P;
  uses
    A in 'A.pas',
    Lib in 'Shared\Lib.pas',
    B in 'Other\B.pas';

P.dproj   DCC_UnitSearchPath = Other;...
          DCCReference: A.pas, Shared\Lib.pas, Other\B.pas

Shared\Lib.pas   unit Lib;   (the file the project names)
Other\Lib.pas    unit Lib;   (same name, on the search path)
Other\B.pas      unit B;  interface  uses Lib;

Unit B uses Lib. The project says Lib is Shared\Lib.pas. The search path Other would find Other\Lib.pas first.

02 — Before

The build before the fix

drag-lint index --project P.dproj --db old.sqlite
drag-lint sql --query "select path from files order by path" --db old.sqlite
C:\TEMP\fx\P\A.pas
C:\TEMP\fx\P\Other\B.pas
C:\TEMP\fx\P\Other\Lib.pas
C:\TEMP\fx\P\P.dpr
C:\TEMP\fx\P\Shared\Lib.pas
5 row(s)
drag-lint query --name Lib --db old.sqlite

unit  Lib  Lib  (C:\TEMP\fx\P\Shared\Lib.pas:1)
unit  Lib  Lib  (C:\TEMP\fx\P\Other\Lib.pas:1)
2 match(es)

Five files, and the unit Lib has two. A caller of Lib could be bound to either, and the compiler only ever reads one.

03 — After

The project's own bindings come first

drag-lint index --project P.dproj --db new.sqlite
drag-lint sql --query "select path from files order by path" --db new.sqlite
C:\TEMP\fx\P\A.pas
C:\TEMP\fx\P\Other\B.pas
C:\TEMP\fx\P\P.dpr
C:\TEMP\fx\P\Shared\Lib.pas
4 row(s)
drag-lint query --name Lib --db new.sqlite

unit  Lib  Lib  (C:\TEMP\fx\P\Shared\Lib.pas:1)
1 match(es)

Other\Lib.pas is gone from the index and Lib has one file.

The rule, from the 1.43.0-alpha change log: a unit named by a .dpr uses X in 'path', and then by a DCCReference, is never path-searched, so a same-named file elsewhere stays out. This is the order the compiler uses. Where the two disagree, the .dpr file wins, the DCCReference file is left out, and a WARN line names both (we did not provoke that case here, so we show no output for it).

04 — A second spelling

One file, one path

The same report exposed a smaller bug. A rooted in path holding .. joined the closure as written, so the printed file count held a second spelling of a file already listed. Every closure entry is now one normalised full path, so each file is counted once. We could not reproduce the reporter's exact route to this one, so we show no output for it.

05 — How drag-lint can know

What the index holds

A project index is the closure, so membership is a plain lookup: drag-lint query --name Lib --db new.sqlite returns the unit that is in it, and a miss means the unit is not part of the project. That is why the closure had to be right before anything built on it (callers, unused-unit checks, impact) could be.

06 — Limits

Honest edges

  • Not yet confirmed on the reporter's project. The fixture above shows the shape, not those 23 files, and the reporter has not yet re-run the comparison on 1.43. The release notes ask anyone whose count still differs to tell us.
  • Re-index once. This release bumps the extractor and resolver versions, so every index re-parses once after installing it.
  • A listed file that is missing on disk binds nothing, and the path search still answers (CHANGELOG).
  • Library databases. The platform library databases are still built from Delphi 13's source, so a 10.3 project gets 13's RTL symbols (stated in the issue thread; a separate, larger question).
As of 2026-11-05, all command output above is real output of drag-lint 1.43.0-alpha (the “before” output: the build of the same release immediately preceding the fix), run on a small scratch fixture indexed with drag-lint index --project P.dproj, with table headers and timings trimmed. The reporter's numbers are quoted from GitHub issue 13.