Repository navigation
msbuild: a skip decided on a stale value leaves its writes in doubt (#1037) - #1040
Merged
Merged
Conversation
…1037) A gate that reads a value bound before content the walk could not see raises no diagnostic, unlike one reading an undefined or unpinned name, so every skip path took such a gate as decided: the walk committed the value it held where MSBuild, holding the rewritten value, ran the write it skipped. Each skip now asks whether the gate was decided from certain inputs (`directory_build::decided_from_certain_inputs`), and where it was not and it reads a stale value: - a property's own gate marks the name stale; - a property group's marks every name a child may write; - a `<Choose>` marks every name written in a branch MSBuild may take instead, from the first `<When>` so decided, on both the decided and the undecided path; - an `<Import>`'s and an `<ImportGroup>`'s latch the walk opaque again, since the names the unseen file writes are unknowable; - a child of a group the walk cannot evaluate is ruled out only by a gate decided from certain inputs. A caller global no longer stays fresh across content the walk could not see: a file that names it in its project's `TreatAsLocalProperty` may write it. Only reserved names do. `tests/fsproj_stale_gate_diff.rs` generates a stale gate on every route (each under three globals, one taking the hidden file) and holds what the walk commits, served and probed, to MSBuild; it pins the four shapes of #1037 beside three more. On main it fails on every route and every shape; reverting any one site of this change fails it again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A skipped `<Choose>` branch marks a write only where neither its own gate nor its group's (nor a nested `<When>`'s) rules it out whatever the uncertain names hold, and the scan of the branches MSBuild may take instead stops at the first `<When>` whose gate holds whatever they hold, reaching `<Otherwise>` only if none does. A stale `<ImportGroup>` gate latches only when one of its imports may run. A property's own gate is judged from certain inputs only when it reads a stale value, which no gate does before the walk passes content it could not see. The differential now gives each route an output only it writes, so a route's census counts what the route itself moves (and fails with every route's XML discarded); routes take gates decided on certain values a quarter of the time, so the walk must go on committing what they leave alone; and `<Choose>` and `<ImportGroup>` children carry gates decided on certain values too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The branches MSBuild may take instead of the walk's are alternatives: it takes at most one. Each is now judged from the state before any of them, in its own order (a write in a branch may enable a later gate in it), and what any may write is marked once all are judged. A nested `<Choose>` takes the same first-match rule as the outer one: stop at the first `<When>` that holds whatever the uncertain names hold, `<Otherwise>` only if none does. A child of a group the walk cannot evaluate keeps its earlier test, and adds the certain-inputs one only for a gate that reads a stale value, so a project with no hidden content judges it as before. A stale `<ImportGroup>` gate probes its imports' gates only once it is known stale. The differential's `<Choose>` branches now nest, and now and then write a name before a write gated on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An `<Import>` whose `Project` (or `Sdk`) reads a value content the walk could not see may have rewritten names another file in the real build: what the walk followed, MSBuild may not have, and what MSBuild followed, the walk did not see. The walk now latches opaque again once it has followed one, as for an import it skips on a stale gate. That covers a name a stale-gated skip left in doubt too, since the skip marks it stale. A stale `<Choose>`'s alternatives are judged before the walk's arm is walked, from the state before the `<Choose>`, and marked after it, so the walk's arm no longer sees the effects of arms exclusive of it. Each alternative's marks are undone from a log of the entries it touched rather than by copying the table, and within a group each write is judged after the ones before it are marked. A child of a stale-skipped group is ruled out wherever its gate fails whatever the uncertain names hold (`false And …` short-circuits), the earlier exactness test still applying where the gate reads nothing stale. The differential gains an import-path route: `Side` bound before the hidden file, or after it and rewritten on a stale gate, selecting between a file that writes nothing and one that writes the route's output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…only (#1037) On a `<Choose>` the walk could not decide, the arms before the undecided gate (from the first decided on a stale value) are judged from the state before the `<Choose>`, ahead of the undecided arms' marks, and marked with them: MSBuild takes one arm, so a later arm's writes cannot enable an earlier arm's gate. A skipped alternative's undo log records each touched name's trust once, not its whole entry: marking leaves every value alone. The differential reads MSBuild's evaluated table (`evaluated`), which tells an undefined name from one defined empty, and holds the walk's `Unset` to the former. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The differential asserts in every evaluation that the walk commits neither gate name, which only content before the hidden import binds: a walk that saw the hidden file would grade no stale gate, and pass. A generated project MSBuild rejects now fails the test rather than dropping out of it. A skipped alternative marks each name once and reports it once, however often its branches (or nested ones) write it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…set (#1037) A stale gate exists only once the walk has passed content it could not see, after which every undefined read is inexact already. A skipped write to a name the walk holds unbound therefore needs no stale mark, and making one turned the read's verdict from `UnsetInexact` (no value held) into `Untrusted` (a value held but doubted), which readers treat differently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Smaug123
enabled auto-merge
November 18, 2026 21:50
Smaug123
added a commit
that referenced
this pull request
Nov 18, 2026
The calls #1040 added still passed a source string and a path. The differential's projects are written to disk at a canonical path, so they are read back through `ProjectFile::read`; the unit tests' documents are buffers at a full path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1037.
The defect
A gate that reads a value bound before content the walk could not see (a stale value) raises no diagnostic. A gate reading an undefined or unpinned name does raise one. Every skip path judged "may the real build go the other way?" from that diagnostic, so a skip decided on a stale value counted as decided: the walk committed the value it held, while MSBuild, holding the rewritten value, ran the write the walk skipped. A caller global was also exempt from staleness, though hidden content can take it back with
TreatAsLocalPropertyand write it.The fix
Every skip asks whether its gate was decided from certain inputs (
directory_build::decided_from_certain_inputs, the primitive #1036 introduced for rejections). Where it was not and the gate reads a stale value:<PropertyGroup>'s gate marks each name a child may write;<Choose>, from the first<When>so decided, marks what MSBuild's alternatives may write. Alternatives are the branches up to the first<When>that holds whatever the uncertain names hold (<Otherwise>only if none does), skipping those certainly false. Each alternative is judged from the state before the<Choose>and in its own order, with an undo log, and the marks are applied once all are judged. This holds on the decided and the undecided path, nested<Choose>s included;<Import>'s or<ImportGroup>'s gate latches the walk opaque again, since the names an unseen file writes are unknowable. An<ImportGroup>latches only if one of its imports may run;<Import>whoseProject/Sdkreads a stale value latches after it is followed: MSBuild may have imported another file;go_staleexempts only reserved names, so caller globals go stale too.The existing trust machinery carries all of it: the stale channel,
latch_walk_opaque,apply_property_provenance. A name the walk holds unbound gets no mark, because after a latch every undefined read is inexact already.Tests
tests/fsproj_stale_gate_diff.rsis a generator. Each project binds gate names, then importshidden.propsunder'$(G.ToUpperInvariant())' == 'X', which the walk cannot decide and MSBuild decides on the globalG. The hidden file may rewrite the gate names and may takeGback withTreatAsLocalProperty. After it, seven routes gate on those names, each writing an output only it writes:<Choose>, with nested choices and in-branch enablement;<Import>;<ImportGroup>;Route gates are decided on certain values a quarter of the time. Every project is evaluated under
G ∈ {x, y, z}. What the walk commits, served and through the probe, must equal MSBuild's evaluated table, definedness included (evaluated). Each route must move its own output in MSBuild in some cases and stay committed in others. Every evaluation must decline the gate names, so a walk that saw the hidden file would fail rather than pass vacuously. Generated projects MSBuild rejects fail the test. A pinned test holds the four #1037 shapes and three siblings.main, every route and all four shapes fail (1,260 violations at the fixed seed).Manifests
No manifest moved.
fsproj_msbuild_corpus_diff,sdk_chain_decline_attributionand every step oftools/ci/project-corpus-gate.sh(the project-corpus resolution differential, restore-cone census, restore-graph and source-doc differentials, assembly sweeps) pass unchanged. In the corpus, a stale gate either never arises or decides nothing the walk was committing, and caller globals going stale after a latch withdraw nothing the gates pin. No compile order or TFM moved.Review findings declined
imports_seenalso holds imports the walk followed on doubted or stale routes, so discharging against it would be unsound. The decline is sound. Filed as msbuild: a certain duplicate import skipped on a stale gate need not re-latch #1042.foreign_definitionswould close that.Found in passing (separate issue)
An imported file's
TreatAsLocalPropertyopt-out lasts past the import in MSBuild, but the walk re-protects the global when the import returns. So a later plain<G>other</G>in the entry project is dropped and the walk commits the imported value: a certain-implies-exact violation onmain, with no stale gate involved. Filed as #1041.🤖 Generated with Claude Code