Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode hangs on "Compiling Swift source files"

I'm running Xcode 7.3.1. When building my Swift based project, it hangs on "Compiling Swift source files". I've tried various combination of deleting DerivedData, clean, run, restarting Xcode, restarting OS X, none seem to work. Any ideas?

like image 907
Steve Kuo Avatar asked Jul 03 '16 21:07

Steve Kuo


3 Answers

I made a class extend itself. That also causes Swift compiler to get stuck in a loop without error:

class X: X
like image 173
Hai Avatar answered Oct 22 '22 09:10

Hai


Thanks for all commentors' suggestions. I narrowed it down to a map's closure referencing a property that I had removed. Example:

var people: [Person] = ...
let foo = people.map { "\($0.name), \($0.age)" }

where Person looks something like:

protocol Person {
    var name: String { get }
    var age: Int { get }
}

This all works fine. Then I removed age while keeping the closure unchanged. This caused Xcode to become hopelessly confused. Probably related to the Swift's type inference.

like image 8
Steve Kuo Avatar answered Oct 22 '22 09:10

Steve Kuo


Something I found useful was the post from RoystonP on https://developer.apple.com/forums/thread/115303?answerId=391817022#391817022:

  1. Open Activity Monitor.
  2. Start your project building.
  3. Wait for the the build’s progress to completely stop for several minutes.
  4. Locate the Swift processes in Activity Monitor (they should be using nearly 100% CPU) and select one of them.
  5. In the menu bar, select “View”, then “Send Signal To Process…”
  6. Select “Abort (SIGABRT)” from the drop-down list.
  7. Click the “Send” button. This will simulate an assertion failing, so the compiler will print information about what it’s doing and then exit.
  8. In Xcode, switch to the Report Navigator (the “speech bubble” button over the left-side pane) and select the build.
  9. Scroll down to the now-failed compilation step and click the transcript button (button with five lines, to the right of the “Compile [Filename]” line).
  10. Scroll down to see the diagnostic information. It will probably include a list of command-line flags, a few lines saying things like “In pass SimplifyCFG”, and a stack trace.

You might have to repeat step 6 and 7 in order to get it to work.

like image 8
basvk Avatar answered Oct 22 '22 09:10

basvk