Skip to content
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

fsc.exe fails with StackOverflowException on a big file. #851

Closed
smoothdeveloper opened this issue Jan 5, 2016 · 30 comments
Closed

fsc.exe fails with StackOverflowException on a big file. #851

smoothdeveloper opened this issue Jan 5, 2016 · 30 comments

Comments

@smoothdeveloper
Copy link
Contributor

I have a project which fails to compile with this output in VS:

error MSB6006: "fsc.exe" exited with code -1073741571.

When I compile from command line:

"C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\fsc.exe" -o:obj\Debug\myassembly.dll -g --debug:full --noframework --define:DEBUG --define:TRACE --doc:..\..\..\..\bin\Debug\myassembly.XML --optimize- --tailcalls- -r:C:\work\gitsvnclone\packages\FSharp.Core\lib\net40\FSharp.Core.dll -r:C:\work\gitsvnclone\packages\FSharp.Data.SqlClient\lib\net40\FSharp.Data.SqlClient.dll -r:C:\work\gitsvnclone\UPLAN\Lib\lcg.Shared\lcg.Common.FrameworkExtensions.dll -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Numerics.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" --target:library --warn:3 --warnaserror:76 --vserrors --LCID:1033 --utf8output --fullpaths --flaterrors --highentropyva- --sqmsessionguid:be8a0043-8b0f-4af0-ab48-a438b86f0a63 --keyfile:"../../../../Tools/Signing/uplan_signing.snk" "C:\Users\gauthier.segay\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.fs" all the .fs files

I get this:

Microsoft (R) F# Compiler version 14.0.23413.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

Process is terminated due to StackOverflowException.

There is a big file (8k lines) with a lots of static declarations in the project.

Is there anyway I can investigate the stack trace before it fails?

@smoothdeveloper
Copy link
Contributor Author

Compiling the same project in release works.

@smoothdeveloper
Copy link
Contributor Author

@xenocons mentionned that disabling XML documentation generation could help (There are lots of modules, some are nested a bit since F# does'nt allow inner type definition).

I haven't figured yet if it's the reason for this error but it's worth a look.

@abelbraaksma
Copy link
Contributor

This issue may be related to my previously reported issue where I demonstrate that a StackOverflowException in fsc.exe is raised on large lambdas: #779. Perhaps you can compare the repro in that issue with your current code and create an additional repro here in case it is a different issue?

@smoothdeveloper
Copy link
Contributor Author

@abelbraaksma, thanks for the pointer, here is what the code looks like:

// elided, see the reproduce zip file attached in later comment

there are about 400 |> dict in my file.

@abelbraaksma
Copy link
Contributor

@smoothdeveloper, is it possible to upload a ZIP file with a sln that contains all those "thousands of lines"? Generally, a bug cannot be considered a bug here until there is a repro. A difference with my issue is, btw, that mine will crash regardless of chosen build, I am curious why yours only crashes on debug build.

@dsyme
Copy link
Contributor

dsyme commented Jan 8, 2016

Closing until a repro is provided per CONTRIBUTING.md

@dsyme dsyme closed this as completed Jan 8, 2016
@smoothdeveloper
Copy link
Contributor Author

@dsyme I just sent you a reproduce project in a mail, I hope this will help the team to investigate the issue.

@smoothdeveloper
Copy link
Contributor Author

Reproduce case for everyone to look
visualfsharp.issue.851.zip

@abelbraaksma
Copy link
Contributor

I can confirm that it indeed fails to compile in Debug build with a StackOverflowException (and that it succeeds with Release build). However, strangely, it does succeed on a second compile. Apparently some intermediate files remain and "fix" a second attempt at building.

The following repro always works:

  • Take the file from @smoothdeveloper post above
  • Select Debug / Any CPU
  • Clean > Build or Rebuild
  • result: StackOverflowException

The part of the build log that is perhaps of interest is:

    Microsoft (R) F# Compiler version 14.0.23020.0
    Copyright (c) Microsoft Corporation. All Rights Reserved.
    Process is terminated due to StackOverflowException.
C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.Targets(155,9): error MSB6006: "fsc.exe" exited with code -1073741571.

Full build log (diagnostics): buildlog#851-diagnostics.txt

@dsyme: I think you can reopen the bug (or the OP can?), it seems a genuine bug to me. Still not sure though whether it has the same cause as #779.

@smoothdeveloper
Copy link
Contributor Author

@abelbraaksma on the second compile, the .dll is there but it is invalid as far as I can tell from looking at it in ILSpy.

Thanks for laying out the more accurate details for reproducing the issue.

@abelbraaksma
Copy link
Contributor

@smoothdeveloper, that's possible (and odd, I wonder what the compiler "thinks" here), I didn't check that deeply and didn't try to load or run the Release or Debug versions.

@smoothdeveloper
Copy link
Contributor Author

@dsyme can we get the bug set to open again?

@dsyme dsyme reopened this Jan 12, 2016
@dsyme dsyme added Bug Area-Compiler Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Jan 15, 2016
@dsyme
Copy link
Contributor

dsyme commented Jul 8, 2016

@abelbraaksma @smoothdeveloper I can't repro this with the ZIP linked here: #851 (comment)

I opened the solution in Visual Studio 2015, compiled it in Debug, and it compiled OK. The generated DLL also passes PEVERIFY

I'll close this as no repro for now - if you have updated repro details please let me know.

@dsyme dsyme closed this as completed Jul 8, 2016
@dsyme dsyme added Resolution-Not Reproducible and removed Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Bug labels Jul 8, 2016
@smoothdeveloper
Copy link
Contributor Author

smoothdeveloper commented Jul 8, 2016

@dsyme I'm still getting same error, I extracted the zip, open the .sln with VS2015 and compiled in DEBUG

image

image

1>------ Build started: Project: visualfsharp.issue.851, Configuration: Debug Any CPU ------
1>  C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\fsc.exe -o:obj\Debug\visualfsharp.issue._851.dll -g --debug:full --noframework --define:DEBUG --define:TRACE --doc:bin\Debug\visualfsharp.issue._851.XML --optimize- --tailcalls- -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\mscorlib.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Numerics.dll" --target:library --warn:3 --warnaserror:76 --vserrors --LCID:1033 --utf8output --fullpaths --flaterrors --subsystemversion:6.00 --highentropyva+ --sqmsessionguid:5364ee24-839a-4bfd-bfd5-f1888a8011ff "C:\Users\gauthier\AppData\Local\Temp\.NETFramework,Version=v4.5.2.AssemblyAttributes.fs" AssemblyInfo.fs Library1.fs 
1>C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.Targets(155,9): error MSB6006: "fsc.exe" exited with code -1073741571.
1>Done building project "visualfsharp.issue.851.fsproj" -- FAILED.
1>
1>Build FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Could it be related to my OS (windows 7 pro 64bit)?

@bjornbaverfjord
Copy link

I can confirm the build failure using Debug/Rebuild on
Windows 10 Pro 64 bit
Visual Studio Community 2015 Update 3

@alfonsogarciacaro
Copy link
Contributor

I'm having the same problem when trying to compile Fable.Core on Windows. It was working on Mono. Also, the problem only happens in Debug config, it works on Release (though I've not checked yet if the assembly is actually valid or not.

Windows 10 64 bit
Visual Studio Community 2015 Update 3
F# Compiler version 14.0.23413.0

Please note Fable.Core.fsproj in the link above cannot be open with VS because of a duplicated folder, I tried rearranging the files but the build problem remained.

@alfonsogarciacaro
Copy link
Contributor

I've been trying to change the compile options one by one to match the Release configuration and at the end setting Optimize to true seemed to fix the build. My current configuration is:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>Full</DebugType>
    <Optimize>true</Optimize>
    <Tailcalls>false</Tailcalls>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants />
    <WarningLevel>3</WarningLevel>
    <PlatformTarget />
    <Prefer32Bit />
    <OtherFlags />
  </PropertyGroup>

If I set Optimize to false, compilation fails.

Hope this helps!

@matthid
Copy link
Contributor

matthid commented Jul 9, 2016

I can reproduce this with Visual Studio 2015 Update 3 as well.
it_crashes

This issue shouldn't be closed

@matthid
Copy link
Contributor

matthid commented Jul 9, 2016

When I attach the debugger I see this:
it_crashes_with_debugger

@dsyme Might a Dump or Minidump file help? I could upload one if it would help.
As it reproduces for quite some people do you have a suggestion what else we can provide to get this accepted? Would remote access to a machine with the issue help?

Call Stack

ntdll.dll!_NtWaitForSingleObject@12�()  Unknown
KernelBase.dll!_WaitForSingleObjectEx@12�() Unknown
ntdll.dll!ExecuteHandler2@20�() Unknown
ntdll.dll!ExecuteHandler@20�()  Unknown
ntdll.dll!_KiUserExceptionDispatcher@8�()   Unknown
diasymreader.dll!PdbEmitter::DefineLocalVar(unsigned short const *,struct SymVariable &)    Unknown
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
diasymreader.dll!SymWriter::EmitScopeTree(unsigned int) Unknown
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
diasymreader.dll!SymWriter::EmitScopeTree(unsigned int) Unknown
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
    ... SNIP ...
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
diasymreader.dll!SymWriter::EmitScopeTree(unsigned int) Unknown
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
diasymreader.dll!SymWriter::EmitScopeTree(unsigned int) Unknown
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
diasymreader.dll!SymWriter::EmitScopeTree(unsigned int) Unknown
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
diasymreader.dll!SymWriter::EmitScopeTree(unsigned int) Unknown
diasymreader.dll!SymWriter::EmitChildren(unsigned int)  Unknown
diasymreader.dll!SymWriter::EmitScopeTree(unsigned int) Unknown
diasymreader.dll!SymWriter::CloseMethod(void)   Unknown
[Managed to Native Transition]  
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.WritePdbInfo@279-6.Invoke(int i, Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.PdbMethodData minfo)   Unknown
FSharp.Core.dll!Microsoft.FSharp.Collections.ArrayModule.IterateIndexed<Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.PdbMethodData>(Microsoft.FSharp.Core.FSharpFunc<int, Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.PdbMethodData, Microsoft.FSharp.Core.Unit>> action, Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.PdbMethodData[] array)    Unknown
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.WritePdbInfo(bool fixupOverlappingSequencePoints, bool showTimes, string f, string fpdb, Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.PdbData info)  Unknown
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.writeBinaryAndReportMappings$cont@4494(bool showTimes, Microsoft.FSharp.Core.FSharpOption<string> pdbfile, string outfile, bool fixupOverlappingSequencePoints, int timestamp, Microsoft.FSharp.Core.FSharpFunc<int, int> textV2P, Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.PdbData pdbData, Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.BinaryChunk debugDirectoryChunk, Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.BinaryChunk debugDataChunk, Microsoft.FSharp.Core.Unit unitVar)    Unknown
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.writeBinaryAndReportMappings(string outfile, Microsoft.FSharp.Compiler.AbstractIL.IL.ILGlobals ilg, Microsoft.FSharp.Core.FSharpOption<string> pdbfile, Microsoft.FSharp.Core.FSharpOption<Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter.ILStrongNameSigner> signer, bool fixupOverlappingSequencePoints, bool emitTailcalls, bool showTimes, bool dumpDebugInfo, Microsoft.FSharp.Compiler.AbstractIL.IL.ILModuleDef modul, bool noDebugData)    Unknown
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.Driver.FileWriter.EmitIL(Microsoft.FSharp.Compiler.CompileOps.TcConfig tcConfig, Microsoft.FSharp.Compiler.AbstractIL.IL.ILGlobals ilGlobals, Microsoft.FSharp.Compiler.ErrorLogger.ErrorLogger _errorLogger, string outfile, Microsoft.FSharp.Core.FSharpOption<string> pdbfile, Microsoft.FSharp.Compiler.AbstractIL.IL.ILModuleDef ilxMainModule, Microsoft.FSharp.Compiler.Driver.SigningInfo signingInfo, Microsoft.FSharp.Compiler.ErrorLogger.Exiter exiter)   Unknown
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.Driver.main4<System.__Canon>(Microsoft.FSharp.Compiler.Driver.Args<System.Tuple<Microsoft.FSharp.Compiler.CompileOps.TcConfig, Microsoft.FSharp.Compiler.ErrorLogger.ErrorLogger, Microsoft.FSharp.Compiler.AbstractIL.IL.ILGlobals, Microsoft.FSharp.Compiler.AbstractIL.IL.ILModuleDef, string, Microsoft.FSharp.Core.FSharpOption<string>, Microsoft.FSharp.Compiler.Driver.SigningInfo, System.Tuple<System.__Canon>>> _arg1) Unknown
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.Driver.typecheckAndCompile(string[] argv, bool bannerAlreadyPrinted, Microsoft.FSharp.Compiler.ErrorLogger.Exiter exiter, Microsoft.FSharp.Compiler.Driver.ErrorLoggerProvider errorLoggerProvider)   Unknown
FSharp.Compiler.dll!Microsoft.FSharp.Compiler.Driver.mainCompile(string[] argv, bool bannerAlreadyPrinted, Microsoft.FSharp.Compiler.ErrorLogger.Exiter exiter) Unknown
fsc.exe!Microsoft.FSharp.Compiler.CommandLineMain.Driver.main(string[] argv)    Unknown
fsc.exe!Microsoft.FSharp.Compiler.CommandLineMain.main(string[] argv)   Unknown
[Native to Managed Transition]  
mscoreei.dll!__CorExeMain@0�()  Unknown
mscoree.dll!__CorExeMain_Exported@0�()  Unknown
kernel32.dll!@BaseThreadInitThunk@12�() Unknown
ntdll.dll!__RtlUserThreadStart()    Unknown
ntdll.dll!__RtlUserThreadStart@8�() Unknown

@dsyme dsyme reopened this Jul 11, 2016
@dsyme
Copy link
Contributor

dsyme commented Jul 11, 2016

@matthid A few different things might have affected this. In any case reopening, we should be able to repro this somehow.

@forki
Copy link
Contributor

forki commented Sep 15, 2016

Also see #1536 and #1537

@haf
Copy link

haf commented Oct 5, 2016

Has this been fixed with 6bbea65? Because I can only compile WinPerfCounters in release mode; or otherwise the compiler crashes.

Repro: download Logary, compile on Windows in Release mode - fine, in Debug mode - compiler crash.

@forki
Copy link
Contributor

forki commented Oct 5, 2016

@KevinRansom proposed a different fix but IIRC it's not yet merged.
Kevin could you please try to compile logary with your fix?

@haf
Copy link

haf commented Oct 5, 2016

Ref causiq/logary#182

Note that in this commit in that pull request, I make WinPerfCounters always compile in release mode. So you'll have to ensure that commit is not present when/if you get around to reproducing this issue (e.g. by checking out an earlier version).

@OmarTawfik
Copy link
Contributor

Assigning to @KevinRansom

@OmarTawfik OmarTawfik assigned KevinRansom and unassigned OmarTawfik Oct 6, 2016
@KevinRansom
Copy link
Member

@haf which build of the f# compiler are you using to build this?

This should be fixed with :
b528c23

@haf
Copy link

haf commented Oct 7, 2016

Let me check on Windows next monday, but it's definitely the default that comes with VS2015 with latest updates.

@KevinRansom
Copy link
Member

I believe this was fixed witht he .pdb fix.

@abelbraaksma
Copy link
Contributor

abelbraaksma commented Aug 27, 2017

Since nobody seems to have confirmed this (I read "I believe" not as a confirmation that it is definitely fixed), I tried the zipped repro with F# 4.0 and F# 4.1, with .NET 4.5.2 and .NET 4.7 in VS2017 RTM and VS2017 latest previews and F# nightlies. Conclusion:

Works like a charm🥇!

@dsyme
Copy link
Contributor

dsyme commented Aug 29, 2017

@abelbraaksma Thanks for checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants