Skip to content

Stabilize parallel optimizer Val iteration for deterministic synthetic names#19810

Open
T-Gro wants to merge 5 commits into
mainfrom
fix-deterministic-strings
Open

Stabilize parallel optimizer Val iteration for deterministic synthetic names#19810
T-Gro wants to merge 5 commits into
mainfrom
fix-deterministic-strings

Conversation

@T-Gro
Copy link
Copy Markdown
Member

@T-Gro T-Gro commented May 26, 2026

Partial fix for #19732.

Optimize/DetupleArgs and Optimize/InnerLambdasToTopLevelFuncs walked their Val sets in Val.Stamp order. Stamps are race-assigned during parallel type-check, so NiceNameGenerator calls fire in different orders per build, producing varying compiler-generated names for the same source.

Sort by valSourceOrderKey (source position with Stamp as final tiebreaker) before name generation. Follows #19028.

eng/test-determinism.cmd moved from Debug to Release config — Detuple/TLR only run under --optimize+, so the Debug job never exercised the race. Verified by draft #19838.

Out of scope

IlxGen.TypeDefsBuilder.AddTypeDef counter race (would churn ~190 EmittedIL baselines).

…19732)

Optimize/DetupleArgs.determineTransforms and Optimize/InnerLambdasToTopLevelFuncs.CreateNewValuesForTLR walked Val sets in Val.Stamp order. Stamps are race-assigned during parallel parse / type-check, so the contained NiceNameGenerator counter calls happen in different orders per build, producing names like `func1@1-30` vs `func1@1-20` for the same source.

Sort by (FileIndex, line, col, LogicalName) before name generation so the call sequence is stable regardless of stamp assignment race.

Also drops the stale OptimizeInputs.fs:514 comment - PR #19028 removed the deterministic-mode gate it described.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label May 26, 2026
Address multi-model review consensus:
- Add Val.Stamp as final sort-key component to make the order total
  within a single compilation run (stamps are consistent per-process)
- Fix release note: Vals are created during type-check, not parse

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@majocha
Copy link
Copy Markdown
Contributor

majocha commented May 27, 2026

We probably want the test-determinism to build Release config to actually test this 😅

@T-Gro T-Gro requested a review from abonie May 27, 2026 13:28
Copy link
Copy Markdown
Member Author

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review — all items addressed in follow-up commits: shared valSourceOrderKey helper, restored signpost comment in OptimizeInputs.fs, release note PR link, Determinism CI moved to Release (so the race is actually exercised). Verification draft #19838 confirms the Release CI catches the race.

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label May 27, 2026
…elease

- Extract valSourceOrderKey into TypedTreeOps.ExprConstruction (.fs + .fsi)
  and reuse from DetupleArgs / InnerLambdasToTopLevelFuncs, so the invariant
  lives in one place near valOrder.
- Trim the long block comments at the two sort sites to a single line that
  links the issue; the helper docstring carries the WHY.
- Restore a brief note in OptimizeInputs.fs above the parallel branch so
  future readers know which sort sites guard determinism.
- azure-pipelines-PR.yml: run eng/test-determinism.cmd in Release config.
  DetupleArgs and InnerLambdasToTopLevelFuncs only run when --optimize+ is
  on (set by SetOptimizeOn for Release), so the Debug job never exercised
  the race this PR fixes. Rename job to Determinism_Release.
- Release note: add PR link.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
T-Gro and others added 2 commits May 28, 2026 15:40
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Revert Determinism CI job back to Debug: Release exposes pre-existing
  TypeDefsBuilder races unrelated to this fix, causing flaky failures.
  Release coverage belongs in a follow-up when all races are fixed.
- Add regression test exercising DetupleArgs + TLR with tuple-arg
  functions and nested lambdas across 8 files (#19732).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants