Skip to content

[AutoDiff] Fix semantic member accessor linear map structs. #31745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dan-zheng
Copy link
Contributor

@dan-zheng dan-zheng commented May 12, 2020

Ensure that semantic member accessors have empty linear map structs.
Semantic member accessor VJPs do not accumulate any callee pullbacks.

Resolves SR-12800: SIL verification error.


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() {
    // SR-1280: trigger semantic member accessor VJP/pullback generation.
    let _: @differentiable (Struct) -> Float = { $0.property }
  }
}

Before:

$ 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
...

After: no verification failure.

Ensure that semantic member accesors have empty linear map structs.
Semantic member accessor VJPs do not accumulate any callee pullbacks.

Resolves SR-12800: SIL verification error.
@dan-zheng dan-zheng requested review from rxwei and marcrasi May 12, 2020 23:57
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 50fb774

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 50fb774

@shahmishal
Copy link
Member

@swift-ci Please test

@dan-zheng dan-zheng merged commit d9c3a84 into swiftlang:master May 13, 2020
@dan-zheng dan-zheng deleted the wrapped-property-differentiation branch May 13, 2020 06:20
rxwei pushed a commit to rxwei/swift that referenced this pull request Jun 3, 2020
…g#31745)

Ensure that semantic member accesors have empty linear map structs.
Semantic member accessor VJPs do not accumulate any callee pullbacks.

Resolves SR-12800: SIL verification error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants