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

[SR-8768] Protect against version mismatch of SwiftSyntax with swift compiler #428

Closed
mdiep opened this issue Sep 17, 2018 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@mdiep
Copy link

mdiep commented Sep 17, 2018

Previous ID SR-8768
Radar rdar://problem/44522431
Original Reporter @mdiep
Type Bug
Environment

Xcode 10.0.0 beta 6
Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.10.44)
Target: x86_64-apple-darwin17.7.0
SwiftSyntax 26b6ef6

Additional Detail from JIRA
Votes 0
Component/s SwiftSyntax
Labels Bug
Assignee None
Priority Medium

md5: 3399c662150bbbca96a7a1b96f0ead6a

Issue Description:

I get a crash running a visitor over this Swift code:

extension AnyError: LocalizedError {
    public var failureReason: String? {
        return (error as? LocalizedError)?.failureReason
    }
}

Here's the top of the backtrace:

* thread #​27, queue = 'com.apple.root.user-initiated-qos', stop reason = EXC_BAD_ACCESS (code=2, address=0x70000602ffd8)
    frame #​0: 0x00000001003526a2 SwiftSyntax`outlined copy of SwiftSyntax.TokenKind + 130
    frame #​1: 0x00000001003525fd SwiftSyntax`outlined copy of SwiftSyntax.(RawSyntaxData in _387FCEF5221330B5D0404835477A54E9) + 93
    frame #&#8203;2: 0x000000010035cf77 SwiftSyntax`initializeWithCopy for RawSyntax at <compiler-generated>:0
    frame #&#8203;3: 0x000000010139d9c6 libswiftCore.dylib`initializeWithCopy value witness for (extension in Swift):Swift.ClosedRange< where A: Swift.Strideable, A.Stride: Swift.SignedInteger>.Index + 86
    frame #&#8203;4: 0x0000000101122dc3 libswiftCore.dylib`Swift.Array._getElement(_: Swift.Int, wasNativeTypeChecked: Swift.Bool, matchingSubscriptCheck: Swift._DependenceToken) -> A + 83
    frame #&#8203;5: 0x0000000101122cc2 libswiftCore.dylib`Swift.Array.subscript.getter : (Swift.Int) -> A + 130
    frame #&#8203;6: 0x0000000101123727 libswiftCore.dylib`protocol witness for Swift.BidirectionalCollection.subscript.getter : (A.Index) -> A.Element in conformance Swift.Array<A> : Swift.BidirectionalCollection in Swift + 23
    frame #&#8203;7: 0x00000001013c6559 libswiftCore.dylib`protocol witness for Swift.Collection.subscript.getter : (A.Index) -> A.Element in conformance Swift.Array<A> : Swift.Collection in Swift + 9
    frame #&#8203;8: 0x00000001010ec5ee libswiftCore.dylib`(extension in Swift):Swift.Collection.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 494
  * frame #&#8203;9: 0x0000000100377e17 SwiftSyntax`SyntaxData.init(raw=SwiftSyntax.RawSyntax @ 0x00007000060306c0, indexInParent=0, parent=0x000060c0000e7000, self=0x000060c0000e7b00) at SyntaxData.swift:95
    frame #&#8203;10: 0x0000000100377b77 SwiftSyntax`SyntaxData.__allocating_init(raw:indexInParent:parent:) at SyntaxData.swift:0
    frame #&#8203;11: 0x000000010037886e SwiftSyntax`SyntaxData.realizeChild(index=0, self=0x000060c0000e7000) at SyntaxData.swift:232
    frame #&#8203;12: 0x0000000100378382 SwiftSyntax`closure #&#8203;1 in SyntaxData.cachedChild(self=0x000060c0000e7000, index=0) at SyntaxData.swift:120
@belkadan
Copy link

@swift-ci create

@rintaro
Copy link
Mannequin

rintaro mannequin commented Sep 19, 2018

Couldn't reproduce with current swift (master) and swift-syntax (master).
@mdiepWhich version of swift toolchain and SwiftSyntax are you using?

@mdiep
Copy link
Author

mdiep commented Sep 21, 2018

This is with Swift 4.2 and both the `master` and `0.40200.0` branches of SwiftSyntax.

@mdiep
Copy link
Author

mdiep commented Sep 21, 2018

Hmm… I think this is user error from how I was building SwiftSyntax. I was building against my checkout of Swift, which is `master`, when I thought I was building against 4.2.

But it does seem like this still shouldn't crash. If the output from swift is unexpected, it seems like that should result in an error instead of a crash.

@akyrtzi
Copy link
Member

akyrtzi commented Oct 5, 2018

This is a case where older SwiftSyntax was matched against newer compiler. Not sure about best way to protect against that and if it is worth it, CC'ing @nkcsgexi, @rintaro, @ahoppen.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
@ahoppen
Copy link
Collaborator

ahoppen commented Jun 21, 2022

This should have been fixed a long time a ago when we started verifying the syntax node hash between the parser library and the SwiftSyntax library.

@ahoppen ahoppen closed this as completed Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants