Skip to content

Enable graph-based type checking, parallel optimizations and ILX gen in deterministic build - #19028

Merged
T-Gro merged 28 commits into
dotnet:mainfrom
majocha:parallel-determinism
Nov 12, 2025
Merged

Enable graph-based type checking, parallel optimizations and ILX gen in deterministic build#19028
T-Gro merged 28 commits into
dotnet:mainfrom
majocha:parallel-determinism

Conversation

@majocha

@majochamajocha commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

This as a follow up to #18998:

  • adds tests for added dependency graph supported scenarios: script compilation mode and misordered .fs .fsi files
  • updates naming and adds comments wrt to the above
  • enables graph based type checking in deterministic builds
  • enables parallel optimizations in deterministic builds
  • enabled parallel ilx gen in deterministic builds

Necessary changes to enable determinism:

  • sort things when writing PDB
  • update NiceNameGenerator to produce stable names
  • update generation of array literal types (multiple delayed gens would place then under "private implementation" concurrently, resulting in non-deterministic order)

There are no additional tests for determinism, it is currently tested only by running the test-determinism script locally and in the CI.

One issue needed investigation: type extensions with mismatched type argument names can break determinism:

// in one filetypeLexBuffer<'Char>// in another filetypeLexBuffer<'char>with

Either char or Char will end up in the IL.

This is related to #15287 and needs work: #19033

@github-actions

github-actionsBot commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/11.0.0.md

@majocha

majocha commented Oct 24, 2025

Copy link
Copy Markdown
ContributorAuthor

Typar name not always picked up from the source (?)
image

But wth is going on here? Looks like a type parameter 'Char gets randomly converted to char.

@majocha

Copy link
Copy Markdown
ContributorAuthor

Good thing is I got exactly the same diff locally as in the CI, so it is already deterministic in this regard 😁

@majocha

majocha commented Oct 24, 2025

Copy link
Copy Markdown
ContributorAuthor

Ok so it's not a type parameter but actual char type. It just randomly gets emitted either as Char or char.

Edit: Nope it was because of not unified type argument names between type declaration and extensions.
NOTE: It needs an actual separate fix.

@majocha
majochaforce-pushed the parallel-determinism branch from eb10796 to 128da51CompareOctober 24, 2025 14:17
@majocha

majocha commented Oct 24, 2025

Copy link
Copy Markdown
ContributorAuthor
image Hallelujah.

Ilx gen is still disabled. Only optimization and graph checking works.

portable pdb test needs updating, too.

@majochamajocha changed the title WIP deterministic generated namesWIP deterministic parallel compilationOct 24, 2025
@majocha

majocha commented Oct 24, 2025

Copy link
Copy Markdown
ContributorAuthor

TODO:

CompilerGeneratedName("T"+ string (newUnique ())+"_"+ string size +"Bytes")// Type names ending ...$T<unique>_37Bytes

and

letilFieldName= CompilerGeneratedName("field"+ string (newUnique ()))

Apart from stabilizing these generated names, the order of of generated IL also needs to be deterministic. Specifically, in FCS.dll generated types in PrivateImplementationDetails are sometimes in different order.

Possibly relevant:

member_.GenerateRawDataValueType(cloc,size)=
// Byte array literals require a ValueType of size the required number of bytes.
// With fsi.exe, S.R.Emit TypeBuilder CreateType has restrictions when a ValueType VT is nested inside a type T, and T has a field of type VT.
// To avoid this situation, these ValueTypes are generated under the private implementation rather than in the current cloc. [was bug 1532].
letcloc= CompLocForPrivateImplementationDetails cloc
rawDataValueTypeGenerator.Apply((cloc, size))

@majochamajocha changed the title WIP deterministic parallel compilationWIP Make more parallel compilation features deterministicOct 25, 2025
@majochamajocha changed the title WIP Make more parallel compilation features deterministicMake graph-based type checking and parallel optimizations deterministicOct 26, 2025
@majocha
majochaforce-pushed the parallel-determinism branch from f837b8d to c032cc3CompareOctober 26, 2025 19:51
@majochamajocha changed the title Make graph-based type checking and parallel optimizations deterministicEnable graph-based type checking and parallel optimizations and ILX gen in deterministic buildOct 27, 2025
@majocha
majocha marked this pull request as ready for review October 27, 2025 06:51
@majocha
majocha requested a review from a team as a code ownerOctober 27, 2025 06:51
@majocha
majochaforce-pushed the parallel-determinism branch from 5d68b92 to caebe81CompareOctober 27, 2025 18:42
it needs to be made compatible with parallel checking
Comment threadsrc/Compiler/AbstractIL/ilwritepdb.fs
Comment threadsrc/Compiler/Checking/CheckDeclarations.fs Outdated
@majocha
majochaforce-pushed the parallel-determinism branch from 513aa4f to 556f28cCompareNovember 9, 2025 13:20

@T-GroT-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Waiting for #19062

@github-project-automationgithub-project-automationBot moved this from New to In Progress in F# Compiler and ToolingNov 10, 2025
@T-Gro

Copy link
Copy Markdown
Member

One thing where I do not have high confidence in the automated test suite (==> will need more manual testing and dogfooding) is the debugger support via pdbs.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants

@majocha@T-Gro@nojaf@abonie