|
| 1 | +// RUN: %target-build-swift %s |
| 2 | +// RUN: %target-swift-frontend -emit-sil -O -g %s | %FileCheck %s |
| 3 | + |
| 4 | +// Issue #58660: Specifically-shaped differentiable functions yield "conflicting debug info for argument" assertion failure |
| 5 | +// Ensure that proper location is preserved after sil-mem2reg location-less stores (created during inlining) |
| 6 | + |
| 7 | +import _Differentiation |
| 8 | + |
| 9 | +// May be a `struct` or `class`. |
| 10 | +class MyState: Differentiable { |
| 11 | + // All of these must be stored instance properties. There must be at least 7 |
| 12 | + // differentiable properties of any type. |
| 13 | + var property1: Float = 0 |
| 14 | + var property2: Float = 0 |
| 15 | + var property3: Float = 0 |
| 16 | + var property4: Float = 0 |
| 17 | + var property5: Float = 0 |
| 18 | + var property6: Float = 0 |
| 19 | + var property7: Float = 0 |
| 20 | +} |
| 21 | + |
| 22 | +struct MyModel: Differentiable { |
| 23 | + // May be `var` or `let`, but must not be `@noDerivative`. Must be a stored |
| 24 | + // instance property. |
| 25 | + let property1 = MyState() |
| 26 | + |
| 27 | + // Must be an instance property, either stored or computed. |
| 28 | + var property2: Float { |
| 29 | + // `get` must exist, and may add `mutating` attribute. |
| 30 | + get { 0 } |
| 31 | + // Cannot add `nonmutating` attribute to `set`. |
| 32 | + set { } |
| 33 | + } |
| 34 | + |
| 35 | + // Must be an instance member. May be a function or computed property, but not |
| 36 | + // a stored property. |
| 37 | + var member3: Float { |
| 38 | + // May not add `mutating` attribute. |
| 39 | + get { 0 } |
| 40 | + } |
| 41 | + |
| 42 | + @differentiable(reverse) |
| 43 | + mutating func member4() { |
| 44 | +// CHECK-LABEL: // pullback of MyModel.member4() |
| 45 | +// CHECK-NOT: debug_value %{{.*}} : $MyModel.TangentVector, var, name "self", argno 1, implicit, scope |
| 46 | +// CHECK: bb1(%{{.*}} : $_AD__$s4main7MyModelV7member4yyF_bb1__PB__src_0_wrt_0): |
| 47 | +// CHECK: debug_value %{{.*}} : $MyModel.TangentVector, var, name "self", argno 1, implicit, loc |
| 48 | + // Must be a differentiable type. |
| 49 | + var localVar: Float = 0 |
| 50 | + |
| 51 | + // Must be assigned from the value of `localVar`, not the value of anything else. |
| 52 | + property2 = localVar |
| 53 | + |
| 54 | + // `false` may instead be any expression that returns a `Bool`. |
| 55 | + if false { |
| 56 | + localVar = member3 |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments