13
votes

After upgrading to Xcode 8 and converting all my code to Swift 3, I have troubles compiling swift resources. It takes a very long time, and my computer gets super laggy and after about 30 minutes I get this

CompileSwift normal arm64 /Users/choojayson/Dropbox/BottomsUp/Thirst/UserDrank.swift cd /Users/choojayson/Dropbox/BottomsUp /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/choojayson/Dropbox/BottomsUp/Thirst/PendingVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/NotificationCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/ProfileCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/NotificationsVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/UserPendingAction.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/ChooseDrinkVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/AppDelegate.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/UserCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/FirebaseReferences.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/ProfileStatsCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/UserDrankTime.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/MyProfileVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/ProfileStatsFooterCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/WeeklyDrank.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/DrinkList.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/DrinkCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/User.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/HeaderCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/EndorseVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/GlobalScore.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/Username.swift /Users/choojayson/Dropbox/BottomsUp/HomeVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/LoginVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/LeaderBoardVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/CollectionViewHeaderCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/Global.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/CircularTransition.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/Drink.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/WeeklyBestVC.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/DrinkStatus.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/LeaderBoardCell.swift /Users/choojayson/Dropbox/BottomsUp/Thirst/PendingCell.swift -primary-file /Users/choojayson/Dropbox/BottomsUp/Thirst/UserDrank.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk -I /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Products/Debug-iphoneos -F /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Products/Debug-iphoneos -F /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Products/Debug-iphoneos/SDWebImage -F /Users/choojayson/Dropbox/BottomsUp/Pods/FirebaseAnalytics/Frameworks/frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/FirebaseAuth/Frameworks/frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/FirebaseDatabase/Frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/FirebaseInstanceID/Frameworks/frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/FirebaseMessaging/Frameworks/frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/FirebaseStorage/Frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/GoogleIPhoneUtilities/Frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/GoogleInterchangeUtilities/Frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/GoogleNetworkingUtilities/Frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/GoogleParsingUtilities/Frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/GoogleSymbolUtilities/Frameworks -F /Users/choojayson/Dropbox/BottomsUp/Pods/GoogleUtilities/Frameworks -F /Users/choojayson/Dropbox/BottomsUp -enable-testing -g -module-cache-path /Users/choojayson/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Thirst-generated-files.hmap -Xcc -I/Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Thirst-own-target-headers.hmap -Xcc -I/Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Thirst-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Thirst-project-headers.hmap -Xcc -I/Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Products/Debug-iphoneos/include -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Firebase/Analytics/Sources -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/Firebase -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/FirebaseAnalytics -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/FirebaseAuth -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/FirebaseDatabase -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/FirebaseInstanceID -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/FirebaseMessaging -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/FirebaseStorage -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/GoogleIPhoneUtilities -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/GoogleInterchangeUtilities -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/GoogleNetworkingUtilities -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/GoogleParsingUtilities -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/GoogleSymbolUtilities -Xcc -I/Users/choojayson/Dropbox/BottomsUp/Pods/Headers/Public/GoogleUtilities -Xcc -I/Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/DerivedSources/arm64 -Xcc -I/Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -DCOCOAPODS=1 -Xcc -working-directory/Users/choojayson/Dropbox/BottomsUp -emit-module-doc-path /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Objects-normal/arm64/UserDrank~partial.swiftdoc -Onone -module-name Thirst -emit-module-path /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Objects-normal/arm64/UserDrank~partial.swiftmodule -serialize-diagnostics-path /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Objects-normal/arm64/UserDrank.dia -emit-dependencies-path /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Objects-normal/arm64/UserDrank.d -emit-reference-dependencies-path /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Objects-normal/arm64/UserDrank.swiftdeps -o /Users/choojayson/Library/Developer/Xcode/DerivedData/Thirst-fbgpdykwgpyxllfixfnpenbijinz/Build/Intermediates/Thirst.build/Debug-iphoneos/Thirst.build/Objects-normal/arm64/UserDrank.o -embed-bitcode-marker

5
I'm having the exact same problem.Lastmboy

5 Answers

13
votes

Believe it or not, this is the piece of code that was causing the problem for me. With it in, the compile takes about 30 minutes. If I simply comment out that chunk of code, it compiles in less than 30 seconds.

let params : [String: Any] = [
    "person_id"       : kPersonId,
    "person_promo_id" : promo.personPromoId!,
    "promo_page_id"   : promo.promoPageId!,
    "seq_no"          : promo.seqNo!,
    "promo_type"      : promo.promoType!,
    "page_name"       : promo.pageName!,
    "image_name"      : promo.imageName!,
    "start_date"      : promo.startDate!,
    "end_date"        : promo.endDate!,
    "website"         : promo.website!,
    "facility_name"   : promo.facilityName!,
    "address"         : promo.street!,
    "city"            : promo.city!,
    "prov_state_cd"   : promo.provState!,
    "country_cd"      : promo.country!,
    "contact_name"    : promo.contactName!,
    "contact_phone"   : promo.contactPhone!,
    "latitude"        : promo.latitude!,
    "longitude"       : promo.longitude!,
    "bgColorRed"      : promo.bgColorRed!,
    "bgColorGreen"    : promo.bgColorGreen!,
    "bgColorBlue"     : promo.bgColorBlue!,
    "promoCategories" : promoCat
]

Based on this and other things I have read, I would hunt for a case where you're assigning values to a large or nested dictionary with an Any or AnyObject in the definition. I'm guessing that it's the Any that is sending the compiler off on a wild good chase.

If you check your log where it fails, it should have the error right at the object that failed. This should give you a clue as to what file to look in.

Edit: @Jay Chow, this is how I solved the compiler problem with the code above:

var params : [String : Any] = [:]
params["person_id"]         = kPersonId
params["person_promo_id"]   = promo.personPromoId
params["promo_page_id"]     = promo.promoPageId
params["seq_no"]            = promo.seqNo
params["promo_type"]        = promo.promoType
params["page_name"]         = promo.pageName
params["image_name"]        = promo.imageName
params["start_date"]        = promo.startDate
params["end_date"]          = promo.endDate
params["website"]           = promo.website
params["facility_name"]     = promo.facilityName
params["address"]           = promo.street
params["city"]              = promo.city
params["prov_state_cd"]     = promo.provState
params["country_cd"]        = promo.country
params["contact_name"]      = promo.contactName
params["contact_phone"]     = promo.contactPhone
params["latitude"]          = promo.latitude
params["longitude"]         = promo.longitude
params["bgColorRed"]        = promo.bgColorRed
params["bgColorGreen"]      = promo.bgColorGreen
params["bgColorBlue"]       = promo.bgColorBlue
params["promoCategories"]   = promoCat
0
votes

In my case, when I found that issue the chunk of code was:

         return realm2.objects(Alert.self).sorted(by: { (alert1, alert2) -> Bool in
     return  alert1.hour < alert2.hour &&
     alert1.minute < alert2.minute &&
     alert1.label < alert2.label
     })
0
votes

My case had to do with appending too many programmatically created constraints to a view controller's view. I had multiple arrays of constraints defined at the class level as follows:

lazy var labelConstraints: [NSLayoutConstraint] = [...]

I was using this notation for all UI elements in my view. By the time I was done building the view, I had roughly 10 arrays of 3-5 NSLayoutConstraints.

I was then appending a concatenated array to the view's constraint array like so:

self.view.addConstraints(labelConstraints + buttonConstraints + viewConstraints, ...)

This line turned out to be the problem. It must be something with lazy initialization and inline array concat. Whatever the cause, I have fixed this using flatMap as follows.

let constraints = [labelConstraints, buttonConstraints, viewConstraints].flatMap{ $0 }
self.view.addConstraints(constraints)
0
votes

In my case, I was writing a class that implemented Equatable and also had generic members. My issue was rooted in comparing the generic members with ==, when the generic class didn't have a == operator implemented.

For example (using Variable from RxSwift):

class Foo: Equatable {

  var fieldOne: Variable<String> = Variable("fieldOne")
  var fieldTwo: Variable<String?> = Variable(nil)

  public static func ==(lhs: Foo, rhs: Foo) -> Bool {
    //should be marked as a compiler error, since Variable doesn't have == 
    return lhs.fieldOne == rhs.fieldOne && lhs.fieldTwo == rhs.fieldTwo 
  }

}

I should have seen a compiler error for this since no definition of == exists for Variable, but the compiler would crash (as well as the static analysis) before being able to show it. I was seeing memory usage of 60GB+ before the crash. Yikes.

It seems swift still has some lingering bugs when it comes to generics.

0
votes

In my case, Xcode 9, Swift 4, the compilator couldn't stand addition of 8 numbers:

let aBitPattern: UInt64 = ((UInt64(a) & UInt64(0xff)) << 0) +
        ((UInt64(b) & UInt64(0xff)) << 8) +
        ((UInt64(c) & UInt64(0xff)) << 16) +
        ((UInt64(d) & UInt64(0xff)) << 24) +
        ((UInt64(e) & UInt64(0xff)) << 32) +
        ((UInt64(f) & UInt64(0xff)) << 40) +
        ((UInt64(g) & UInt64(0xff)) << 48) +
        ((UInt64(h) & UInt64(0xff)) << 56)

Transforming to this solved the infinite compilation:

var aBitPattern: UInt64 = ((UInt64(a) & UInt64(0xff)) << 0);
    aBitPattern += ((UInt64(b) & UInt64(0xff)) << 8);
    aBitPattern += ((UInt64(c) & UInt64(0xff)) << 16);
    aBitPattern += ((UInt64(d) & UInt64(0xff)) << 24);
    aBitPattern += ((UInt64(e) & UInt64(0xff)) << 32);
    aBitPattern += ((UInt64(f) & UInt64(0xff)) << 40);
    aBitPattern += ((UInt64(g) & UInt64(0xff)) << 48);
    aBitPattern += ((UInt64(h) & UInt64(0xff)) << 56);

Yeah, and sometimes the semicolons help the compilator to understand your code as well.

I always look forward to the new Swift compilator and it always is a huge disappointment from Apple.