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

SyntaxRewriter crashes when called from a thread other than main

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: SwiftSyntax
    • Labels:
      None
    • Environment:

      SwiftSyntax 0.50100.0, Xcode 11.1. Made a simple SwiftPM project, used generate-xcodeproj to make a project to open (double-clicking the Package.swift file did not produce a buildable project).

      Description

      I'm trying to create and use a SyntaxRewriter subclass from a thread other than main. I'm not sharing between threads, so it seems like it should be fine. However, I get an EXEC_BAD_ACCESS inside of SwiftSyntax. Here's some sample code that demonstrates the problem, which is adapted from the SwiftSyntax README's sample code:

      let string = """
      
      protocol P {
          var x: Int? { get set }
      }
      
      
      """
      
      let queue = DispatchQueue.global()
      let sourceFile = try! SyntaxParser.parse(source: string)
      let semaphore = DispatchSemaphore(value: 0)
      queue.async {
          _ = Renamer().visit(sourceFile)
          semaphore.signal()
      }
      semaphore.wait()
      print("done")
      

      It crashes with an EXEC_BAD_ACCESS, typically in `SyntaxRewriter.visitChildren()`. Trying to print any variables in the debugger outputs "Trying to put the stack in unreadable memory at <some memory address>".

      I can't reproduce this in an optimized build.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            benpious Ben Pious
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: