Skip to content

Large, single-file sources of F# get the line number and debug-stepping totally wrong #758

Closed

Description

@abelbraaksma

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.

This was also reported on StackOverflow with a screenshot.

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:

b4afq

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.

Activity

  1. dsyme commented on Dec 5, 2015

    @dsyme
    Contributor

    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?

  2. 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
  3. abelbraaksma commented on Dec 9, 2015

    @abelbraaksma
    ContributorAuthor

    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 ;).

  4. abelbraaksma commented on Dec 9, 2015

    @abelbraaksma
    ContributorAuthor

    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'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).

    fsharp-bug-758-1

    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.

  5. 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
  6. added
    Impact-Low
    on Jan 8, 2016
  7. added this to the Unknown milestone on Aug 25, 2018
  8. modified the milestones: Unknown, 16.0 on Sep 20, 2018
  9. cartermp commented on Oct 25, 2018

    @cartermp
    Contributor

    Fixed in #4476

  10. abelbraaksma commented on Oct 29, 2018

    @abelbraaksma
    ContributorAuthor

    Fantastic! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-Low

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions