Repository navigation
Description
In an existing checkout, a change to FCSCommitHash does not reach the generated FSComp.fs. The vendored FSharpEmbedResourceText task stays the one built from the previous FCS commit, and FSComp.fs keeps that commit's boilerplate. Fresh clones, CI and released packages are not affected: they build the task and generate FSComp.fs from scratch.
How it went stale
FCSCommitHash moved to 409c7a62 in de77b27, for dotnet/fsharp#20658 (Build parser diagnostic messages without sprintf). That PR changed src/FSharp.Build/FSharpEmbedResourceText.fs, the generator's boilerplate, and not FSComp.txt:
- before it, an accessor with arguments goes through
GetStringFunc,createMessageStringandFSharpValue.MakeFunction; - after it, the generator formats with
String.Format(FormatMessage).
Three things keep the old code in an existing checkout:
BuildFantomasBuildTasksinsrc/Fantomas.FCS/Fantomas.FCS.fsprojonly runs when the task assembly is missing (Condition="!Exists('$(FantomasBuildTasksAssembly)')"), so the task is never rebuilt from the new.deps/$(FCSCommitHash)/src/FSharp.Build/FSharpEmbedResourceText.fs.- The generator's own up-to-date check compares
FSComp.txtwith its outputs and nothing else. A change to the generator alone never regeneratesFSComp.fs, and aFSComp.txtdownloaded for the new commit can be older than anFSComp.fsgenerated before. - The
UsingTaskhas noTaskFactory="TaskHostFactory", so a reused MSBuild node keeps the task assembly loaded. A rebuilt task would not be picked up while that node lives, and on Windows the assembly is locked.
Seen in two checkouts at FCSCommitHash 409c7a62:
| Checkout | Fantomas.FCS.BuildTasks.dll |
FSComp.fs |
|---|---|---|
main at 75cf73f |
built 16 September, has GetStringFunc, no FormatMessage |
regenerated 14 October, has mkFunctionValue |
v9.0 at 9f7699a |
built 6 October, has GetStringFunc, no FormatMessage |
regenerated 14 October, has mkFunctionValue |
Why it matters
On the JIT the old boilerplate works, which is why nothing showed on main. Under Native AOT it fails for every message with an int argument, 54 of the 1785 accessors, because DynamicFunction<int, string> has no native code. Found while publishing fantomas-tools' preview lambda with Native AOT against a local v9.0 checkout: let a = "Ā"B was answered with
'Microsoft.FSharp.Reflection.DynamicFunction`2[System.Int32,System.String]' is missing native code or metadata.
in place of "This byte array literal contains 1 characters that do not encode as a single byte", and the diagnostic lost its range. The publish also warns about FSComp.SR.mkFunctionValue (IL2062, IL2072), which knownAotWarnings does not list. The fix #20658 was taken for never reached the checkout.
Compared with dotnet/fsharp
At the same commit, GenerateFantomasTextResources matches the text half of GenerateFSharpTextResources in Microsoft.FSharp.Targets, and the FSComp.txt item and the task's parameters match too. The differences are in how the task is found and loaded, in FSharpBuild.Directory.Build.targets:
- dotnet/fsharp normally takes the task from its Proto bootstrap (
$(ProtoOutputPath)\fsc\FSharp.Build.dll), which its build script rebuilds.BuildFantomasBuildTasksfollows its fallback,BuildFSharpBuildForResourceGeneration,!Existscondition included: the same blind spot, on a path dotnet/fsharp rarely takes and Fantomas always does. - its
UsingTaskhasTaskFactory="TaskHostFactory", with the comment "TaskHostFactory keeps the node from locking what it loads."
Possible fix
- Put
$(FCSCommitHash)in the output path ofFantomas.FCS.BuildTasks, and in the folder the generated sources go to, so a hash change gives a fresh task and fresh output. - Add
TaskFactory="TaskHostFactory"to theUsingTask.
A check: in a checkout built before a hash change, build again and look for FormatMessage and no GetStringFunc in the generated FSComp.fs.
Workaround
rm -rf artifacts/bin/Fantomas.FCS.BuildTasks artifacts/obj/Fantomas.FCS
dotnet build src/Fantomas.Core
Activity