swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.2k stars 10.32k forks source link

[SR-10949] Sourcekitd crashed making a CursorInfo request #53340

Open ChristopherRogers opened 5 years ago

ChristopherRogers commented 5 years ago
Previous ID SR-10949
Radar None
Original Reporter @ChristopherRogers
Type Bug

Attachment: Download

Environment swift-DEVELOPMENT-SNAPSHOT-2019-06-06-a or swift-5.1-DEVELOPMENT-SNAPSHOT-2019-06-15-a Xcode 11 beta 1 (11M336w) sk-stress-test --rewrite-mode=concurrent /path/to/Foo.swift swiftc -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk -target x86_64-apple-ios10.0-simulator /path/to/Foo.swift
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Source Tooling | |Labels | Bug, CompilerCrash, FoundByStressTester | |Assignee | None | |Priority | Medium | md5: 64085663e3c2e65713d51c345b5a5a94

Issue Description:

Assertion failed: (!baseName.isSpecial() && "Can't retrieve the identifier of a special base name"), function getBaseIdentifier, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/include/swift/AST/Identifier.h, line 449.

sourcekit: [1:connection-event-handler:8515: 0.0000] Connection interruptFailure detected: SourceKit crashed
  request: CursorInfo in /Users/JP61036/Code/line-ios/Logger.swift (modified: insideOut) at offset 51 with args: -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk -target x86_64-apple-ios10.0-simulator swift-5.1-DEVELOPMENT-SNAPSHOT-2019-06-15-a /Users/JP61036/Code/line-ios/Logger.swift
-- begin file content --------
extension Foo {
    init(_ bar: Bar) 
        self.<cursor-offset>init
-- end file content ----------
sourcekit: [1:updateSemanticEditorDelay:8515: 0.0009] disabling semantic editor for 10 secondssourcekit: [1:pingService:8515: 0.0010] pinging servicesourcekit: [1:ping-event-handler:9475: 0.0011] connection invalid error
belkadan commented 5 years ago

davidungar (JIRA User), the backtrace looks like some of your refactorings? Not sure, though.

swift-ci commented 5 years ago

Comment by David Ungar (JIRA)

Thanks, @belkadan. I'll take a look.

swift-ci commented 5 years ago

Comment by David Ungar (JIRA)

The portion that passes through my refactoring was also there before the refactoring.

(See line 1220-1224 in NameLookup.cpp, commit 18f4bcb5ff8a15db71581da090fc3f35495e867a.)

I'm happy to look at it; @belkadan, can you tell me how to reproduce this kind of crash?

belkadan commented 5 years ago

I haven't ever actually had to myself. @nathawes, @nkcsgexi?

nathawes commented 5 years ago

You can reproduce it using the sourcekit-test utility, which should be in bin next to swiftc if you're building locally:

1. Add the content between the 'begin/end file content' markers to a new file e.g. /tmp/test.swift:

extension Foo {
    init(_ bar: Bar) 
        self.<cursor-offset>init

2. work out the character offset of and remove the '\<cursor-offset>' part from the file (51 in this case) and save.

  1. in your local build directory run 'sourcekitd-test' as below to reproduce the crash:
<build-dir>/bin/sourcekitd-test -req=cursor -offset=51 /tmp/test.swift -- /tmp/test.swift

The bit after the -- is the swift compiler args to use for the file you're interested in. In this case it's a self-contained invalid file, so we don't need anything other than the file itself.

swift-ci commented 5 years ago

Comment by David Ungar (JIRA)

Thanks a bunch, @belkadan and @nathawes . I've got a putative fix: https://github.com/apple/swift/pull/25584 . If it passes review, I'll land it.