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-12534] Segfault + type of expression is ambiguous without more context #54977

Open
swift-ci opened this issue Apr 7, 2020 · 7 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 regression swift 5.2

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 7, 2020

Previous ID SR-12534
Radar rdar://problem/62201672
Original Reporter Anandabits (JIRA User)
Type Bug

Attachment: Download

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

md5: efe5a0167c1f9d308b4c1005db2b545e

Issue Description:

The attached sample project compiles fine in Swift 5.1 / Xcode 11.3 but has issues in Swift 5.2 / Xcode 11.4

@beccadax
Copy link
Contributor

@swift-ci create

@CodaFi
Copy link
Member

CodaFi commented Apr 24, 2020

It takes a lot to untwist this example, but ultimately it's failing to resolve the conformance of `S2<B, Z>` to `SS`. `B` is referenced recursively as a protocol requirement rather than as a generic parameter, which may be the consequence of several lookup-related changes we've made in 5.2. Either way, whatever `B` maps to, I would encourage you to define it explicitly in the conformance and give it a name that does not conflict with the protocol requirement.

@swift-ci
Copy link
Collaborator Author

Comment by Matthew Johnson (JIRA)

Thank you for tracking this down. I apologize for the complexity - it took quite a while to boil this down from proprietary code and I didn't have time to simplify further.

Now that you understand what is going on, would you say that the Swift 5.1 behavior is correct? Or are you suggesting that when the crash is fixed behavior will be different going forward (such as a build error)?

The `B` in the `SS` conformance is even getting inferred rather than being explicitly stated in Swift 5.1. Are there any general recommendations we can follow to avoid issues when providing a conformance that involves type parameter / associated type conflicts like this? Or should inference just work here like it did in 5.1?

In this particular case neither `S2` or `SS` are intended to be aware of the existence of the other at all. So in some sense, the name `B` being used in both places is coincidental. The app itself is the only thing aware of both, so the usual caveat of not conforming a type from a different module to a protocol from a different module doesn't apply.

@swift-ci
Copy link
Collaborator Author

Comment by Matthew Johnson (JIRA)

@CodaFi I updated the relevant code in my production project so the protocol and the type parameter are no longer the same and I'm still seeing a segfault in the compiler.

@CodaFi
Copy link
Member

CodaFi commented Jun 23, 2020

Ah, turns out all you needed was S2.C to be resolved here

extension S2: SP {
    public enum A { case a }

    public func a(_ a: S2.A) { }
    public var b: LS<B, Z> { _b }
    public typealias C = LS<B, Z>
}

@CodaFi
Copy link
Member

CodaFi commented Jun 23, 2020

Still, the compiler should not crash on this code. Associated type inference is not registering missing witnesses when it resolves S2: SP, it just substitutes in the ErrorTypes it gets while resolving the broken conformance. This seems like a regression in associated type inference. We should be able to infer C from the value witness

public func c(_: @escaping (LS<B, Z>) -> Void) { }

@CodaFi
Copy link
Member

CodaFi commented Jun 23, 2020

Breaking the inheritance relation between SS and SP also doesn't crash because associated type inference can see the value witnesses in SP and try them first instead of trying to resolve SS first, find no value witnesses to infer from, and pick up error types.

@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 regression swift 5.2
Projects
None yet
Development

No branches or pull requests

4 participants