Files
swift-mirror/test/AutoDiff/compiler_crashers_fixed/sr13305-noderivative-inout-parameter.swift
Richard Wei af8942d940 [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'.
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.
2021-02-07 14:09:46 -08:00

39 lines
1.8 KiB
Swift

// RUN: %target-swift-frontend -emit-sil -verify %s
import _Differentiation
// SR-13305: Test protocol witness thunk for `@differentiable` protocol
// requirement, where the required method has a non-wrt `inout` parameter
// that should be treated as a differentiability result.
protocol SR_13305_Protocol {
@differentiable(reverse, wrt: x)
func method(x: Float, y: inout Float)
}
struct SR_13305_Struct: SR_13305_Protocol {
@differentiable(reverse, wrt: x)
func method(x: Float, y: inout Float) {
y = y * x
}
}
// Original crash:
// Assertion failed: (!array.empty() && "claiming next from empty array!"), function claimNext, file /Users/danielzheng/swift-build/swift/lib/SILGen/SILGenPoly.cpp, line 112.
// Stack dump:
// ...
// 1. Swift version 5.3-dev (LLVM f8bd914aadc2e7b, Swift ba9c433c81d51ea)
// 2. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
// 3. While generating SIL witness table protocol conformance to 'SR_13305_Protocol' (at sr-13305.swift:7:1) for type 'SR_13305_Struct' (declared at [sr-13305.swift:12:1 - line:17:1] RangeText="struct SR_13305_Struct: SR_13305_Protocol {
// @differentiable(reverse, wrt: x)
// func method(x: Float, y: inout Float) {
// y = y * x
// }
// ")
// 4. While generating protocol witness thunk SIL function "@AD__$s4main15SR_13305_StructVAA0B15_13305_ProtocolA2aDP6method1x1yySf_SfztFTW_jvp_SUU".
// for 'method(x:y:)' (at sr-13305.swift:14:3)
// 5. While emitting reabstraction thunk in SIL function "@$sSfIegy_S2fIegyd_TR".
// ...
// 7 swift-frontend 0x0000000100fe80ad swift::SILResultInfo const& claimNext<swift::SILResultInfo>(llvm::ArrayRef<swift::SILResultInfo>&) + 93
// 8 swift-frontend 0x0000000100fe6cc0 (anonymous namespace)::ResultPlanner::claimNextInnerResult((anonymous namespace)::ResultPlanner::PlanData&) + 32