Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle sourcekitd error #169

Merged
merged 7 commits into from Feb 9, 2016
Merged

Conversation

norio-nomura
Copy link
Collaborator

#166

Notes:

  • Use sourcekitd_set_notification_handler().
    sourcekitd_set_notification_handler() set the handler to be executed on main thread queue.
    So, we vacate main thread to dispatch_main(). Without that, SourceKittenFramework waits 10 seconds for SourceKitService restored.
  • Add Request.sendMayThrow() that may throws Request.Error.
    good naming? or change send() to throwing error?
  • for crashing test, we can use following from apple/swift
validation-test/compiler_crashers_fixed/04592-swift-constraints-constraintsystem-simplifyconstraint.swift
validation-test/compiler_crashers_fixed/24947-swift-lexer-leximpl.swift
validation-test/compiler_crashers_fixed/26018-swift-parser-skipsingle.swift
validation-test/compiler_crashers_fixed/26830-swift-printingdiagnosticconsumer-handlediagnostic.swift
validation-test/compiler_crashers_fixed/27433-std-function-func-swift-parser-parsenominaldeclmembers.swift
validation-test/compiler_crashers_fixed/27757-swift-parser-parsebraceitems.swift
validation-test/compiler_crashers_fixed/27947-swift-parser-parsebraceitems.swift

Those files can crash sourcekitd in Xcode 7.2.1, but not newer version of sourcekitd.

@@ -91,6 +91,10 @@ private func fromSourceKit(sourcekitObject: sourcekitd_variant_t) -> SourceKitRe
/// dispatch_once_t token used to only initialize SourceKit once per session.
private var sourceKitInitializationToken: dispatch_once_t = 0

/// dispatch_semaphore_t used to waiting sourcekitd restored.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dispatch_semaphore_t used when waiting for sourcekitd to be restored.

@jpsim
Copy link
Owner

jpsim commented Feb 9, 2016

This is probably necessary, although error handling inevitably muddies up the code 😢

@jpsim
Copy link
Owner

jpsim commented Feb 9, 2016

This is great work @norio-nomura! I wasn't able to figure this out the last few times I tried, so kudos! 👏

`sourcekitd_set_notification_handler()` set the handler to be executed on main thread queue.
So, we vacate main thread to `dispatch_main()`.
Change `SwiftDocs.init(file:arguments:)` to failable.
@norio-nomura norio-nomura changed the title [WIP] handle sourcekitd error handle sourcekitd error Feb 9, 2016
@norio-nomura
Copy link
Collaborator Author

Updated.
sample log on handling SourceKitService crashes:

sourceKitten doc
Running xcodebuild
Parsing 142-success2.swift (1/5)
sourcekit: [1:connection-event-handler:9475: 0.0000] Connection interrupt
sourcekit: [1:pingService:9475: 0.0010] pinging service
sourcekit: [1:ping-event-handler:6659: 0.0111] service restored
sourcekitten: connection to SourceKitService restored!
sourcekit: [1:connection-event-handler:9475: 0.0852] Connection interrupt
sourcekit: [1:updateSemanticEditorDelay:9475: 0.0853] disabling semantic editor for 1 seconds
sourcekit: [1:pingService:9475: 0.0854] pinging service
sourcekitten: connection to SourceKitService restored!
Parsing 27947-swift-parser-parsebraceitems.swift (2/5)
sourcekit: [1:sourcekitd_send_request_sync:3331: 0.0859] request dropped while restoring service
sourcekit: [1:ping-event-handler:10095: 0.0968] service restored
sourcekitten: connection to SourceKitService restored!
restoring serviceParsing 142-nodoc.swift (3/5)
Parsing 142-fail.swift (4/5)
Parsing 142-success1.swift (5/5)
[{
  "\/Users\/norio\/Documents\/workspace\/github\/SwiftLint\/Carthage\/Checkouts\/SourceKitten\/SourceKitten142\/SourceKitten142\/142-success2.swift" : {
    "key.substructure" : [
      {

@@ -6,7 +6,9 @@

##### Enhancements

* None.
* Add `Request.failableSend()` that can handle SourceKitService crashes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a breaking change in this PR: SwiftDocs(file:arguments:) now throws.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes.
I changed it to failable SwiftDocs.init?(file:arguments:).

Change `SwiftDocs.init(file:arguments:)` to `SwiftDocs.init?(file:arguments:)`
@jpsim
Copy link
Owner

jpsim commented Feb 9, 2016

Great, thanks again for this @norio-nomura!

jpsim added a commit that referenced this pull request Feb 9, 2016
@jpsim jpsim merged commit 561fed0 into jpsim:master Feb 9, 2016
@norio-nomura
Copy link
Collaborator Author

Thanks for reviews! 🙏 😄

@norio-nomura norio-nomura deleted the nn-handle-sourcekitd-error branch February 9, 2016 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants