10

One of my projects (containing over 200 files in pure Swift) has just recently started interfering with the indexing process. The indexing process freezes midway and then stops abruptly, causing SourceKitService to crash.

I simply cannot find the faulty code; because there appears to be none!

My code compiles just fine (without a single warning!) - and yet it fails to be indexed. Initially, I thought it to be an Xcode 7.2 issue and so upgraded to the latest beta (7.3); however the issue still persists. I cannot revert back to my old code because too much work will be undone, and I can't spot a particular file to blame. The crash report is here.

To clarify, Xcode itself does not crash, only the indexing process (and SourceKitService as a consequence).

Any ideas on how to go about fixing this?

Vatsal Manot
  • 17,695
  • 9
  • 44
  • 80
  • I suppose you did, but just in case you didn't: "clean project + clean derived data" might help. – Eric Aya Jan 30 '16 at 16:47
  • @EricD.: I've tried that already. – Vatsal Manot Jan 30 '16 at 16:47
  • There's always the hammer: deleting `~/Library/Caches/com.apple.dt.Xcode/` *usually* solves this kind of problem, but it also resets some prefs and DBs so it could have cumbersome side-effects, beware (make a TimeMachine copy first or something). – Eric Aya Jan 30 '16 at 16:55
  • @EricD.: Been there, done that. – Vatsal Manot Jan 30 '16 at 16:57
  • Go through the history of your project and find the commit which caused this issue. – Silmaril Feb 02 '16 at 21:23
  • @Silmaril: My project isn't under source control. – Vatsal Manot Feb 02 '16 at 21:26
  • @VatsalManot How big the size of your project, if you have some files are very huge and can be recognized by Xcode for indexing, it might cause a scenario like you said. – Allen Feb 03 '16 at 07:33
  • @Allen: Largest file is 36kb, but it's just some boilerplate code, nothing complex enough to mess up SourceKitService. – Vatsal Manot Feb 03 '16 at 07:34
  • @VatsalManot Did you try to removing module cache? rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache – Allen Feb 03 '16 at 07:42
  • @Allen: Yes, I did. It didn't help. – Vatsal Manot Feb 03 '16 at 07:45
  • @VastsalManot Hmm~ It's really interesting. Maybe try to find another Mac to open the project. If the issue is just gone, at least we can know the error is generated from system but not the project itself. – Allen Feb 03 '16 at 08:25
  • @Allen: Not a problem with my Mac. I have a few other (unrelated) projects that work fine. But all the projects dependent on this one seem to crash. – Vatsal Manot Feb 03 '16 at 08:27
  • @Allen: I also have a clean install of the latest Xcode (straight from the App Store), and the latest beta as well. – Vatsal Manot Feb 03 '16 at 08:27
  • @Allen: It's not a problem with my code, because my project compiles just fine. It's probably a bug in SourceKit, however I can't seem to find what's causing it. – Vatsal Manot Feb 03 '16 at 08:29

2 Answers2

5

Remove "xcuserdata" from .xcodeproj (right click on .xcodeproj > select Show Package Contents. This should solve the problem.

TechBee
  • 1,897
  • 4
  • 22
  • 46
1

If I'm reading properly, the problem comes from this part of the process:

Thread 8 Crashed:
0   com.apple.SourceKitService      0x000000010450d9fc swift::TypeBase::getDesugaredType() + 12
1   com.apple.SourceKitService      0x00000001043bccbe (anonymous namespace)::DeclChecker::checkDynamicSelfReturn(swift::FuncDecl*, swift::TypeRepr*, unsigned int) + 478
2   com.apple.SourceKitService      0x00000001043b7c08 (anonymous namespace)::DeclChecker::visitFuncDecl(swift::FuncDecl*) + 1432
3   com.apple.SourceKitService      0x00000001043acc0d (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 2733
4   com.apple.SourceKitService      0x00000001043a7ea7 swift::TypeChecker::validateDecl(swift::ValueDecl*, bool) + 727
5   com.apple.SourceKitService      0x00000001043b6426 (anonymous namespace)::DeclChecker::visitSubscriptDecl(swift::SubscriptDecl*) + 1478
6   com.apple.SourceKitService      0x00000001043acbdd (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 2685
7   com.apple.SourceKitService      0x00000001043a7ea7 swift::TypeChecker::validateDecl(swift::ValueDecl*, bool) + 727
8   com.apple.SourceKitService      0x00000001044fc003 swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, unsigned int, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 3075
9   com.apple.SourceKitService      0x00000001043c7a7c swift::TypeChecker::lookupMember(swift::DeclContext*, swift::Type, swift::DeclName, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 556
10  com.apple.SourceKitService      0x00000001043d51b7 (anonymous namespace)::ConformanceChecker::lookupValueWitnesses(swift::ValueDecl*, bool*) + 359
11  com.apple.SourceKitService      0x00000001043d11a1 (anonymous namespace)::ConformanceChecker::resolveWitnessViaLookup(swift::ValueDecl*) + 401
12  com.apple.SourceKitService      0x00000001043ce86f swift::TypeChecker::checkConformance(swift::NormalProtocolConformance*) + 2255
13  com.apple.SourceKitService      0x000000010438011b typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) + 1099
14  com.apple.SourceKitService      0x00000001043809e5 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int) + 1781
15  com.apple.SourceKitService      0x0000000103fa40c2 swift::CompilerInstance::performSema() + 4738
16  com.apple.SourceKitService      0x0000000103e9a836 SourceKit::SwiftLangSupport::indexSource(llvm::StringRef, SourceKit::IndexingConsumer&, llvm::ArrayRef<char const*>, llvm::StringRef) + 4262
17  com.apple.SourceKitService      0x0000000103eb086a void SourceKit::WorkQueue::DispatchData::callAndDelete<handleRequestImpl(void*, std::__1::function<void (void*)>)::$_2>(void*) + 2170
18  libdispatch.dylib               0x00007fff9b7de33f _dispatch_client_callout + 8
19  libdispatch.dylib               0x00007fff9b7ec03a _dispatch_block_invoke + 474
20  com.apple.SourceKitService      0x00000001056afbbf executeBlock(void*) + 15
21  com.apple.SourceKitService      0x0000000103f3e58d ExecuteOnThread_Dispatch(void*) + 13
22  libsystem_pthread.dylib         0x00007fff8be14c13 _pthread_body + 131
23  libsystem_pthread.dylib         0x00007fff8be14b90 _pthread_start + 168
24  libsystem_pthread.dylib         0x00007fff8be12375 thread_start + 13

which leads us to :

https://github.com/apple/swift/pull/932/files

20days + ago

So I guess it's a known issue. However I don't know what is causing it. I'm pretty sure it's a swift code style that is not well supported yet.

I also found your crash in this Crash test project:

https://github.com/practicalswift/swift-compiler-crashes

If you look into it, you might find the precise case that triggers one of those crashes:

  • ✓ 28197 swift typebase getdesugaredtype
  • ✓ 28200 swift typebase getdesugaredtype
  • ✓ 28203 swift typebase getdesugaredtype
Mikael
  • 2,355
  • 1
  • 21
  • 45