TL;DR

I found a bug in Swift compiler with nested enums and protocol conformance. Scroll down to Edit 3.

Original post:

I'm really frustrated... Xcode 10 just broke the other day. Not sure what triggered it. I was running 10.14.0 and Xcode 10.0 and that was working until yesterday. Then suddenly the cooler fan on my Macbook Pro (2016, fully maxed) started going crazy, never stopping and I saw extreme CPU load in Activity Monitor.

I tried restarting Xcode and the computer did not help. So I figured it would not hurt to install Mojave 10.14.1. That did not help. Then I downloaded Xcode 10.1, did not help.

I have tried deleting derived data, restarting Xcode, restaring the Macbook many times, nothing helps. My Xcode project (it's (open source and pretty small)[https://github.com/OpenZesame/Zupreme]) that is using Carthage. It gets stuck on building, task 221 of 256.

enter image description here

In Activity Monitor I see lots of processes with the name swift, which I have no recollection of seeing before.

enter image description here

Did anyone else experience these problems? I understand that I'm not really giving you anything to go on here, since I'm almost certain that the randomly started appearing on Mojave 10.14.0 and Xcode 10.0, which has been working for quite some time...

Right now I'm downloading the Xcode_10.1.xip file from developer portal to perform a clean install. I'm also trying to remove all projects built with carthage from the Carthage/Build/ folder and building them again. I will report back the results in a bit.

Edit 1:

To give more details, I found out that it is the Compile Sources build phase that never finishes.

Also, removing and rebuilding my Carthage dependencies did not help. Still waiting for my Mac to unpack Xcode_10.1.xip downloaded from dev portal. Will report back when I have tried that clean install.

Edit 2:

I was on a work in progress feature branch when I had all this issue. All my changes was compiling during my development. I did not get any compilation errors. Now I tried switching back to my develop branch, and voila it just works again. So the swift compiler never finished with either success or fail. I opened a PR containing the changes that I've done in my code base and will search through them to see what is causing the swift compiler to fail to finish. The PR is public and can be found here if anyone is interested

Edit 3:

I found the bug, it is indeed a bug with the swift compiler as suggested in comments. So this was a red herring, it did not have anything to do with Xcode 10 specifically, I was able to reproduce the same bug in Xcode 9.4.1.

The few lines of code below causes the swift compiler to never finish, not even with a compilation error:

protocol EmptyProtocol {}
class AbstractFoobar<Foo> {}
// This kills the swift compiler
final class SomeFoobar: AbstractFoobar<SomeFoobar.Foo> {
    enum Foo: EmptyProtocol {}
}

For now, I solved it by moving the conformance to EmptyProtocol into an extension, which solves the bug!

// But this works, moving the protocol conformance out to an extension
final class SomeFoobar2: AbstractFoobar<SomeFoobar2.Foo> {
    enum Foo {}
}
extension SomeFoobar2.Foo: EmptyProtocol {}

Track the status of the bug here: https://bugs.swift.org/browse/SR-9160

0

There are 0 answers