mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Compiler: - Add `Forward` and `Reverse` to `DifferentiabilityKind`. - Expand `DifferentiabilityMask` in `ExtInfo` to 3 bits so that it now holds all 4 cases of `DifferentiabilityKind`. - Parse `@differentiable(reverse)` and `@differentiable(_forward)` declaration attributes and type attributes. - Emit a warning for `@differentiable` without `reverse`. - Emit an error for `@differentiable(_forward)`. - Rename `@differentiable(linear)` to `@differentiable(_linear)`. - Make `@differentiable(reverse)` type lowering go through today's `@differentiable` code path. We will specialize it to reverse-mode in a follow-up patch. ABI: - Add `Forward` and `Reverse` to `FunctionMetadataDifferentiabilityKind`. - Extend `TargetFunctionTypeFlags` by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in `DifferentiabilityMask` which is reserved for `AsyncMask` and `ConcurrentMask`; `AsyncMask` is ABI-stable so we cannot change that. _Differentiation module: - Replace all occurrences of `@differentiable` with `@differentiable(reverse)`. - Delete `_transpose(of:)`. Resolves rdar://69980056.
51 lines
2.3 KiB
Swift
51 lines
2.3 KiB
Swift
// Test missing protocol requirement `@differentiable` attribute errors for
|
|
// non-public protocol witnesses, when the protocol conformance is declared in a
|
|
// separate file from witnesses.
|
|
//
|
|
// Implicit `@differentiable` attributes cannot be generated for protocol
|
|
// witnesses when the conformance is declared from a separate file from the
|
|
// witness. Otherwise, compilation of the file containing the conformance
|
|
// creates references to external symbols for implicit `@differentiable`
|
|
// attributes, even though no such symbols exist.
|
|
//
|
|
// Context: https://github.com/apple/swift/pull/29771#issuecomment-585059721
|
|
|
|
// Note: `swiftc main.swift other_file.swift` runs three commands:
|
|
// - `swiftc -frontend -primary-file main.swift other_file.swift -o ...`
|
|
// - `swiftc -frontend main.swift -primary-file other_file.swift -o ...`
|
|
// - `/usr/bin/ld ...`
|
|
//
|
|
// `%target-build-swift` performs `swiftc main.swift other_file.swift`, so it is expected to fail (hence `not`).
|
|
// `swiftc -frontend -primary-file main.swift other_file.swift` should fail, so `-verify` is needed.
|
|
// `swiftc -frontend main.swift -primary-file other_file.swift` should succeed, so no need for `-verify`.
|
|
|
|
// RUN: %target-swift-frontend -c -verify -primary-file %s %S/Inputs/other_file.swift
|
|
// RUN: %target-swift-frontend -c %s -primary-file %S/Inputs/other_file.swift
|
|
// RUN: not %target-build-swift %s %S/Inputs/other_file.swift
|
|
|
|
import _Differentiation
|
|
|
|
// Error: conformance is in different file than witnesses.
|
|
// expected-error @+1 {{type 'ConformingStruct' does not conform to protocol 'Protocol1'}}
|
|
extension ConformingStruct: Protocol1 {}
|
|
|
|
// No error: conformance is in same file as witnesses.
|
|
extension ConformingStruct: Protocol2 {
|
|
func internalMethod4(_ x: Float) -> Float {
|
|
x
|
|
}
|
|
}
|
|
|
|
public final class ConformingStructWithSupersetAttr: Protocol2 {}
|
|
|
|
// rdar://70348904: Witness mismatch failure when a matching witness with a *superset* `@differentiable`
|
|
// attribute is specified.
|
|
//
|
|
// Note that public witnesses are required to explicitly specify `@differentiable` attributes except
|
|
// those w.r.t. parameters that have already been covered by an existing `@differentiable` attribute.
|
|
extension ConformingStructWithSupersetAttr {
|
|
// @differentiable(reverse, wrt: self) // Omitting this is okay.
|
|
@differentiable(reverse)
|
|
public func internalMethod4(_ x: Float) -> Float { x }
|
|
}
|