DianQK / Flix

iOS reusable form library in Swift.
MIT License
725 stars 43 forks source link

Segmentation fault: 11 While emitting IR SIL function ... #30

Open DianQK opened 5 years ago

DianQK commented 5 years ago

Maybe you will find Segmentation fault: 11 While emitting IR SIL function ... error info when use AnimatableCollectionViewProvider. This look like Swift bug.

This issue will closed when this error go away.

This code will cause Segmentation fault: 11:

class TestRadioProvider<Option: Equatable & StringIdentifiableType>: AnimatableCollectionViewProvider {
    func configureCell(_ collectionView: UICollectionView, cell: RadioCollectionViewCell, indexPath: IndexPath, value: Value) {
    }
    func createValues() -> Observable<[Value]> {
        return Observable.empty()
    }
    typealias Cell = RadioCollectionViewCell
    typealias Value = Option
}

There are some workaround methods:

add createAnimatableNodes:

class TestRadioProvider<Option: Equatable & StringIdentifiableType>: AnimatableCollectionViewProvider {
    func configureCell(_ collectionView: UICollectionView, cell: RadioCollectionViewCell, indexPath: IndexPath, value: Value) {
    }
    func createValues() -> Observable<[Value]> {
        return Observable.empty()
    }
    typealias Cell = RadioCollectionViewCell
    typealias Value = Option
    func createAnimatableNodes() -> Observable<[IdentifiableNode]> {
        let providerIdentity = self._flix_identity
        return createValues()
            .map { $0.map { IdentifiableNode(providerIdentity: providerIdentity, valueNode: $0) } }
    }
}

or add a model to warp this Option:

struct SegmentationFault11Warp<Value: Equatable & StringIdentifiableType>: Equatable & StringIdentifiableType {
    var identity: String {
        return value.identity
    }
    let value: Value
}

class TestRadioProvider<Option: Equatable & StringIdentifiableType>: AnimatableCollectionViewProvider {
    func configureCell(_ collectionView: UICollectionView, cell: RadioCollectionViewCell, indexPath: IndexPath, value: Value) {
    }
    func createValues() -> Observable<[Value]> {
        return Observable.empty()
    }
    typealias Cell = RadioCollectionViewCell
    typealias Value = SegmentationFault11Warp<Option>
}
10000TB commented 5 years ago

This very helpful !

@DianQK wondering how to explain the crash and your advised ways of workaround ?