-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fable hangs on active pattern usage #1767
Comments
Hmm, it looks like there's some infinite recursion happening here. Not sure what's the problem but I see you're suppressing warning 40 in that file. I think in those cases, the F# compiler injects some code to check the value is correctly initialized. Although we have some support for that (see #237) it's probably flaky and may not work in complicated cases like yours. Would it be possible to refactor the code to avoid the warning? ...without the "nowarn" cheat ;) |
It is not possible to refactor to avoid the warning--recursion is a necessary part of left-recursive packrat parsing, because I need to define the recursive active pattern in such a way that it can be cached and called repeatedly until a fixpoint is reached. (That is what the pack function does.) Note also that the F# compiler does not hang during regular F# compilation of this file (e.g. for unit tests), only in Fable. |
I also want to note that in this particular case, deleting those four lines is an acceptable workaround--they represent little-used grammar productions that I can live without. |
I actually found a better workaround for my use case. The issue is that the previous workaround was not robust: I still ran into situations where the compiler would apparently hang. I wound up doing two things: I was ultimately able to follow Alfonso's suggestion to remove warning 40 by using stateful variables for my recursive pattern definitions instead of relying on compiler magic, which was enough to prevent dotnet.exe from blowing up to 19GB, but there were still perf issues (10 minutes to compile instead of 45 seconds). So the second thing I ultimately did was to flatten my active patterns by defining helper active patterns. Snippet illustrating both techniques:
Additional details at this commit: MaxWilson/ShiningSword@1c56935 |
Good to hear you managed to fix it @MaxWilson, thanks for sharing! |
Should I close this issue, or leave it open since technically a workaround isn't a fix? |
We can leave it open in case there's some day time to reproduce and try to fix this :) |
Sounds like what I've previously reported at dotnet/fsharp#4691 |
Closing as there's already an issue to track this in the fsharp repo, thanks @cmeeren! |
Description
In some cases, Fable hangs at compile time even as dotnet.exe grows to a multi-gigabyte memory footprint.
Repro code
I don't have a standalone repro unfortunately, but I do have a minimal delta in the git repo here. Branch repro/fableHangs fails to compile; branch repro/fableHangsWorkaround succeeds. The only difference between them is that the repro has a few extra cases in its active patterns. Deleting the following lines makes fable no longer hang:
Expected and actual results
Expected: fable either compiles or emits an error.
Actual: fable grows to a multi-GB footprint (dotnet.exe is around 19GB) and then hangs.
Known workarounds
In this case, "delete those four lines" is an acceptable workaround. Those cases represent edge cases, and simply failing to match those edge cases is not a big problem for me. Filing the issue for awareness, but I am not blocked.
Related information
Fable version: 2.1.12
Operating system: Windows 10
The text was updated successfully, but these errors were encountered: