Skip to content

[SR-12800] Wrapped property differentiation: IRGen crash due to non-empty linear map structs #55245

@dan-zheng

Description

@dan-zheng
Previous ID SR-12800
Radar None
Original Reporter @dan-zheng
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AutoDiff
Assignee @dan-zheng
Priority Medium

md5: 0c2d275ba92022931bf6172ebda026b7

Issue Description:

import _Differentiation

@propertyWrapper
struct Wrapper<Value> {
  private var value: Value

  @differentiable(where Value: Differentiable)
  var wrappedValue: Value {
    get { value }
    set { value = newValue }
  }
}
extension Wrapper: Differentiable where Value: Differentiable {}

struct Struct: Differentiable {
  @Wrapper var property: Float

  static func testGetter() {
    let _: @differentiable (Struct) -> Float = { $0.property }
  }
}
$ swift test.swift
SIL verification failed: number of struct operands does not match number of stored member variables of struct: opi != opEnd
Verifying instruction:
->   %15 = struct $_AD__$s4test6StructV8propertySfvg_bb0__PB__src_0_wrt_0 () // user: %17
     %17 = partial_apply [callee_guaranteed] %16(%15) : $@convention(method) (Float, @owned _AD__$s4test6StructV8propertySfvg_bb0__PB__src_0_wrt_0) -> Struct.TangentVector // user: %18
In function:
// AD__$s4test6StructV8propertySfvg__vjp_src_0_wrt_0
sil private [ossa] @AD__$s4test6StructV8propertySfvg__vjp_src_0_wrt_0 : $@convention(method) (Struct) -> (Float, @owned @callee_guaranteed (Float) -> Struct.TangentVector) {
// %0                                             // users: %2, %1
bb0(%0 : $Struct):
  debug_value %0 : $Struct, let, name "self", argno 1 // id: %1
  %2 = struct_extract %0 : $Struct, #Struct._property // user: %4
  %3 = alloc_stack $Wrapper<Float>                // users: %14, %5, %4
  store %2 to [trivial] %3 : $*Wrapper<Float>     // id: %4
  %5 = load [trivial] %3 : $*Wrapper<Float>       // user: %8
  %6 = alloc_stack $Float                         // users: %13, %12, %10
  %7 = alloc_stack $Wrapper<Float>                // users: %11, %10, %8
  store %5 to [trivial] %7 : $*Wrapper<Float>     // id: %8
  // function_ref Wrapper.wrappedValue.getter
  %9 = function_ref @$s4test7WrapperV12wrappedValuexvg : $@convention(method) <τ_0_0> (@in_guaranteed Wrapper<τ_0_0>) -> @out τ_0_0 // user: %10
  %10 = apply %9<Float>(%6, %7) : $@convention(method) <τ_0_0> (@in_guaranteed Wrapper<τ_0_0>) -> @out τ_0_0
  dealloc_stack %7 : $*Wrapper<Float>             // id: %11
  %12 = load [trivial] %6 : $*Float               // user: %18
  dealloc_stack %6 : $*Float                      // id: %13
  dealloc_stack %3 : $*Wrapper<Float>             // id: %14
  %15 = struct $_AD__$s4test6StructV8propertySfvg_bb0__PB__src_0_wrt_0 () // user: %17
  // function_ref AD__$s4test6StructV8propertySfvg__pullback_src_0_wrt_0
  %16 = function_ref @AD__$s4test6StructV8propertySfvg__pullback_src_0_wrt_0 : $@convention(method) (Float, @owned _AD__$s4test6StructV8propertySfvg_bb0__PB__src_0_wrt_0) -> Struct.TangentVector // user: %17
  %17 = partial_apply [callee_guaranteed] %16(%15) : $@convention(method) (Float, @owned _AD__$s4test6StructV8propertySfvg_bb0__PB__src_0_wrt_0) -> Struct.TangentVector // user: %18
  %18 = tuple (%12 : $Float, %17 : $@callee_guaranteed (Float) -> Struct.TangentVector) // user: %19
  return %18 : $(Float, @callee_guaranteed (Float) -> Struct.TangentVector) // id: %19
} // end sil function 'AD__$s4test6StructV8propertySfvg__vjp_src_0_wrt_0'

Fix: linear map structs for semantic member accessors should be empty.

Metadata

Metadata

Assignees

Labels

AutoDiffbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions