swiftlang / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages
Apache License 2.0
3.2k stars 264 forks source link

SourceKit-LSP crashes when selecting non-Xcode toolchain on macOS #1521

Open twof opened 6 days ago

twof commented 6 days ago

Swift version

swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a

Platform

macOS 15.0 beta

Editor

VS Code

Does the issue reproduce with Swift 6?

Yes

Description

I get an error

EverythingButTheBagelCore/Package.swift: {"code":null,"killed":false,"signal":"SIGSEGV","cmd":"/Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a.xctoolchain/usr/bin/swift package describe --type json"}

EverythingButTheBagelCore is the name of the package.

Steps to Reproduce

Install noted toolchain, switch to it in VS Code selecting workspace

Logging

% sourcekit-lsp diagnose
sourcekit-lsp diagnose collects information that helps the developers of sourcekit-lsp diagnose and fix issues.
This information contains:
- Crash logs from SourceKit
- Log messages emitted by SourceKit
- Versions of Swift installed on your system
- If possible, a minimized project that caused SourceKit to crash
- If possible, a minimized project that caused the Swift compiler to crash

All information is collected locally.

                                          Diagnosing sourcekit-lsp issues
 0% [-------------------------------------------------------------------------------------------------]
Collecting log messageszsh: segmentation fault  sourcekit-lsp diagnose

It does not appear that anything was generated. Where should it be?

twof commented 6 days ago

Additional output from SourceKit LSP

[Info  - 5:12:33 PM] Connection to server got closed. Server will restart.
true
[Error - 5:12:33 PM] Server process exited with signal SIGSEGV.
[Info  - 5:12:34 PM] Connection to server got closed. Server will restart.
true
[Error - 5:12:34 PM] Server process exited with signal SIGSEGV.
[Info  - 5:12:34 PM] Connection to server got closed. Server will restart.
true
[Error - 5:12:34 PM] Server process exited with signal SIGSEGV.
[Info  - 5:12:35 PM] Connection to server got closed. Server will restart.
true
[Error - 5:12:35 PM] Server process exited with signal SIGSEGV.
[Info  - 5:12:36 PM] Connection to server got closed. Server will restart.
true
[Error - 5:12:36 PM] Server process exited with signal SIGSEGV.
[Error - 5:12:36 PM] Server process exited with signal SIGSEGV.
[Error - 5:12:37 PM] Request textDocument/documentSymbol failed.
Error: Connection is disposed.
    at Lt (/Users/fnord/.vscode/extensions/sswg.swift-lang-1.10.3/dist/extension.js:47:482)
    at Object.sendRequest (/Users/fnord/.vscode/extensions/sswg.swift-lang-1.10.3/dist/extension.js:47:2538)
    at _m.sendRequest (/Users/fnord/.vscode/extensions/sswg.swift-lang-1.10.3/dist/extension.js:55:113948)
    at async u (/Users/fnord/.vscode/extensions/sswg.swift-lang-1.10.3/dist/extension.js:55:55671)
    at async Object.provideDocumentSymbols (/Users/fnord/.vscode/extensions/sswg.swift-lang-1.10.3/dist/extension.js:106:8465)
    at async h.provideDocumentSymbols (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:153:98122)
[Error - 5:13:02 PM] Connection to server got closed. Server will not be restarted.
ahoppen commented 6 days ago

Synced to Apple’s issue tracker as rdar://130547854

twof commented 6 days ago

Let me know if I should move this to the VS Code extension repo.

ahoppen commented 4 days ago

This is an issue in SourceKit-LSP (or the Swift toolchains in general), so SourceKit-LSP is the correct repo.

This started crashing sometime between swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-13-a and swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-18-a.

Finishes fine:

/Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-13-a.xctoolchain/usr/bin/sourcekit-lsp diagnose --components logs

Crashes:

/Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-18-a.xctoolchain/usr/bin/sourcekit-lsp diagnose --components logs

There were no changes to SourceKit-LSP between these two tags. Both are referring to 7ad1dcf2675abdc2c0a2dec6bbb95ea388f269f5.

The crash is in withCheckedThrowingContinuation. It seems like there was some change in Swift Concurrency that’s causing the crash. I’m checking with them to see if they have an idea.

Thread 1 Crashed:
0   sourcekit-lsp                          0x10078d49c specialized withCheckedThrowingContinuation<A>(isolation:function:_:) + 108
1   sourcekit-lsp                          0x10078c63d Process.waitUntilExit() + 1
2   sourcekit-lsp                          0x1013d4eb5 DiagnoseCommand.addOsLog(toBundle:) + 1
3   sourcekit-lsp                          0x1013d929d closure #2 in DiagnoseCommand.run() + 1
4   sourcekit-lsp                          0x1013dcaa1 partial apply for closure #2 in DiagnoseCommand.run() + 1
5   sourcekit-lsp                          0x1013dc825 specialized DiagnoseCommand.orPrintError(_:) + 1
6   sourcekit-lsp                          0x1013d741d DiagnoseCommand.run() + 1
7   sourcekit-lsp                          0x1013d9a91 protocol witness for AsyncParsableCommand.run() in conformance DiagnoseCommand + 1
8   sourcekit-lsp                          0x10013e371 static AsyncParsableCommand.main() + 1
9   sourcekit-lsp                          0x10011cb61 specialized thunk for @escaping @convention(thin) @async () -> () + 1
10  libswift_Concurrency.dylib             0x25cef3949 completeTaskAndRelease(swift::AsyncContext*, swift::SwiftError*) + 1
adam-fowler commented 4 days ago

As an aside swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-13-a crashed for me while swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a appears to be working. I do not have the macOS or Xcode betas installed at the moment.

ahoppen commented 4 days ago

swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-13-a was crashing due to https://github.com/swiftlang/sourcekit-lsp/issues/1469, which only affects macOS 14.4 and 14.5.

ahoppen commented 7 hours ago

This was caused by https://github.com/swiftlang/swift/pull/74367, the following reduced example crashes on macOS 15.0 beta 2 (24A5279h).

$ cat ./crash.swift 
let _: Int = try await withCheckedThrowingContinuation { continuation in
    continuation.resume(returning: 1)
}
$ /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-18-a.xctoolchain/usr/bin/swiftc crash.swift -sdk $(sdk); and ./crash
dyld[73180]: Symbol not found: _$ss31withCheckedThrowingContinuation9isolation8function_xScA_pSgYi_SSyScCyxs5Error_pGXEtYaKlF
  Referenced from: <C6DC9B57-F781-322E-BEEC-7E0F9958E6D3> /Users/alex/Desktop/crash
  Expected in:     <82723C8F-3EEF-354B-B355-CE94DA469AEE> /usr/lib/swift/libswift_Concurrency.dylib
fish: Job 1, './crash' terminated by signal SIGABRT (Abort)