Uploaded image for project: 'Swift'
  1. Swift
  2. SR-12360

SwiftFormat uses a SwiftSyntax tag that can cause stack overflow in debug mode

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: swift-format
    • Labels:
      None

      Description

      Stack overflow 2: revenge of the rdar://55929175

      After implementing formatting in sourcekit-lsp I was investigating why it wasn't working for things that are nested four levels deep. After fighting with debugger, I had a hunch that it may be stack overflow. I found a comment in the function that was crashing:

          // The implementation of every generated case goes into its own function. This
          // circumvents an issue where the compiler allocates stack space for every
          // case statement next to each other in debug builds, causing it to allocate
          // ~50KB per call to this function. rdar://55929175
      

      It crashes only in debug mode, on macos

      To reproduce:

      • clone https://github.com/Trzyipolkostkicukru/sourcekit-lsp/tree/format and checkout commit ed642036f4b9ce7696ad340523ed8e9b4bdb9761
      • get toolchain swift-DEVELOPMENT-SNAPSHOT-2020-01-29-a and set it as your compiler
      • compile and set up sourcekit-lsp
      • try to format a file with 4+ levels of nesting, for example:
        do {
        do { do { do { print("Hello, world") } } } 
        }
        

        Attachments

          Activity

            People

            Assignee:
            allevato Tony Allevato
            Reporter:
            cukier cukr
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: