Skip to content

Commit dd95257

Browse files
authored
Merge pull request swiftlang#58418 from philipturner/patch-35
[AutoDiff][RequirementMachine] Regression test for S4TF RNN/Sequential crasher caused by GenericSignatureBuilder
2 parents 186afa5 + 61a3524 commit dd95257

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %target-swift-frontend -emit-sil -verify %s
2+
3+
// SR-15884: Crash while compiling Swift for TensorFlow. This was caused by a
4+
// bug in GenericSignatureBuilder, similar to one involving `CaseIterable`. In
5+
// this reproducer, `KeyPathIterabe` is similar enough to `CaseIterable` to
6+
// cause the GSB crash. It was fixed by RequirementMachine abstract signatures.
7+
8+
import _Differentiation
9+
@_spi(Reflection) import Swift
10+
11+
struct RNNCellInput<Input>: Differentiable {}
12+
struct RNNCellOutput<Output>: Differentiable {}
13+
14+
protocol Layer: Differentiable {
15+
associatedtype Input
16+
associatedtype Output: Differentiable
17+
18+
@differentiable(reverse)
19+
func callAsFunction(_ input: Input) -> Output
20+
}
21+
22+
public protocol KeyPathIterable {
23+
associatedtype AllKeyPaths: Sequence
24+
where AllKeyPaths.Element == PartialKeyPath<Self>
25+
}
26+
27+
protocol RecurrentLayerCell: Layer, KeyPathIterable
28+
where
29+
Input == RNNCellInput<TimeStepInput>,
30+
Output == RNNCellOutput<TimeStepOutput>
31+
{
32+
associatedtype TimeStepInput
33+
associatedtype TimeStepOutput: Differentiable
34+
}
35+
36+
struct RecurrentLayer<Cell: RecurrentLayerCell>: Layer {
37+
typealias Input = Cell.TimeStepInput
38+
typealias Output = Cell.TimeStepOutput
39+
40+
var cell: Cell
41+
42+
@differentiable(reverse)
43+
func callAsFunction(_ inputs: Cell.TimeStepInput) -> Cell.TimeStepOutput {
44+
// expected-warning @+1 {{function call causes an infinite recursion}}
45+
return self(inputs)
46+
}
47+
}

0 commit comments

Comments
 (0)