Fable icon indicating copy to clipboard operation
Fable copied to clipboard

Stack overflow when compiling large discriminated union

Open Bjorn-Strom opened this issue 1 year ago • 2 comments

Description

Stack overflow when compiling large discriminated union. We have a project with a big discriminated union. To reproduce I made one with 400 cases.

It does compile in the fable repl, but not on my machine.

Repro code

It does compile in the Fable repl, for some reason. But included the repl to share code.

REPL.

Expected and actual results

I expect that it would compile, like it does in the normal F# compiler. Fable 3 and in the fable repl.

Error:

Started Fable compilation...
Stack overflow.
Repeat 392 times:
--------------------------------
   at Fable.Transforms.AST.visit(Microsoft.FSharp.Core.FSharpFunc`2<Fable.AST.Fable.Expr,Fable.AST.Fable.Expr>, Fable.AST.Fable.Expr)
   at Fable.Transforms.AST.visitFromOutsideIn(Microsoft.FSharp.Core.FSharpFunc`2<Fable.AST.Fable.Expr,Microsoft.FSharp.Core.FSharpOption`1<Fable.AST.Fable.Expr>>, Fable.AST.Fable.Expr)
   at [email protected](Fable.AST.Fable.Expr)
--------------------------------
   at Fable.Transforms.AST.visit(Microsoft.FSharp.Core.FSharpFunc`2<Fable.AST.Fable.Expr,Fable.AST.Fable.Expr>, Fable.AST.Fable.Expr)
   at Fable.Transforms.AST.visitFromOutsideIn(Microsoft.FSharp.Core.FSharpFunc`2<Fable.AST.Fable.Expr,Microsoft.FSharp.Core.FSharpOption`1<Fable.AST.Fable.Expr>>, Fable.AST.Fable.Expr)
   at Fable.Transforms.FableTransforms+getTransformations@663-3[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Invoke(System.__Canon, Fable.AST.Fable.Expr)
   at Microsoft.FSharp.Collections.ListModule.Fold[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>>, System.__Canon, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Fable.Transforms.FableTransforms.transformMemberBody@682(Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Core.FSharpFunc`2<Fable.Compiler,Microsoft.FSharp.Core.FSharpFunc`2<Fable.AST.Fable.Expr,Fable.AST.Fable.Expr>>>, Fable.Compiler, Fable.AST.Fable.MemberDecl)
   at Fable.Transforms.FableTransforms+transformMemberBody@682-1.Invoke(Fable.Compiler, Fable.AST.Fable.MemberDecl)
   at Fable.Transforms.FableTransforms.transformDeclaration(Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Core.FSharpFunc`2<Fable.Compiler,Microsoft.FSharp.Core.FSharpFunc`2<Fable.AST.Fable.Expr,Fable.AST.Fable.Expr>>>, Fable.Compiler, Fable.AST.Fable.File, Fable.AST.Fable.Declaration)
   at [email protected](Fable.AST.Fable.Declaration)
   at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>, Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Microsoft.FSharp.Primitives.Basics.List.map[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Microsoft.FSharp.Collections.ListModule.Map[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,System.__Canon>, Microsoft.FSharp.Collections.FSharpList`1<System.__Canon>)
   at Fable.Transforms.FableTransforms.transformFile(Fable.Compiler, Fable.AST.Fable.File)
   at [email protected](Microsoft.FSharp.Core.Unit)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Microsoft.FSharp.Control.AsyncActivation`1<System.__Canon>, System.__Canon, Microsoft.FSharp.Core.FSharpFunc`2<System.__Canon,Microsoft.FSharp.Control.FSharpAsync`1<System.__Canon>>)
   at Microsoft.FSharp.Control.Trampoline.Execute(Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Control.AsyncReturn>)
   at <StartupCode$FSharp-Core>[email protected](System.Object)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

Related information

  • Fable version: dotnet fable --version - 4.1.4
  • Operating system - MacOS Ventura 13.0

Bjorn-Strom avatar Sep 05 '23 16:09 Bjorn-Strom

Perhaps related to #3501

I also think to remember that in the past .NET or Fable had some issues with Mac OS performance. Could be worth it to dig in that direction too if needed.

MangelMaxime avatar Sep 05 '23 18:09 MangelMaxime

I confirm that the problem is related to Mac OS, as when using Gitpod (via https://github.com/MangelMaxime/template-gitpod-fable-4-vite-react) the project compile fine.

And the Gitpod VM has only 8Gb of ram while on my Mac I have the stack overflow exception.

MangelMaxime avatar Sep 05 '23 19:09 MangelMaxime