Constant folding for large number of constants can crash compiler
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
Please provide a succinct description of the issue.
If an expression gets too long or if there's too many values the compiler crashes.
Provide the steps required to reproduce the problem:
1. Step A
let sum = 1 + 1 + 1 + ( ... keep saying + 1, 3000 times)
2. Step B
dotnet build
/usr/local/share/dotnet/sdk/3.1.302/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6006: "dotnet" exited with code 134. [/Users/m/repos/michael/benchmark-variables/benchmark-fsharp/benchmark-fsharp.fsproj]
That's one way to crash it. Another way that makes `dotnet build` actually segfault is to make to many value bindings like:
let v0 = 0.0
let v1 = 1.1
...
let v3000 = 3000.3000
Then sum them:
sum = v0 + v1 + v2 ... v3000
In both cases the compiler can handle about 2000 things, but crashes around 3000.
I was trying something similar with the dotnet csharp compiler. It can go a bit further to 10,000 class members, but crashes before 100,000. The Mono csc compiler can handle anything I throw at it but resulting code performs the worst.
[benchmark-fsharp.zip](https://github.com/dotnet/fsharp/files/5013068/benchmark-fsharp.zip)
You can run `go.sh` in the zip file. There's a couple of python scripts which can generate different sources to stress the compiler.
**Expected behavior**
Don't crash
**Actual behavior**
Crash
**Known workarounds**
**Related information**
Provide any related information (optional):
* Operating system
macOS
* .NET Runtime kind (.NET Core, .NET Framework, Mono)
core 3.1
* Editing Tools (e.g. Visual Studio Version, Visual Studio)
vim
Contributor guide
Assessment
This issue has not been assessed yet.