dotnet / dotnet/fsharp

"FS3511: This state machine is not statically compilable." for large records in complex task

Open
#18,547 5 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-StateMachines Bug
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

**Repro steps**
The following compiles in Debug mode but warns in Release mode, with "error FS3511: This state machine is not statically compilable. A resumable code invocation at '(26,8--26,12)' could not be reduced. An alternative dynamic implementation will be used, which may be slower. Consider adjusting your code to ensure this state machine is statically compilable, or else suppress this warning.".

```fsharp
namespace Foo

type Thing =
{
A : int
B : int
C : int
D : int
E : int
F : int
G : int
H : int
I : int
J : int
K : int
L : int
M : int
N : int
O : int
}

module TestIt =

let thing () =
task {
match failwith "" with
| None -> return failwith ""
| Some _ ->

let blah =
task {
return failwith ""
}

printfn "hi"

return
{
A = failwith ""
B = failwith ""
C = failwith ""
D = failwith ""
H = failwith ""
F = failwith ""
G = failwith ""
I = failwith ""
E = failwith ""
J = failwith ""
K = failwith ""
L = failwith ""
M = failwith ""
N = failwith ""
O = failwith ""
}
|> Ok
}
```

This appears to be very sensitive to the details of this example. For example, removing a field from the record, it compiles cleanly. Reordering the `E` field to be in its alphabetical order also compiles cleanly. Removing the `printfn` compiles cleanly, and replacing the sub-`task` with a `Task.FromResult` compiles cleanly.

**Expected behavior**

Compilation succeeds identically in Release and Debug modes.

**Actual behavior**

Compilation fails in Release mode.

**Known workarounds**

Just ignore the warning and fall back to the dynamic version.

**Related information**

Provide any related information (optional):

```
$ dotnet --info
.NET SDK:
Version: 9.0.203
Commit: dc7acfa194
Workload version: 9.0.200-manifests.9df47798
MSBuild version: 17.13.20+a4ef1e90f

Runtime Environment:
OS Name: ubuntu
OS Version: 22.04
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/9.0.203/

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.4
Architecture: x64
Commit: f57e6dc747

.NET SDKs installed:
6.0.400 [/usr/share/dotnet/sdk]
8.0.408 [/usr/share/dotnet/sdk]
9.0.203 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.15 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.15 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/usr/share/dotnet]
```

I'm using FSharp.Core 8.0.100, if that's relevant.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.