swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-2623] Swift 3 compiler crashes when a public type calls a rethrowing function declared by a protocol #45228

Open groue opened 8 years ago

groue commented 8 years ago
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

  1. open GRDB.xcworkspace in Xcode
  2. 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 commented 8 years ago

The compiler crashes when:

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 commented 8 years ago

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

eeckstein commented 8 years ago

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

eeckstein commented 8 years ago

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

eeckstein commented 8 years ago

Assigning to Roman as he has fixed it.

swift-ci commented 8 years ago

Comment by Dan Thorpe (JIRA)

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

belkadan commented 8 years ago

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

swift-ci commented 8 years ago

Comment by Dan Thorpe (JIRA)

@belkadan sure, sorry for the delay...

Checkout this commit/project: https://github.com/ProcedureKit/ProcedureKit/commit/bf77b7b6e8f46cde00bb1d3bd8a923266f2c37d4 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 commented 8 years ago

Comment by Dan Thorpe (JIRA)

@belkadan the crash is "fixed" with these changes: https://github.com/ProcedureKit/ProcedureKit/commit/a31ebc3a2ef3b1ba237c9d43b464527d020bf41b

belkadan commented 8 years ago

Thanks, Dan. Reopening for now. @swiftix?

665a6372-7905-4d90-89bd-872a3b8a2537 commented 8 years ago

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.