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-3153] Segfault with circularity in protocol associated types #45741

Closed
swift-ci opened this issue Nov 7, 2016 · 3 comments
Closed

[SR-3153] Segfault with circularity in protocol associated types #45741

swift-ci opened this issue Nov 7, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself serialization Area → compiler: Serialization & deserialization

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 7, 2016

Previous ID SR-3153
Radar None
Original Reporter Noobish1 (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 8.1/Swift 3.0.1

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

md5: d6a496a42b8e4894e181c8a2a4ac571d

Issue Description:

When these three protocol/structs are defined in one file there is no segfault, but when they are defined in separate files it causes a segfault.

import Foundation

public protocol JSONKey: RawRepresentable, Hashable {
    var stringValue: String { get }
}

extension JSONKey where Self.RawValue == String {
    public var stringValue: String {
        return rawValue
    }
}
import Foundation

public struct KeyedMapper<Object: Mappable> {
    public let JSON: [AnyHashable : Any]

    public init(JSON: [AnyHashable : Any], type: Object.Type) {
        self.JSON = JSON
    }
}
import Foundation

public protocol Mappable {
    associatedtype Key: JSONKey

    init(map: KeyedMapper<Self>) throws
}

Part of the log is this

1.  While reading from /Users/Blair/Library/Developer/Xcode/DerivedData/KeyedMapperSegFault-cbmkkertbzqysabwirlimgurjxaj/Build/Intermediates/KeyedMapperSegFault.build/Debug-iphonesimulator/KeyedMapperSegFault.build/Objects-normal/x86_64/KeyedMapper~partial.swiftmodule
2.  While deserializing decl #&#8203;3 (STRUCT_DECL)
3.  While deserializing 'Object' (GenericTypeParamDecl #&#8203;1) 
4.  While deserializing decl #&#8203;6 (XREF)
5.  Cross-reference to module 'KeyedMapperSegFault'
    ... Mappable
    ... Key
6.  While loading members for 'Mappable' at <invalid loc>
7.  While deserializing 'init' (ConstructorDecl #&#8203;4) 
8.  While deserializing decl #&#8203;8 (PARAM_DECL)
9.  While deserializing decl #&#8203;9 (XREF)
10. Cross-reference to module 'KeyedMapperSegFault'
    ... KeyedMapper
11. While reading from /Users/Blair/Library/Developer/Xcode/DerivedData/KeyedMapperSegFault-cbmkkertbzqysabwirlimgurjxaj/Build/Intermediates/KeyedMapperSegFault.build/Debug-iphonesimulator/KeyedMapperSegFault.build/Objects-normal/x86_64/KeyedMapper~partial.swiftmodule
12. While deserializing decl #&#8203;3 (STRUCT_DECL)
@belkadan
Copy link
Contributor

belkadan commented Nov 7, 2016

For anyone else hitting the same issue: only Mappable and KeyedMapper should need to be in one file.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 4, 2017

Comment by Christopher Hatton (JIRA)

Thanks @belkadan for reporting this problem: and the (hopefully temporary) solution of putting the inter-dependant definitions in the same file.

The problem seems to be masked whenever 'Whole Module Optimization' is switched on; but is manifest whenever it is off i.e. in Debug configuration.

As heavy users of Swift generics, coping with this issue and other 'SegFault' compiler bugs has been costing our team quite a lot of time.

@slavapestov
Copy link
Member

This was fixed a while ago when we added nested type lookup in deserialization.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 serialization Area → compiler: Serialization & deserialization
Projects
None yet
Development

No branches or pull requests

3 participants