Files
swift-mirror/validation-test/Evolution/Inputs/protocol_add_requirements.swift
Slava Pestov 6bf9ab19ff Add preliminary library evolution test for resiliently adding a new protocol requirement
This test ensures that the runtime correctly instantiates resilient conformances,
and that IRGen emits the correct metadata, allowing a conformance that was
compiled before a new requirement was added to present a default implementation
of this requirement.

For now, this runs with --no-backward-deployment, so we only test before/before,
before/after and after/after cases.

Getting after/before working is also an expected capability here, but requires
IRGen witness table emission to know which requirements were satisfied by
defaults, so that they can be dropped if they appear at the end of a witness
table. In turn, this requires serializing SILDefaultWitnessTables. This will
be added in a subsequent patch.

In addition to fixing the above case, I need to write additional tests and
possibly fix bugs related to more elaborate cases involving generics, as well as
default witnesses for properties and subscripts.
2016-03-03 07:37:00 -08:00

52 lines
963 B
Swift

public func getVersion() -> Int {
#if BEFORE
return 0
#else
return 1
#endif
}
public protocol ElementProtocol : Equatable {
func increment() -> Self
}
public protocol AddRequirementsProtocol {
associatedtype Element : ElementProtocol
func importantOperation() -> Element
func unimportantOperation() -> Element
#if AFTER
func uselessOperation() -> Element
#endif
}
extension AddRequirementsProtocol {
public func unimportantOperation() -> Element {
return importantOperation().increment()
}
#if AFTER
public func uselessOperation() -> Element {
return unimportantOperation().increment()
}
#endif
}
public func doSomething<T : AddRequirementsProtocol>(t: T) -> [T.Element] {
#if BEFORE
return [
t.importantOperation(),
t.unimportantOperation(),
t.unimportantOperation().increment(),
]
#else
return [
t.importantOperation(),
t.unimportantOperation(),
t.uselessOperation(),
]
#endif
}