Skip to content

msbuild: MSBuildAllProjects reads inexact after the property pass (#1131) - #1142

Merged
Smaug123 merged 4 commits into
mainfrom
issue-1131-all-projects
Nov 25, 2026
Merged

Smaug123 merged 4 commits into
mainfrom
issue-1131-all-projects

Conversation

@Smaug123

Copy link
Copy Markdown
Collaborator

Claim

Every read of MSBuildAllProjects after the property pass is exact against MSBuild or declined. Between its property pass and its item pass, MSBuild's evaluator prepends the most recently written of the project and its imports to MSBuildAllProjects (Evaluator.SetAllProjectsProperty, MSBuild 18.9). It picks that file by file times the walk does not read. Before this PR, the walk kept the documents' last write, and committed what rested on it: the final value, a Compile item's spec, and the gates of ProjectReferences and PackageReferences.

Domain

  • Reads of MSBuildAllProjects, in any spelling, from the item pass on: item specs, item and item-group gates, reference gates, and the final property table.
  • A read during the property pass, before MSBuild's write, stays exact and committed.
  • A gate whose other operand decides it stays decided.

Change

At the start of the item pass, State::write_all_projects unbinds the name. A read of an unbound name then gets the judgement every undefined read gets (undefined_read_is_exact). An msbuild name is one MSBuild may define where no document does (is_toolset_initial_property_name), so the read is not exact. Each consumer already declines such a read, and decides without it where another operand settles the decision. The function asserts the prefix judgement it rests on.

Tests

all_projects_property_diff runs against design-time MSBuild:

  • Writes: none, an empty value, a value, off (the value the gates test), and the SDK's append.
  • Spellings: two.
  • Reference gates: one per project, so that a decline of one gate cannot hide a wrong decision of another behind the list it makes uncertain.
  • What it reads and grades:
    • the property pass's read, which must be exact, and committed wherever the write reads nothing;
    • the final value, which must be exact or declined;
    • a Compile item's spec, compared in order;
    • a ProjectReference and a PackageReference behind the project's gate: one the rewritten value closes (== 'off') or one it opens (!= '').
  • How the reference list is graded: the list's contract tolerates a missing edge behind a gate the walk cannot decide, so a certain list is held to no phantom edge. Separately, the walk's own read of the list (ItemRead::exact, the read that an @(ProjectReference) in the walk takes) must hold MSBuild's references whenever it is exact.

a_gate_another_operand_decides_keeps_compile_certain: a Compile item under false And '$(MSBuildAllProjects)' == 'off' keeps the list certain.

Mutation checks:

  • Without the unbind, the grid fails with 18 wrong commits. Among them is an exact @(ProjectReference) read of [] where MSBuild holds a reference.
  • A mutation that treats only the opening gate's unbound read as exact (!= '') fails the grid with 16 wrong commits. The same mutation passes the round 2 grid, which held both gates in one project.

The fix is just the unbind. Two earlier versions of it did more, and are gone:

  • A refused mark: mutation-checking it showed it moved nothing.
  • Dropping the name from the project-written map: that map publishes only names that are still bound, so the drop moved nothing either.

Decline cost

None measured. Each of these is unchanged:

  • the msbuild corpus differential's manifest (fsproj_msbuild_corpus_diff);
  • the SDK chain decline attribution;
  • the restore-cone census and its reads manifests (restore_cone_reads_*.txt);
  • every other manifest in the whole-project gate.

The real-SDK must-commit lists in fsproj_global_perturbation_diff and fsproj_sdk_import_graph_generative_diff still pass.

Review and gate

Codex ran four rounds against origin/main 193c28caa. Each finding is fixed with a test that fails without its fix.

  • Round 1:

    • R1: the first version marked the name stale. Reference and package gates ignore staleness, so a ProjectReference and a PackageReference gated on == 'off' were committed where MSBuild excludes them.
    • R2: staleness withdrew the whole Compile list for a gate another operand decides.
    • R3: Unset was not graded as an exact claim.
    • R3: Compile was compared as a set.
    • R3: no boundaries.tsv row for the grid.

    All five are fixed in ab1affabd by modelling MSBuild's write as one the walk does not compute.

  • Round 2:

    • R3: every reference gate compared with off, which the rewritten value never equals, so a walk that took the unbound name for an exact empty one would pass. Fixed in 0e65b17bd with a != '' gate and the ItemRead::exact check. Mutation-checking that fix is what showed the refused mark was redundant.
  • Round 3:

    • R3: both gates sat in one project. Fixed in 94b21a940.
  • Round 4: no findings.

The full gate ran locally on 0e65b17bd, because the build box is unreachable: fmt, clippy, doc, the msbuild corpus and SDK chain sweeps, cargo test --workspace, and every step of tools/ci/project-corpus-gate.sh. All are green, and the load average was 60–80. The #1132 sema wedge did not occur.

94b21a940 changes only all_projects_property_diff.rs. On it, fmt, clippy (borzoi-msbuild, all targets) and that test were rerun, all green. No other step reads that file.

Closes #1131

🤖 Generated with Claude Code

Smaug123 and others added 4 commits November 25, 2026 08:35
)

Between its property pass and its item pass, MSBuild's evaluator prepends
the most recently written of the project and its imports to
`MSBuildAllProjects` (`Evaluator.SetAllProjectsProperty`, 18.9). It
chooses that file by file times the walk does not read. The walk kept the
documents' last write, so an item reading the name, and the final table's
value, were committed and wrong.

At the start of the item pass, `MSBuildAllProjects` goes stale
(`PropertyMap::mark_stale`) under a cause naming that write, so every later
read is inexact. A read during the property pass, before the write, stays
exact. An unbound name already reads inexact (the `msbuild` prefix).

Test first: `all_projects_property_diff` writes nothing, an empty value, a
value, or the SDK's append, in two spellings. It reads the name from a
property during the property pass, from a `Compile` item, and from the
final table, each against design-time MSBuild. The two later reads failed
in 8 cases before the fix. The property pass's read must stay committed
wherever the write reads nothing.

Decline cost: the msbuild corpus differential and the SDK chain
attribution do not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 1 of review: a stale value reached `Compile` items and the final
table, but not the dependency items. `ProjectReference` and
`PackageReference` gates leave staleness out, so a reference gated on
`'$(MSBuildAllProjects)' == 'off'` was committed where MSBuild excludes it.
Staleness also withdrew the whole `Compile` list for a gate another
operand decides.

MSBuild's write between the passes is now modelled as a write the walk
refuses to compute (`State::write_all_projects`). The binding goes and the
name is marked refused, as for a document's write that cannot be
evaluated, so every later read is an undefined read that is not exact.
Each consumer already judges that (a reference's spec and gate, a
`Compile` spec, the final table), deciding without the name where another
operand settles the decision.

Tests:
- `all_projects_property_diff` adds a `ProjectReference` and a
  `PackageReference` gated on the name, and a write of the value they
  test. It compares `Compile` in order. It checks the final value and the
  property pass's read with every exact outcome (`Value`, and `Unset`
  against MSBuild's undefined), declining only `UnsetInexact` and
  `Untrusted`.
- `a_gate_another_operand_decides_keeps_compile_certain`: a `Compile` item
  under `false And '$(MSBuildAllProjects)' == 'off'` keeps the list
  certain.
- A `boundaries.tsv` row for the grid.

Without the write, the grid fails with 16 wrong commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 2 of review: the grid's reference gates all compare the name with
`off`, which the rewritten value never equals, so a walk that took the
unbound name for an exact empty one would still pass them.

- `all_projects_property_diff` adds a `ProjectReference` and a
  `PackageReference` behind `'$(MSBuildAllProjects)' != ''`, which MSBuild
  opens in every row. The reference list's contract tolerates a missing
  edge behind a gate the walk cannot decide, so a certain list is held to
  no phantom edge. And the walk's own read of the list, the one an
  `@(ProjectReference)` in it takes (`ItemRead::exact`), must hold
  MSBuild's references whenever it is exact. Without the write, that read
  is exact and empty where MSBuild holds `Q.fsproj`.

Mutation-checking the write showed its refused mark and its drop from the
project-written map change nothing: an unbound `msbuild` name already
reads inexact (`is_toolset_initial_property_name`), and the written map
publishes only bound names. `State::write_all_projects` now just unbinds
the name, and asserts the prefix judgement it rests on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its own

Round 3 of review: both reference gates sat in one project, so a decline
of the `== 'off'` gate made the whole list uncertain and hid a wrong
decision of the `!= ''` one. The package list had the same blind spot.

`all_projects_property_diff` now writes one `ProjectReference` and one
`PackageReference` per project, under one of `GATES`. A mutation that takes
the `!= ''` gate's unbound read for an exact one, while the `== 'off'` gate
still declines, passes the old grid and fails this one with 16 wrong
commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Smaug123
Smaug123 added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 8fdbd41 Nov 25, 2026
20 checks passed
@Smaug123
Smaug123 deleted the issue-1131-all-projects branch November 25, 2026 15:57
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.

msbuild: the item pass reads MSBuildAllProjects without MSBuild's SetAllProjectsProperty write

1 participant