You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
64-bit fscAnyCpu.exe uses more stack than 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022) #12322
A project that is part of a reasonably complex solution is failing to build in 2022 due to the compiler crashing. I've managed to boil things down to a simple, standalone repro shown below.
Repro steps
The following simplified code typifies that which is causing the compiler to crash:
modulerepro_fscanycpu_failure//// This builds fine in VS2019, but fails under VS2022 with://// 1> Process is terminated due to StackOverflowException.// 1> C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools\Microsoft.FSharp.Targets(317,9): error MSB6006: "fscAnyCpu.exe" exited with code -1073741571.//// Opening this file in the VS2022 editor will also crash, presumably for the same underlying reason.//typeReproBuilder()=member_.Delay x = x ()member_.Yield(x)= x
member_.Combine(x,y)= x + y
letrepro= ReproBuilder ()letcallSite()=
repro {// Commenting out some of the below is enough to avoid StackOverflow on my machine.012345678901234567890123456789012345678901234}
@kentcb
I think this is something related to TFM of the nuget package you used.
Have you updated the microsoft.servicefabric nuget package? I've used version 8.1.335 and I have no problem.
@eriawan Yes, I did try upgrading to latest Microsoft.ServiceFabric.Services.Remoting to no avail. I've also tried to extract this into a minimal repro, but no luck.
Happy to upload a binlog, but is there somewhere private I can upload it or someone I can share a OneDrive link with?
By building with more diagnostics, I could see that fsAnyCpu.exe was terminating due to stack overflow when building my Types project. By process of elimination, I identified which file was causing the crash. Even opening this file in the editor would eventually crash VS, so I had to edit it in VS2019, but doing so allowed me to identify the code that was triggering the regression...
It's a custom CE we use to define codecs. We use it extensively throughout our entire solution, and yet this one particular case was causing a SO. By playing around with it, I determined that there was no particular line triggering the SO, but rather the sheer number of them. It was happy with up to 38 lines, but the 39th would trigger a crash (either in editor, or in compiler, so presumably the same SO crash).
Of course, there must be something our CE is doing, or something about what we're doing on each line to trigger the SO. And of course, something about FSC must have changed such that this is crashing where it never previously did. That's where I'm at and will possibly handball this issue internally.
@jimfoye Hmm, maybe, but I use Windows and sounds like it's a non-issue there. I'll try and find some time to repro this in a standalone project later in the week.
@kentcb Thanks for the repro. We'll work on it, we don't have a large-input stress test of that size, and we must be doing something quadratic or worse.
Reacted by Eriawan Kusumawardhono, Heron Barreto Peixoto and Jay
So it seems that F# 6 code is not really at fault (e.g. net472, net5 process about the same), but rather the switch to 64-bit compiler for .NET Framework by default is causing 2x stack to be used.
Note that we're seeing the problems in large computation expressions in particular because these do not produce SyntaxTree and TypedTree results that are processed "linearly" in the compiler (e.g. unlike large lists, or large lists of let and sequential execution), rather they are treated as large nested method application expressions.
@KevinRansom Note that we have a disparity in input size processing capabilities between .NET SDK and .NET Framework in any case and so there is an implicit dependency on the .NET Framework compiler being picked up by uses here. We should keep trying to pin down input processing sizes and make sure that .NET Core compiler is always able to process inputs as least as large as .NET Framework.
I get the same error (fscAnyCpu.exe exiting with -1073741571) in VS 2022 for a solution that builds in VS 2019. It does seem to be computation-expression related—in my case, it seems to be the gen computation expression from FsCheck.
is not sufficient to stop IDE failures, because the IDE is now running as 64-bit. Instead you should simply make your problematic inputs smaller as a workaround.
I suppose we must work on linearizing the processing of the above.
changed the title [-]Project that builds in VS2019 fails to build in VS2022[/-][+]64-bit fscAnyCpu.exe uses more stack and can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/+]on Nov 17, 2021
changed the title [-]64-bit fscAnyCpu.exe uses more stack and can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/-][+]64-bit fscAnyCpu.exe uses more stack,can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/+]on Nov 17, 2021
changed the title [-]64-bit fscAnyCpu.exe uses more stack,can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/-][+]64-bit fscAnyCpu.exe uses more stack than 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/+]on Nov 17, 2021
@dsyme I'm not sure if this is what you were looking for, or whether it adds anything beyond @kentcb's minimal repro above, but the following snippet with 115 let!s in FsCheck's gen computation expression will crash VS 2022 if you open it in an F# script file (which however compiles fine when passed into dotnet fsi directly). The ~114 let! limit for the gen computation expression accords with what I see in my actual projects (i.e., files with fewer let!s are fine, but files with more cause VS 2022 to crash).
If you remove one let!, leaving only 114, it will not crash VS.
Separately, adding <FSharpPrefer64BitTools>false</FSharpPrefer64BitTools> to the affected fsproj files as you suggested above does indeed allow them to build in VS (as long as you don't open the files with the big computation expressions).
It may also be worth noting that I have another (custom, unrelated) computation expression in a separate project which in one case is used with more than 200 and!s—this also does not compile in VS 2022, but it does not crash VS, and the failure to compile seems to be for a different reason:
error FS0073: internal error: Expression is too large and/or complex to emit. Method name: '...'. Recursive depth: 140.
I at first suspected that the difference between this case and that of gen is that most of this computation expression builder's methods are marked inline, while those for gen are not. That appears not to be the case, though: it just seems that the compiler will tolerate more and!s (closer to ~300) than let!s.
In this case, however, setting FSharpPreferNetFrameworkTools to false allows my project to build without error in VS 2022 (it builds without error in VS 2019 and with dotnet build using the .NET 5 or 6 SDKs).
Realistically our three shipped compilers (netfx 32, netfx 64, net6) do have different capacity limits along some input dimensions. Ideally the capacity limits would be identical across all three , but that's really, really hard to arrange without avoiding the use of stack altogether.
I will look at the specific case of these computation expressions. We do have the option of simply switching to a new stack, for example, at a particular expression depth.
@jayhill@patroeper Thank you for the repro, it was a new problem related to writing debug scopes. I'm not sure why our existing testing didn't catch it as we certainly have test with hundreds or thousands of let . Hmmmm....
In any case, a fix and testing is included in #12420
@jayhill@patroeper A note on your repro: you are using --debug:full (<DebugType>full</DebugType>) instead of --debug:portable (portable`). For some variations of your example, and among other problems, this casuses a stack overflow in the C++ code we use to emit old-style PDBs. The solution for this is to move to emit portable PDBs, so add this to your project files:
<DebugType>portable</DebugType>
I think some of our fixes to debugging scopes exposed this problem. It's not a thing we can fix, and it is likely we will just accept these new capacity limits for old-style PDBs and instead ask people to switch to emit portable PDBs.
Activity
smoothdeveloper commentedon Nov 1, 2021
@kentcb just in case it has an impact, can you try compiling the same project in Release mode (assuming it was Debug mode you tried)?
kentcb commentedon Nov 1, 2021
@smoothdeveloper Alas, same problem.
eriawan commentedon Nov 1, 2021
@kentcb
I think this is something related to TFM of the nuget package you used.
Have you updated the microsoft.servicefabric nuget package? I've used version 8.1.335 and I have no problem.
See also
https://www.nuget.org/packages/Microsoft.ServiceFabric/8.1.335
cartermp commentedon Nov 1, 2021
@kentcb if you're allowed to build with the
/blflag and upload the binlog then that makes it a lot easier for folks to diagnose.vzarytovskii commentedon Nov 1, 2021
Yeah, binlog or minimal repro would be ideal.
kentcb commentedon Nov 1, 2021
@eriawan Yes, I did try upgrading to latest
Microsoft.ServiceFabric.Services.Remotingto no avail. I've also tried to extract this into a minimal repro, but no luck.Happy to upload a binlog, but is there somewhere private I can upload it or someone I can share a OneDrive link with?
kentcb commentedon Nov 1, 2021
By building with more diagnostics, I could see that
fsAnyCpu.exewas terminating due to stack overflow when building myTypesproject. By process of elimination, I identified which file was causing the crash. Even opening this file in the editor would eventually crash VS, so I had to edit it in VS2019, but doing so allowed me to identify the code that was triggering the regression...It's a custom CE we use to define codecs. We use it extensively throughout our entire solution, and yet this one particular case was causing a SO. By playing around with it, I determined that there was no particular line triggering the SO, but rather the sheer number of them. It was happy with up to 38 lines, but the 39th would trigger a crash (either in editor, or in compiler, so presumably the same SO crash).
Of course, there must be something our CE is doing, or something about what we're doing on each line to trigger the SO. And of course, something about FSC must have changed such that this is crashing where it never previously did. That's where I'm at and will possibly handball this issue internally.
jimfoye commentedon Nov 2, 2021
Perhaps related to #9231?
kentcb commentedon Nov 2, 2021
@jimfoye Hmm, maybe, but I use Windows and sounds like it's a non-issue there. I'll try and find some time to repro this in a standalone project later in the week.
kentcb commentedon Nov 4, 2021
@vzarytovskii @cartermp Please see updated issue description for a simple repro
dsyme commentedon Nov 5, 2021
@kentcb Thanks for the repro. We'll work on it, we don't have a large-input stress test of that size, and we must be doing something quadratic or worse.
ly29 commentedon Nov 9, 2021
Noticed something similar which crashes Visual Studio 2022 hard.
4 remaining items
dsyme commentedon Nov 17, 2021
For the first repro up above:
F# 5 net472 VS2019 shipped fsc.exe 32-bit blows stack with > ~80 nested Combine/Yield in computation expression
"c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools\fsc.exe" a.fsF# 6 net472 VS2022 shipped fsc.exe 32-bit blows stack with > ~75 nested Combine/Yield in computation expression
"c:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools\fsc.exe" a.fsF# 6 net472 VS2022 shipped fscAnyCpu.exe 64-bit blows stack with > ~40 nested Combine/Yield in computation expression
"c:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools\fscAnyCpu.exe" a.fsF# 5 net5 SDK fsc.dll 64-bit blows stack with > ~65 nested Combine/Yield in computation expression
dotnet "\Program Files\dotnet\sdk\5.0.403\FSharp\fsc.dll" a.fsF# 6 net5 SDK fsc.dll 64-bit blows stack with > ~75 nested Combine/Yield in computation expression
dotnet "\Program Files\dotnet\sdk\6.0.100\FSharp\fsc.dll" a.fsSo it seems that F# 6 code is not really at fault (e.g. net472, net5 process about the same), but rather the switch to 64-bit compiler for .NET Framework by default is causing 2x stack to be used.
Note that we're seeing the problems in large computation expressions in particular because these do not produce SyntaxTree and TypedTree results that are processed "linearly" in the compiler (e.g. unlike large lists, or large lists of
letand sequential execution), rather they are treated as large nested method application expressions.@KevinRansom Note that we have a disparity in input size processing capabilities between .NET SDK and .NET Framework in any case and so there is an implicit dependency on the .NET Framework compiler being picked up by uses here. We should keep trying to pin down input processing sizes and make sure that .NET Core compiler is always able to process inputs as least as large as .NET Framework.
@brianrourkeboll Do you have a public repro?
Thanks, we will use this to form the basis of a repro too
dsyme commentedon Nov 17, 2021
Note that this workaround:
is not sufficient to stop IDE failures, because the IDE is now running as 64-bit. Instead you should simply make your problematic inputs smaller as a workaround.
I suppose we must work on linearizing the processing of the above.
dsyme commentedon Nov 17, 2021
@jimfoye I investigated the failure building Debug FSharp.Data - see fsprojects/FSharp.Data#1411 for the details, and it's related to the separate problem #12413
[-]Project that builds in VS2019 fails to build in VS2022[/-][+]64-bit fscAnyCpu.exe uses more stack and can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/+][-]64-bit fscAnyCpu.exe uses more stack and can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/-][+]64-bit fscAnyCpu.exe uses more stack,can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/+][-]64-bit fscAnyCpu.exe uses more stack,can't compile inputs accepted by 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/-][+]64-bit fscAnyCpu.exe uses more stack than 32-bit fsc.exe (was: Project that builds in VS2019 fails to build in VS2022)[/+]brianrourkeboll commentedon Nov 17, 2021
@dsyme I'm not sure if this is what you were looking for, or whether it adds anything beyond @kentcb's minimal repro above, but the following snippet with 115
let!s in FsCheck'sgencomputation expression will crash VS 2022 if you open it in an F# script file (which however compiles fine when passed intodotnet fsidirectly). The ~114let!limit for thegencomputation expression accords with what I see in my actual projects (i.e., files with fewerlet!s are fine, but files with more cause VS 2022 to crash).Repro
If you remove one
let!, leaving only 114, it will not crash VS.Separately, adding
<FSharpPrefer64BitTools>false</FSharpPrefer64BitTools>to the affected fsproj files as you suggested above does indeed allow them to build in VS (as long as you don't open the files with the big computation expressions).It may also be worth noting that I have another (custom, unrelated) computation expression in a separate project which in one case is used with more than 200
and!s—this also does not compile in VS 2022, but it does not crash VS, and the failure to compile seems to be for a different reason:error FS0073: internal error: Expression is too large and/or complex to emit. Method name: '...'. Recursive depth: 140.I at first suspected that the difference between this case and that of
genis that most of this computation expression builder's methods are markedinline, while those forgenare not. That appears not to be the case, though: it just seems that the compiler will tolerate moreand!s (closer to ~300) thanlet!s.In this case, however, setting
FSharpPreferNetFrameworkToolstofalseallows my project to build without error in VS 2022 (it builds without error in VS 2019 and withdotnet buildusing the .NET 5 or 6 SDKs).dsyme commentedon Nov 18, 2021
@brianrourkeboll Thank you
Realistically our three shipped compilers (netfx 32, netfx 64, net6) do have different capacity limits along some input dimensions. Ideally the capacity limits would be identical across all three , but that's really, really hard to arrange without avoiding the use of stack altogether.
I will look at the specific case of these computation expressions. We do have the option of simply switching to a new stack, for example, at a particular expression depth.
dsyme commentedon Nov 18, 2021
This is fixed in #12420, at least for practical purposes, given the current repros.
jayhill commentedon Nov 18, 2021
Wow — impressive @dsyme!
Would this also somehow mitigate this situation and repro, in which only
letbindings — not custom CEs — are in play?That is the same issue that I'm experiencing.
dsyme commentedon Nov 18, 2021
No, but we can get that fixed too
dsyme commentedon Nov 19, 2021
@jayhill @patroeper Thank you for the repro, it was a new problem related to writing debug scopes. I'm not sure why our existing testing didn't catch it as we certainly have test with hundreds or thousands of
let. Hmmmm....In any case, a fix and testing is included in #12420
dsyme commentedon Nov 19, 2021
@jayhill @patroeper A note on your repro: you are using
--debug:full(<DebugType>full</DebugType>) instead of--debug:portable (portable`). For some variations of your example, and among other problems, this casuses a stack overflow in the C++ code we use to emit old-style PDBs. The solution for this is to move to emit portable PDBs, so add this to your project files:I think some of our fixes to debugging scopes exposed this problem. It's not a thing we can fix, and it is likely we will just accept these new capacity limits for old-style PDBs and instead ask people to switch to emit portable PDBs.
baronfel commentedon Jan 7, 2022
@dsyme should this be closed since #12420 was merged?