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-11153] Segmentation fault: 11 when using multiple protocols with Self constraints #53550

Closed
swift-ci opened this issue Jul 17, 2019 · 7 comments
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-11153
Radar rdar://problem/53257826
Original Reporter Qbyte (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11.0 beta 3, beta 4 and beta 5 using "Swift 5" as "Swift Language Version"

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

md5: 1cfc1409d7950524b30cb3f47f9f9e83

Issue Description:

The following code produces a Segmentation fault: 11:

protocol VectorSpace {
    associatedtype Field: FieldAlgebra
}

protocol FieldAlgebra: VectorSpace where Self.Field == Self {
    associatedtype ComparableSubalgebra: ComparableFieldAlgebra
    static var zero: Self { get }
}

protocol ComparableFieldAlgebra: FieldAlgebra where Self.ComparableSubalgebra == Self {
}

func test<F: FieldAlgebra>(_ f: F) {
    _ = F.ComparableSubalgebra.zero
}

It still produces the Segmentation fault if you change the protocol FieldAlgebra to

protocol FieldAlgebra: VectorSpace {
    typealias Field = Self
    associatedtype ComparableSubalgebra: ComparableFieldAlgebra
    static var zero: Self { get }
}
@theblixguy
Copy link
Collaborator

It doesn't crash for me on the master branch, where I get the following warning:

typealias overriding associated type 'Field' from protocol 'VectorSpace' is better expressed as same-type constraint on the protocol

@belkadan
Copy link
Contributor

Even in the version without the typealias? I'm seeing a crash in irgen::emitArchetypeWitnessTableRef, but admittedly I haven't pulled from master recently.

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Maximilian Hünenberger (JIRA)

I just tested on Xcode 11.0 beta 4 and it still produces the segmentation fault.

@theblixguy
Copy link
Collaborator

Sorry, I tried with `-emit-ir` and both examples didn't cause a segfault, but yeah, when compiling normally it crashes in `emitArchetypeWitnessTableRef` as you mentioned. Sorry for the false alarm!

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 9, 2019

Comment by Maximilian Hünenberger (JIRA)

I tested it again on Xcode 11.0 beta 5 and it still produces a "Segmentation fault: 11" and after a clean build additionally "Command CompileSwift failed with a nonzero exit code".

@tjw
Copy link
Contributor

tjw commented Sep 24, 2019

I've been hitting a similar (same?) crasher for months now and finally had a few cycles to narrow it down. My case only happens if there are multiple source files, though, so it might not be exactly the same (still crashes in `emitArchetypeWitnessTableRef`.

This crashes for me still in Xcode 11.0 GM2 (11A420a).

In one file:

protocol Snapshotting {
    associatedtype NativeType: NativeInserting where NativeType.SnapshotType == Self
    associatedtype ChangeType: SnapshotChange where ChangeType.SnapshotType == Self
}

protocol NativeInserting {
    associatedtype SnapshotType : Snapshotting where SnapshotType.NativeType == Self
}

protocol SnapshotProperties : OptionSet where RawValue == Int {
    static var all: Self { get }
}

protocol SnapshotChange {
    associatedtype SnapshotType : Snapshotting where SnapshotType.ChangeType == Self
    associatedtype PropertiesType : SnapshotProperties
}

and in the other file:

class WatchRegistry {
    func single<S: Snapshotting>(objectType: S.Type) throws -> Watch<S>
    {
        return try Watch<S>.singleObject(objectType: S.self, properties: S.ChangeType.PropertiesType.all)
    }
}

class Watch<SnapshotType : Snapshotting> {
    static func singleObject(objectType: SnapshotType.Type, properties: SnapshotType.ChangeType.PropertiesType) throws -> Watch<SnapshotType> {
        fatalError()
    }
}

@slavapestov
Copy link
Member

The original crash is fixed by #36402 @tjw's test case appears to be a different issue. I can confirm it crashes in Swift 5.1 but works in Swift 5.2, so it was fixed by some other change along the way. I'll add a regression test to be sure.

@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

6 participants