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-10441] Demangler crash: Assertion failed: (false && "cannot add child") #52841

Open
theblixguy opened this issue Apr 10, 2019 · 5 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@theblixguy
Copy link
Collaborator

Previous ID SR-10441
Radar None
Original Reporter @theblixguy
Type Bug
Environment

Swift 5.1 (near master), macOS 10.14.4

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: fe28a105cf1569245add499d28117e10

Issue Description:

This code causes a crash in the demangler:

protocol Foo {
  associatedtype ErrorType: Error
}

extension Array: Error where Element: Error {}

class Bar<A: Foo> {
  func doSomething(with result: Result<Any, [A.ErrorType]>) {}
}
Assertion failed: (false && "cannot add child"), function addChild, file /Users/suyashsrijan/Documents/swift-src/swift/lib/Demangling/Demangler.cpp, line 355

Removing the where clause on the Array extension fixes the crash. The following code also leads to a crash, however it happens in the ASTMangler when calling `swift::Mangle::ASTMangler::getSpecialManglingContext()`:

extension Array: Error where Element: Error {}

class Bar {
  func doSomething(with result: Result<Any, [Error]>) {}
}
Assertion failed: (is<T>() && "Invalid accessor called"), function get, file /Users/suyashsrijan/Documents/swift-src/llvm/include/llvm/ADT/PointerUnion.h, line 136.

I think this has to do with passing an Array<Error> to the Result type and adding the constrained extension on Array.

@theblixguy
Copy link
Collaborator Author

cc @slavapestov do you know why this is happening?

@theblixguy
Copy link
Collaborator Author

I dumped the Child and it's

kind=Type
  kind=Protocol
    kind=Module, text="test_file"
    kind=Identifier, text="Foo"

The `PayloadKind` happens to be `Index` here, so it hits the default case of the switch and hits the assertion. Without assertions, this crashes in SIL.

@theblixguy
Copy link
Collaborator Author

I wonder if the index has something to do with the generic parameter(s) on Bar...

@slavapestov
Copy link
Member

@DougGregor might have some ideas

@theblixguy
Copy link
Collaborator Author

Thanks I'll wait for @DougGregor to respond. In the meantime, here's something I noticed - I extracted the mangled name in both scenarios and when I pass it to swift-demangle, it demangles just fine. However, when you expand the mangling for the case where the Array's element is constrained to Error, there's some extra nodes inside AnyProtocolConformanceList:

kind=DependentProtocolConformanceRoot, index=1
                              kind=DependentProtocolConformanceRoot, index=1
                                kind=Type
                                  kind=Protocol
                                    kind=Module, text="test_file"
                                    kind=Identifier, text="Foo"
                                kind=Type
                                  kind=DependentGenericParamType, text="A"
                                    kind=Index, index=0
                                    kind=Index, index=0
                              kind=DependentAssociatedConformance
                                kind=Type
                                  kind=DependentMemberType
                                    kind=Type
                                      kind=DependentGenericParamType, text="A"
                                        kind=Index, index=0
                                        kind=Index, index=0
                                    kind=DependentAssociatedTypeRef, text="ErrorType"
                                kind=Type
                                  kind=Protocol
                                    kind=Module, text="Swift"
                                    kind=Identifier, text="Error"

Mangling for doSomething() when the Element is constrained to Error using the where clause:

s9test_file3BarC11doSomething4withys6ResultOyypSay9ErrorTypeQzGAJs0H0AAxAA3FooHD1_AIsAKHA1__HCg_G_tF

Mangling for doSomething() when the Element not is constrained to Error using the where clause:

s9test_file3BarC11doSomething4withys6ResultOyypSay9ErrorTypeQzGAJs0H0AAyHCg_G_tF

Not quite sure why this is failing to demangle, but I'll wait for Doug to provide any ideas so I can fix this bug!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants