Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I restore indexing functionality? (Xcode)

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?

like image 257
Vatsal Manot Avatar asked Jan 30 '16 15:01

Vatsal Manot


2 Answers

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

like image 55
TechBee Avatar answered Nov 13 '22 03:11

TechBee


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
like image 28
Mikael Avatar answered Nov 13 '22 03:11

Mikael