swiftlang / swift

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

[SR-7804] Cross-module protocol conformance fails with optimised build #50343

Open swift-ci opened 6 years ago

swift-ci commented 6 years ago
Previous ID SR-7804
Radar None
Original Reporter ArekPerform (JIRA User)
Type Bug

Attachment: Download

Environment Xcode 9.3, Xcode 9.4 Target: iOS simulator, any device MacOS 10.13.4
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 273257dafa930bf84c29e4a65beb1213

Issue Description:

Module A provides a protocol conformance for UIKit type

extension UIControlState: Hashable {
    public var hashValue: Int {
        return Int(rawValue.hashValue)
    }
}

Module B makes use of that type

    func buttonTexts() -> [UIControlState: String] {
        return [
            UIControlState.normal: "normal",
            UIControlState.highlighted: "highlighted"
        ]
    }

If Swift optimisation is set to None for Module B the app compiles. If it's set to -O fails with error:

Undefined symbols for architecture x86_64:
  "protocol witness table for __C.UIControlState : Swift.Equatable in UIKit", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Dead> of generic specialization <__C.UIControlState, Swift.String> of static (extension in Swift):Swift._NativeDictionaryBuffer< where A: Swift.Hashable>.fromArray([(A, B)]) -> Swift._NativeDictionaryBuffer<A, B> in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Example project attached

belkadan commented 6 years ago

Fixed in master and on the Swift 4.2 branch! @slavapestov, do you remember what fixed this one?

swift-ci commented 6 years ago

Comment by Arkadiusz Matecki (JIRA)

Awesome, too bad it wasn't fixed before I had to do important release 😉