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-2623] Swift 3 compiler crashes when a public type calls a rethrowing function declared by a protocol #45228

Open
groue opened this issue Sep 13, 2016 · 11 comments
Assignees
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 optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@groue
Copy link

groue commented Sep 13, 2016

Previous ID SR-2623
Radar None
Original Reporter @groue
Type Bug
Status Reopened
Resolution
Environment

Xcode 8 GM Version 8.0 (8A218a), SWIFT_VERSION=3.0

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

md5: 44aba97a60df66fb84678b64067ecd23

Issue Description:

Hello,

The Swift 3 compiler embedded in Xcode 8 GM Version 8.0 (8A218a) crashes when building the GRDBOSX scheme in Release configuration of https://github.com/groue/GRDB.swift/tree/a8906da890820a0c9090821569c33d411efc9d8f

Steps to reproduce:

1. download the project at https://github.com/groue/GRDB.swift/tree/a8906da890820a0c9090821569c33d411efc9d8f
2. open GRDB.xcworkspace in Xcode
3. build the GRDBOS scheme in the Release configuration

Compiler crashes with Segmentation fault 11 "While running pass #410260 SILFunctionTransform "Simplify CFG" on SILFunction "@TFC4GRDB24FetchedRecordsController12performFetchfT_T"."

I could not build a smaller sample code which exhibits the issue, unfortunately. It looks like the trouble lies in the DatabaseWriter protocol, which crashes the compiler when it is used.

@groue
Copy link
Author

groue commented Sep 13, 2016

The compiler crashes when:

  • a protocol declares a rethrowing function

  • a public object (class or struct) has a property which adopts the protocol

  • the rethrowing function is called on the property

  • the code is compiled in the Release configuration

Here is a minimal sample code which reproduces the issue (I could make it crash in an Xcode project):

protocol P {
    func f(closure: () throws -> Void) rethrows
}

// Segmentation fault: 11
// While running pass #​271294 SILFunctionTransform "Simplify CFG" on SILFunction "@_TFC4GRDB11PublicClass1ffT_T_"
public class PublicClass {
    let p: P
    init(p: P) {
        self.p = p
    }
    public func f() {
        p.f { _ in }
    }
}

// No error
class InternalClass {
    let p: P
    init(p: P) {
        self.p = p
    }
    public func f() {
        p.f { _ in }
    }
}

// Segmentation fault: 11
// While running pass #​271367 SILFunctionTransform "Simplify CFG" on SILFunction "@_TFV4GRDB12PublicStruct1ffT_T_".
public struct PublicStruct {
    let p: P
    init(p: P) {
        self.p = p
    }
    public func f() {
        p.f { _ in }
    }
}

// No error
struct InternalStruct {
    let p: P
    init(p: P) {
        self.p = p
    }
    public func f() {
        p.f { _ in }
    }
}

@belkadan
Copy link
Contributor

Looks like we've fixed this in master. @eeckstein, do you know what would have fixed this?

@eeckstein
Copy link
Member

No. There were no changes in SimplifyCFG which could have fixed this. I'm still investigating...

@eeckstein
Copy link
Member

Found it. It was fixed by 226e4a7 "Fix a bug related to the opened archetypes tracking"

@eeckstein
Copy link
Member

Assigning to Roman as he has fixed it.

@swift-ci
Copy link
Collaborator

Comment by Dan Thorpe (JIRA)

Can be re-produced when an internal type has property which adopts the protocol. Not just public.

@belkadan
Copy link
Contributor

danthorpe (JIRA User), can you attach your project, so we can try it against master?

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 1, 2016

Comment by Dan Thorpe (JIRA)

@belkadan sure, sorry for the delay...

Checkout this commit/project: ProcedureKit/ProcedureKit@bf77b7b and then compile the ProcedureKit target for Mac.

git clone https://github.com/ProcedureKit/ProcedureKit.git
git fetch origin
git checkout bf77b7b6e8f46cde00bb1d3bd8a923266f2c37d4

Compiling in Release configuration gives:

  1. While running pass [CodeCompletion] Rebalance match score and semantic context #3661 SILFunctionTransform "Simplify CFG" on SILFunction "@TFC12ProcedureKit9Protector4readurfFxqdqd_".

The type in question is a generic abstraction to provide many-reads/single-write thread safety, see Protector in Sources/Support.swift

Also, this changeset was necessary to get round a Swift 3.0 (Xcode 8.0) release configuration compilation error (doesn't happen in debug configuration) - separate issue which you might be interested in too.

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 2, 2016

Comment by Dan Thorpe (JIRA)

@belkadan the crash is "fixed" with these changes: ProcedureKit/ProcedureKit@a31ebc3

@belkadan
Copy link
Contributor

belkadan commented Oct 3, 2016

Thanks, Dan. Reopening for now. @swiftix?

@swiftix
Copy link
Mannequin

swiftix mannequin commented Oct 4, 2016

I'm looking into it. When I tried to reproduce with the ToT compiler, I'm running into a different issue. The compiler crashes in the devirtualizer. Seems like this new bug was introduced very recently.

@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 optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

5 participants