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-13849] Compiler crash when building generic signature for substitutable type #56247

Closed
swift-ci opened this issue Nov 12, 2020 · 7 comments
Closed
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

@swift-ci
Copy link
Collaborator

Previous ID SR-13849
Radar rdar://problem/71343919
Original Reporter Trundle (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 8cf6ce4d00d73c29d31cc99f8cc77747

Issue Description:

The following code makes the Swift compiler crash with an assertion error:

protocol Prot {
    associatedtype T
}

class C<P: Prot> where P.T: Hashable {
}

class Spam<P: Prot> where P.T == Int {
    func m(_ f: (C<P>) -> C<P>) {
    }
}

Output:

swift: /home/build-user/swift/lib/SIL/IR/SILFunctionType.cpp:1167: swift::CanType (anonymous namespace)::SubstFunctionTypeCollector::getSubstitutedInterfaceType(swift::Lowering::AbstractionPattern, swift::CanType): Assertion `result && "substType was not bindable to abstraction pattern type?"' failed.
Stack dump:
0.  Program arguments: /usr/bin/swift -frontend -interpret /tmp/spam.swift -disable-objc-interop -color-diagnostics -module-name spam 
1.  Swift version 5.3 (swift-5.3-RELEASE)
2.  While evaluating request SILGenWholeModuleRequest(SIL Generation for module spam)
3.  While emitting SIL for 'm(_:)' (at /tmp/spam.swift:9:5)
@typesanitizer
Copy link

@swift-ci create

@typesanitizer
Copy link

Thanks for the minimal bug report and the note about the assertion!

@CodaFi
Copy link
Member

CodaFi commented Nov 16, 2020

This is a known problem where the GSB treats anchors derived from covariant Self in the wrong way which produces incorrectly-minimized signatures. You can work around this by applying the Hashable constraint directly to the protocol requirement and removing the where clause, or if possible, by making the class `final`.

@swift-ci
Copy link
Collaborator Author

Comment by Andreas Stührk (JIRA)

Thank you for the workarounds![]( I have another snippet that produces another assertion error (void swift::ArchetypeType::registerNestedType(swift::Identifier, swift::Type): Assertion found )= NestedTypes.end() && found->first == name && "Unable to find nested type?"' failed`) and goes away once I make the class final. Is it worth reporting it as a separate bug or is it likely a duplicate of this one?

@CodaFi
Copy link
Member

CodaFi commented Nov 17, 2020

It’s the same bug.

@slavapestov
Copy link
Member

It's a different bug, but I'm working on a fix.

@slavapestov
Copy link
Member

#36697

@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
This issue was closed.
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

5 participants