You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AutoDiff] Fix differentiation for non-wrt inout parameters. (#33304)
Fix SIL differential function type calculation to handle non-wrt `inout`
parameters.
Patch `SILFunctionType::getDifferentiabilityResultIndices` to prevent returning
empty result indices for `@differentiable` function types with no formal results
where all `inout` parameters are `@noDerivative`. TF-1305 tracks a robust fix.
Resolves SR-13305.
Exposes TF-1305: parameter/result differentiability hole for `inout` parameters.
// SR-13305: Test protocol witness thunk for `@differentiable` protocol
7
+
// requirement, where the required method has a non-wrt `inout` parameter
8
+
// that should be treated as a differentiability result.
9
+
10
+
protocolSR_13305_Protocol{
11
+
@differentiable(wrt: x)
12
+
func method(x:Float, y:inoutFloat)
13
+
}
14
+
15
+
structSR_13305_Struct:SR_13305_Protocol{
16
+
@differentiable(wrt: x)
17
+
func method(x:Float, y:inoutFloat){
18
+
y = y * x
19
+
}
20
+
}
21
+
22
+
// Original crash:
23
+
// Assertion failed: (!array.empty() && "claiming next from empty array!"), function claimNext, file /Users/danielzheng/swift-build/swift/lib/SILGen/SILGenPoly.cpp, line 112.
24
+
// Stack dump:
25
+
// ...
26
+
// 1. Swift version 5.3-dev (LLVM f8bd914aadc2e7b, Swift ba9c433c81d51ea)
27
+
// 2. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
28
+
// 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 {
29
+
// @differentiable(wrt: x)
30
+
// func method(x: Float, y: inout Float) {
31
+
// y = y * x
32
+
// }
33
+
// ")
34
+
// 4. While generating protocol witness thunk SIL function "@AD__$s4main15SR_13305_StructVAA0B15_13305_ProtocolA2aDP6method1x1yySf_SfztFTW_jvp_SUU".
35
+
// for 'method(x:y:)' (at sr-13305.swift:14:3)
36
+
// 5. While emitting reabstraction thunk in SIL function "@$sSfIegy_S2fIegyd_TR".
0 commit comments