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

Comments

@groue
Copy link

@groue 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 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

@belkadan belkadan commented Sep 14, 2016

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

@eeckstein
Copy link
Member

@eeckstein eeckstein commented Sep 14, 2016

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

@eeckstein
Copy link
Member

@eeckstein eeckstein commented Sep 15, 2016

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

@eeckstein
Copy link
Member

@eeckstein eeckstein commented Sep 15, 2016

Assigning to Roman as he has fixed it.

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Sep 24, 2016

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

@belkadan belkadan commented Sep 26, 2016

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

@swift-ci
Copy link
Collaborator

@swift-ci 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 #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 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 belkadan commented Oct 3, 2016

Thanks, Dan. Reopening for now. @swiftix?

@swiftix
Copy link
Mannequin

@swiftix 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants