Skip to content

Conversation

dan-zheng
Copy link
Contributor

Support @differentiable class initializers in final classes.

  • Allow @differentiable and @derivative attributes for original initializers
    in final classes. Reject original initializers in non-final classes.
  • Add special logic in SILGenModule::getOrCreateCustomDerivativeThunk to
    thunk user-defined class initializer derivative functions to the expected
    derivative type for class initializers.

Also support differentiation for class-related casting instructions:
unchecked_ref_cast and upcast.

These instructions are generated when calling super.init or referencing
inherited superclass members.

Resolves SR-12151 and SR-12153.


Example:

class Super: Differentiable {
  var base: Float

  // Error: `Super` is non-final.
  @differentiable
  init(base: Float) {
    self.base = base
  }
}

final class Sub: Super {
  // No error: `Sub` is final.
  @differentiable
  override init(base: Float) {
    super.init(base: base)
  }
}
class.swift:5:4: error: '@differentiable' attribute cannot be declared on 'init' in a non-final class; consider making 'Super' final
  @differentiable
   ^

Support `@differentiable` class initializers in final classes.

- Allow `@differentiable` and `@derivative` attributes for original initializers
  in final classes. Reject original initializers in non-final classes.
- Add special logic in `SILGenModule::getOrCreateCustomDerivativeThunk` to
  thunk user-defined class initializer derivative functions to the expected
  derivative type for class initializers.

Also support differentiation for class-related casting instructions:
`unchecked_ref_cast` and `upcast`.

These instructions are generated when calling `super.init` or referencing
inherited superclass members.

Resolves SR-12151 and SR-12153.
@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Feb 11, 2020
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants