Skip to content
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

[SR-9788] [AD] Diagnostic-induced crasher: Incorrect differentiation invoker for @differentiable attribute #52213

Closed
rxwei opened this issue Jan 29, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow

Comments

@rxwei
Copy link
Member

rxwei commented Jan 29, 2019

Previous ID SR-9788
Radar None
Original Reporter @rxwei
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Swift for TensorFlow
Labels Bug
Assignee pschuh (JIRA)
Priority Medium

md5: 978ac7ab1664410bb2c846868c271d14

Issue Description:

When this differentiation task is registered, it should've been assigned the `DifferentiableAttribute` invoker. The current behavior is that it emits a non-differentiability note without emitting an error at the root invoker. This causes later passes to continue to run and end up crashing.

Here are some examples:

  1. Non-crashing but should've never passed compilation.
var a: Float = 0
enum T {
  @differentiable
  func foo(x: Float) -> Float {
    a = x
    a = a + x
    return a
  }
}
/Users/rxwei/Desktop/diffattrcrash.swift:13:12: note: expression is not differentiable
    return a
           ^

2. Crashing late passes when it's a protocol requirement.

protocol P {
  @differentiable
  func foo(x: Float) -> Float
}
var a: Float = 0
enum T : P {
  @differentiable
  func foo(x: Float) -> Float {
    a = x
    a = a + x
    return a
  }
}
swift git:(tensorflow) ✗ $SWIFT_XCODE_BUILD_PATH/bin/swiftc ~/Desktop/diffattrcrash.swift
/Users/rxwei/Desktop/diffattrcrash.swift:13:12: note: expression is not differentiable
    return a
           ^
Assertion failed: (it != FunctionOrder.end() && "no order number for SIL function definition?"), function getFunctionOrder, file /Users/rxwei/Development/Swift/swift-tf-source/swift/lib/IRGen/IRGenModule.h, line 397.
Stack dump:
...
@rxwei
Copy link
Member Author

rxwei commented Jan 29, 2019

There are two parts of the fix:

  1. Emit an error here at the function's declaration location as a fallback (we would normally expect things to have an AST node!). This makes sure even pure-SIL differentiation tests won't crash.
  2. Make sure we always get use invoker kind `DifferentiationAttribute` for `@differentiable` instead of `SILDifferentiableAttribute`.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow
Projects
None yet
Development

No branches or pull requests

1 participant