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-15127] LLDB's TypeSystemSwiftTypeRef::GetEncoding() assertion fails on many common types #4306

Closed
BradLarson opened this issue Aug 27, 2021 · 8 comments
Assignees
Labels
bug Something isn't working LLDB for Swift

Comments

@BradLarson
Copy link
Collaborator

Previous ID SR-15127
Radar rdar://problem/82537719
Original Reporter @BradLarson
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s LLDB for Swift
Labels Bug
Assignee @adrian-prantl
Priority Medium

md5: fc3759b70fe42c89371a809dd0a9e6c8

Issue Description:

In builds with assertions enabled (such as the nightly macOS Swift toolchains), LLDB regularly hits an assertion failure in TypeSystemSwiftTypeRef::GetEncoding() when printing variables in many common cases. For example, if you create the following file in Xcode:

import Dispatch

public enum MyEnum {
    case good
    case bad
}

public extension DispatchQueue {
    func asyncEC(
        test: MyEnum = .good,
        execute work: @escaping () -> Void
    ) {
        self.async(execute: work)
    }
}

let queue = DispatchQueue(label: "A", attributes: .concurrent)

queue.asyncEC {
    let a = 33
    print(a)
}

and set a breakpoint on the `self.async()` line, building and running the above will lead to an lldb-rpc-server crash due to the failing assertion here. This renders LLDB unusable within Xcode when working with the nightly Swift snapshots and placing breakpoints in areas that trigger this assertion.

The assertion appears to be the result of non-builtin types (such as the MyEnum type above) falling through the switch statement there. The previous implementation of TypeSystemSwiftTypeRef::GetEncoding() (replaced in this commit) simply called SwiftASTContext's getEncoding() which did not have an assertion for types that fell through the switch statement in the same way. It returned a value of `lldb::eEncodingInvalid` for many of those types.

If you remove the assertion on line 2283 in TypeSystemSwiftTypeRef::GetEncoding() and build a toolchain with that version of LLDB within it, lldb-rpc-server no longer crashes in Xcode in the same places and appears to behave properly. However, simply pulling out an assertion is usually not a preferred solution, so there may be a better way to resolve this.

@typesanitizer
Copy link

cc @kastiglione

@swift-ci create

@adrian-prantl
Copy link
Member

doesn't reproduce on rebranch.

@adrian-prantl
Copy link
Member

I can't reproduce this on release/5.5 either:

```

(lldb) v

(a.MyEnum) test = good

```

@adrian-prantl
Copy link
Member

Maybe it's about a specific query Xcode makes. I'll try a downloadable toolchain.

@adrian-prantl
Copy link
Member

GetEncoding: Unhandled node kind for type $s9asynctest6MyEnumOD

@adrian-prantl
Copy link
Member

#3241

@adrian-prantl
Copy link
Member

Thanks for reporting this and particularly thanks for the test case!

@BradLarson
Copy link
Collaborator Author

@adrian-prantl - Thanks for the quick fix, that'll greatly improve the development experience for folks on our end. Sorry about not specifying that we only observed this in Xcode.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working LLDB for Swift
Projects
None yet
Development

No branches or pull requests

3 participants