dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.88k stars 783 forks source link

Compiler hangs wne compiling inline recursive invocation #17376

Closed miegir closed 2 months ago

miegir commented 3 months ago

Repro steps

  1. Create a new F# project with the following code in Program.fs:
    let rec inline test m = test m in test 0
  2. Compile the project using dotnet build.

In fact, any recursive inline function can be declared and then invoked somewhere.

Expected behavior

Compiler is expected to output some error because inline rec functions are not allowed and quit.

Actual behavior

Compiler outputs several errors and warnings and then hangs with continuously increasing memory consumption. Compiler output before hang (with paths stripped):

Program.fs(1,25): error FS1114: The value 'test' was marked inline but was not bound in the optimization environment [TestApp.fsproj]
Program.fs(1,16): error FS1113: The value 'test' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible [TestApp.fsproj]
Program.fs(1,25): warning FS1116: A value marked as 'inline' has an unexpected value [TestApp.fsproj]
Program.fs(1,25): warning FS1118: Failed to inline the value 'test' marked 'inline', perhaps because a recursive value was marked 'inline' [TestApp.fsproj]
Program.fs(1,25): error FS1114: The value 'test' was marked inline but was not bound in the optimization environment [TestApp.fsproj]
Program.fs(1,16): error FS1113: The value 'test' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible [TestApp.fsproj]
Program.fs(1,25): error FS1114: The value 'test' was marked inline but was not bound in the optimization environment [TestApp.fsproj]
Program.fs(1,16): error FS1113: The value 'test' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible [TestApp.fsproj]

N.B. This bug is contrived of course. I never thought of writing such code in real applications.

Martin521 commented 3 months ago

For me (net8) the compiler runs (with similar error messages) and finishes normally. Which SDK / compiler / TFM are you using?

Martin521 commented 2 months ago

Actually, after updating from 8.0.206 to 8.0.302 I have exactly the behavior described in the OP.