mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The above referenced issue was causing a compiler crash when writing differentiable protocols and corresponding implementers, without importing the `_Differentiation` module. Changes in this CR fix the issue by marking any `@differentiable` attributes as invalid, if the `_Differentiation` module has not been imported. This ignores the `@differentiable` attributes when the protocol witnesses are being verified. Witness verification was previously leading to an error (due to missing `@differentiable` attribute on the protocol requirement implementer), and the corresponding diagnostic emission code was then leading to a crash, because it was expecting the `_Differentiation` module to be present.
17 lines
656 B
Swift
17 lines
656 B
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
protocol P {
|
|
@differentiable(reverse) // expected-error {{@differentiable attribute used without importing module '_Differentiation'}}
|
|
func req()
|
|
}
|
|
|
|
struct S: P {
|
|
// Had the `_Differentiation` module been imported, this conformance
|
|
// requirement would have generated an error, complaining about the
|
|
// missing `@derivative` attribute. However, because the `_Differentiation`
|
|
// module import is missing, the `@differential` attribute on `P` is marked
|
|
// invalid and therefore not used while validating witnesses (specifically `S.req()`)
|
|
// for the `P.req()` requirement.
|
|
public func req() {}
|
|
}
|