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
Large, single-file sources of F# get the line number and debug-stepping totally wrong #758
If your source file is sufficiently large (essentially, over 2^16 or 64k lines long) the line number used when source stepping, or the curlies that you on syntax errors, are reported on totally wrong lines (essentially, current line minus 216).
This may not happen often in practice, but if it happens, it is highly confusing. I suggest to either raise a compile error "source file to large, maximum of 65535 lines reached, consider splitting your source in multiple source files" or to allow a integer instead of a short for the line number counter. I don't think it is a limitation of .NET or Visual Studio, large auto-generated source files in C# do not exhibit this problem.
A practical issue with this is specifically autogenerated files, for instance, we use a Dynamics CRM mapping which generates a single file of 350k lines for the entity mappings using Microsoft tooling. Converting that to F# is currently not an option.
Since the auto-created function names use line numbers to identify them, this has the effect that line numbers on such functions point to the wrong location. I have not tried whether this could confuse the compiler in creating such names.
See how the debugger stops at a blank line, how the selection is wrong, and how the code-coverage tools report non-existing lines as hit:
A by-product of this behavior is that setting a breakpoint with F9 will actually set it on the non-existing line, as if no breakpoint was set on the actual code.
Note, surprisingly, __LINE__ stores the correct line information.
PS: previously, and in some comments, this entry also showed an example that, next to the wrong line numbers being reported, also crashed Visual Studio. I have now moved that into a separate bug entry: #779.
Yes, this is indeed a limitation with the implementation of the ``range` type in range.fs, which stores location information in a limited range of bits. But looking at the above it seems your very large file is generated C# code? Or is it F# code?
changed the title [-]Large, single-file sources of F# get the line number and debug-stepping totally wrong[/-][+]StackOverflowException on large source files, and/or F# getting the line number and debug-stepping totally wrong[/+]on Dec 9, 2015
Hi Don, thanks for your answer. I have added a repro to the original report as while reproing I found a related bug that kinda changes the bug report as a whole. As such I updated the text a bit. (repro is in next comment, the crash is reported separately: #779)
Actually, it was all F#, why did you think it was C#? The screenshot in the OP is from an FSharp project file during debugging.
If this is a limitation of F#, I think at the very least it would be a good thing if the compiler, upon finding too many lines, issues a warning, or an error. And of course, it shouldn't crash Visual Studio and everything in it ;).
This repro shows F# behavior on large files by printing line information from __LINE__, the internal function decoration mechanism and from .NET's StackFrame. It can also be observed that Lint thinks this file module is 12931 lines long, while in fact is is 144004 lines long (but that's probably out of scope for this bug report).
If you run it in Debug or Release mode (code is different for both versions because the F# compiler's optimization inlines differently when optimizations are on), you'll get output that looks something like this:
[... snip...]
Real line 62000, decorated: 62000, stack: 62000 (fu@62000-434)
Real line 63000, decorated: 63000, stack: 63000 (fu@63000-441)
Real line 64000, decorated: 64000, stack: 64000 (fu@64000-448)
Real line 65000, decorated: 65000, stack: 65000 (fu@65000-455)
Real line 66000, decorated: 464, stack: 464 (fu@464-462)
Real line 67000, decorated: 1464, stack: 1464 (fu@1464-469)
Real line 68000, decorated: 2464, stack: 2464 (fu@2464-476)
Real line 69000, decorated: 3464, stack: 3464 (fu@3464-483)
[... snip ...]
As you can see, the line numbering (as Don already confirmed) starts from zero (464) again. Between the parentheses is the decorated name of the current function.
Another observation: the repro in the zip does not allow you to set any breakpoint other than the first few lines. Change the first fu-line from line 1000 to line 771, and selecting a breakpoint works again, everywhere (albeit on the wrong physical offset). There seems to be some relation to the size of the file, but I couldn't quite understand what was happening, because sometimes increased sizes still allowed breakpoints.
changed the title [-]StackOverflowException on large source files, and/or F# getting the line number and debug-stepping totally wrong[/-][+]Large, single-file sources of F# get the line number and debug-stepping totally wrong[/+]on Dec 9, 2015
Activity
dsyme commentedon Dec 5, 2015
Yes, this is indeed a limitation with the implementation of the ``range` type in range.fs, which stores location information in a limited range of bits. But looking at the above it seems your very large file is generated C# code? Or is it F# code?
[-]Large, single-file sources of F# get the line number and debug-stepping totally wrong[/-][+]StackOverflowException on large source files, and/or F# getting the line number and debug-stepping totally wrong[/+]abelbraaksma commentedon Dec 9, 2015
Hi Don, thanks for your answer.
I have added a repro to the original report as while reproing I found a related bug that kinda changes the bug report as a whole. As such I updated the text a bit.(repro is in next comment, the crash is reported separately: #779)Actually, it was all F#, why did you think it was C#? The screenshot in the OP is from an FSharp project file during debugging.
If this is a limitation of F#, I think at the very least it would be a good thing if the compiler, upon finding too many lines, issues a warning, or an error. And of course, it shouldn't crash Visual Studio and everything in it ;).
abelbraaksma commentedon Dec 9, 2015
FSharpBug758-repro1.zip
This repro shows F# behavior on large files by printing line information from
__LINE__, the internal function decoration mechanism and from .NET'sStackFrame. It can also be observed that Lint thinks this file module is 12931 lines long, while in fact is is 144004 lines long (but that's probably out of scope for this bug report).If you run it in Debug or Release mode (code is different for both versions because the F# compiler's optimization inlines differently when optimizations are on), you'll get output that looks something like this:
As you can see, the line numbering (as Don already confirmed) starts from zero (464) again. Between the parentheses is the decorated name of the current function.
Another observation: the repro in the zip does not allow you to set any breakpoint other than the first few lines. Change the first
fu-line from line 1000 to line 771, and selecting a breakpoint works again, everywhere (albeit on the wrong physical offset). There seems to be some relation to the size of the file, but I couldn't quite understand what was happening, because sometimes increased sizes still allowed breakpoints.[-]StackOverflowException on large source files, and/or F# getting the line number and debug-stepping totally wrong[/-][+]Large, single-file sources of F# get the line number and debug-stepping totally wrong[/+]cartermp commentedon Oct 25, 2018
Fixed in #4476
abelbraaksma commentedon Oct 29, 2018
Fantastic! Thanks!