Skip to content

Take the source stat before reading the source - #3440

Merged
plajjan merged 2 commits into
mainfrom
source-stat-before-read
Nov 22, 2026
Merged

plajjan merged 2 commits into
mainfrom
source-stat-before-read

Conversation

@plajjan

@plajjan plajjan commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

A build took a module's stat after reading its source, so a write landing during the read left a .tydb that paired the hash of the old content with the stat of the new file, and later builds trusted that stat and never compiled the new version. The stat is now taken before a single read that gives both the parsed text and the hashed bytes.

A module's .tydb records the hash and the stat of the source that the
build compiled. A later plan trusts the .tydb without reading the source
when the source's stat is unchanged and older than the .tydb.

The new tests write a new version of a source right after a build has
read it. They cover the three places where a build reads a source: the
first read of a new module, the read of a changed module, and the read
for the front passes of a module whose own source is unchanged.

All three fail here. The build takes the stat after the read, so the
.tydb pairs the hash of the version that was read with the stat of the
new version. The next plan trusts that .tydb and never compiles the new
version.
A module's .tydb records the hash and the stat of the source that the
build compiled. A later plan trusts the .tydb without reading the source
when the source's stat equals the recorded one and is older than the
.tydb. This rule holds only if the recorded stat is the stat of the
version that was compiled, or of an older version.

Before, the build took the stat after it had read the source. It did so
when it read a new or changed module, and when it read an unchanged
module again to run its front passes. A write that landed between the
read and the stat gave a .tydb with the hash of the old version and the
stat of the new version. Every later plan trusted that .tydb, so the new
version was not compiled until the file changed again.

After, the build takes the stat first and then reads the file once.
A write that lands during the read leaves the file with a stat other
than the recorded one, so the next plan hashes the source and compiles
the new version. readModuleSource does this for every read of a module
that is compiled. An editor overlay records no stat.

The disk source provider now reads a file once and decodes the bytes as
UTF-8. It used to read the text and the bytes through two handles, and
the text was read lazily while the parser consumed it. So the parsed
text could come from a later version of the file than the hashed bytes.
A source that is not valid UTF-8 now fails with

  acton: src/a.act: invalid argument (cannot decode byte 0xff as UTF-8)

where it failed with

  acton: src/a.act: hGetContents: invalid argument (cannot decode byte sequence starting from 255)

SourceSnapshot loses its ssIsOverlay field. A snapshot is an overlay
when spReadOverlay returned it.
@plajjan
plajjan force-pushed the source-stat-before-read branch from 5d7038f to ce48bbe Compare November 22, 2026 14:22
@plajjan
plajjan merged commit 5172b66 into main Nov 22, 2026
53 checks passed
@plajjan
plajjan deleted the source-stat-before-read branch November 22, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant