@@ -65,10 +65,9 @@ public protocol Differentiable {
6565  /// All differentiable variables of this value.
6666  var  allDifferentiableVariables :  AllDifferentiableVariables  {  get  set  } 
6767
68-   /// Returns `self` moved along the value space towards the given tangent
69-   /// vector. In Riemannian geometry (mathematics), this represents an
70-   /// exponential map.
71-   func  moved( along direction:  TangentVector )  ->  Self 
68+   /// Moves `self` along the value space towards the given tangent vector. In
69+   /// Riemannian geometry (mathematics), this represents an exponential map.
70+   mutating  func  move( along direction:  TangentVector ) 
7271
7372  @available ( * ,  deprecated,  
7473             message:  " 'CotangentVector' is now equal to 'TangentVector' and will be removed " )  
@@ -82,13 +81,9 @@ public extension Differentiable where AllDifferentiableVariables == Self {
8281  } 
8382} 
8483
85- // FIXME: The `Self : AdditiveArithmetic` constraint should be implied by
86- // `TangentVector == Self`, but the type checker errors out when it does not
87- // exist.
88- public  extension  Differentiable 
89-   where  TangentVector ==  Self ,  Self :  AdditiveArithmetic  { 
90-   func  moved( along direction:  TangentVector )  ->  Self  { 
91-     return  self  +  direction
84+ public  extension  Differentiable  where  TangentVector ==  Self  { 
85+   mutating  func  move( along direction:  TangentVector )  { 
86+     self  +=  direction
9287  } 
9388} 
9489
@@ -451,7 +446,7 @@ internal protocol _AnyDerivativeBox {
451446
452447  // `Differentiable` requirements.
453448  var  _allDifferentiableVariables :  _AnyDerivativeBox  {  get  } 
454-   func  _moved ( along direction:  _AnyDerivativeBox )   ->   _AnyDerivativeBox 
449+   mutating   func  _move ( along direction:  _AnyDerivativeBox ) 
455450
456451  /// The underlying base value, type-erased to `Any`.
457452  var  _typeErasedBase :  Any  {  get  } 
@@ -555,18 +550,17 @@ internal struct _ConcreteDerivativeBox<T> : _AnyDerivativeBox
555550    return  _ConcreteDerivativeBox ( _base. allDifferentiableVariables) 
556551  } 
557552
558-   func  _moved( along direction:  _AnyDerivativeBox )  ->  _AnyDerivativeBox  { 
559-     if  _isOpaqueZero ( )  { 
560-       return  direction
561-     } 
553+   mutating  func  _move( along direction:  _AnyDerivativeBox )  { 
562554    if  direction. _isOpaqueZero ( )  { 
563-       return   self 
555+       return 
564556    } 
557+     // The case where `self._isOpaqueZero()` returns true is handled in
558+     // `AnyDerivative.move(along:)`.
565559    guard  let  directionBase = 
566560      direction. _unboxed ( to:  T . TangentVector. self)  else  { 
567561      _derivativeTypeMismatch ( T . self,  type ( of:  direction. _typeErasedBase) ) 
568562    } 
569-     return   _ConcreteDerivativeBox < T > ( _base. moved ( along:  directionBase) ) 
563+     _base. move ( along:  directionBase) 
570564  } 
571565} 
572566
@@ -661,7 +655,11 @@ public struct AnyDerivative : Differentiable & AdditiveArithmetic {
661655    get  {  return  AnyDerivative ( _box:  _box. _allDifferentiableVariables)  } 
662656    // set { _box._allDifferentiableVariables = newValue._box }
663657  } 
664-   public  func  moved( along direction:  TangentVector )  ->  AnyDerivative  { 
665-     return  AnyDerivative ( _box:  _box. _moved ( along:  direction. _box) ) 
658+   public  mutating  func  move( along direction:  TangentVector )  { 
659+     if  _box. _isOpaqueZero ( )  { 
660+       _box =  direction. _box
661+       return 
662+     } 
663+     _box. _move ( along:  direction. _box) 
666664  } 
667665} 
0 commit comments