34
34
35
35
using namespace swift ;
36
36
37
- // / Return true if `move(along :)` can be invoked on the given `Differentiable`-
37
+ // / Return true if `move(by :)` can be invoked on the given `Differentiable`-
38
38
// / conforming property.
39
39
// /
40
- // / If the given property is a `var`, return true because `move(along :)` can be
40
+ // / If the given property is a `var`, return true because `move(by :)` can be
41
41
// / invoked regardless. Otherwise, return true if and only if the property's
42
- // / type's 'Differentiable.move(along :)' witness is non-mutating.
42
+ // / type's 'Differentiable.move(by :)' witness is non-mutating.
43
43
static bool canInvokeMoveAlongOnProperty (
44
44
VarDecl *vd, ProtocolConformanceRef diffableConformance) {
45
45
assert (diffableConformance && " Property must conform to 'Differentiable'" );
46
- // `var` always supports `move(along :)` since it is mutable.
46
+ // `var` always supports `move(by :)` since it is mutable.
47
47
if (vd->getIntroducer () == VarDecl::Introducer::Var)
48
48
return true ;
49
49
// When the property is a `let`, the only case that would be supported is when
50
- // it has a `move(along :)` protocol requirement witness that is non-mutating.
50
+ // it has a `move(by :)` protocol requirement witness that is non-mutating.
51
51
auto interfaceType = vd->getInterfaceType ();
52
52
auto &C = vd->getASTContext ();
53
53
auto witness = diffableConformance.getWitnessByName (
54
- interfaceType, DeclName (C, C.Id_move , {C.Id_along }));
54
+ interfaceType, DeclName (C, C.Id_move , {C.Id_by }));
55
55
if (!witness)
56
56
return false ;
57
57
auto *decl = cast<FuncDecl>(witness.getDecl ());
@@ -70,7 +70,7 @@ getStoredPropertiesForDifferentiation(
70
70
for (auto *vd : nominal->getStoredProperties ()) {
71
71
// Peer through property wrappers: use original wrapped properties instead.
72
72
if (auto *originalProperty = vd->getOriginalWrappedProperty ()) {
73
- // Skip immutable wrapped properties. `mutating func move(along :)` cannot
73
+ // Skip immutable wrapped properties. `mutating func move(by :)` cannot
74
74
// be synthesized to update these properties.
75
75
if (!originalProperty->isSettable (DC))
76
76
continue ;
@@ -87,8 +87,8 @@ getStoredPropertiesForDifferentiation(
87
87
varType, diffableProto, nominal);
88
88
if (!conformance)
89
89
continue ;
90
- // Skip `let` stored properties with a mutating `move(along :)` if requested.
91
- // `mutating func move(along :)` cannot be synthesized to update `let`
90
+ // Skip `let` stored properties with a mutating `move(by :)` if requested.
91
+ // `mutating func move(by :)` cannot be synthesized to update `let`
92
92
// properties.
93
93
if (!includeLetPropertiesWithNonmutatingMoveAlong &&
94
94
!canInvokeMoveAlongOnProperty (vd, conformance))
@@ -214,14 +214,14 @@ bool DerivedConformance::canDeriveDifferentiable(NominalTypeDecl *nominal,
214
214
});
215
215
}
216
216
217
- // / Synthesize body for `move(along :)`.
217
+ // / Synthesize body for `move(by :)`.
218
218
static std::pair<BraceStmt *, bool >
219
219
deriveBodyDifferentiable_move (AbstractFunctionDecl *funcDecl, void *) {
220
220
auto &C = funcDecl->getASTContext ();
221
221
auto *parentDC = funcDecl->getParent ();
222
222
auto *nominal = parentDC->getSelfNominalTypeDecl ();
223
223
224
- // Get `Differentiable.move(along :)` protocol requirement.
224
+ // Get `Differentiable.move(by :)` protocol requirement.
225
225
auto *diffProto = C.getProtocol (KnownProtocolKind::Differentiable);
226
226
auto *requirement = getProtocolRequirement (diffProto, C.Id_move );
227
227
@@ -236,31 +236,31 @@ deriveBodyDifferentiable_move(AbstractFunctionDecl *funcDecl, void *) {
236
236
SmallVector<VarDecl *, 8 > diffProperties;
237
237
getStoredPropertiesForDifferentiation (nominal, parentDC, diffProperties);
238
238
239
- // Create call expression applying a member `move(along :)` method to a
240
- // parameter member: `self.<member>.move(along: direction .<member>)`.
239
+ // Create call expression applying a member `move(by :)` method to a
240
+ // parameter member: `self.<member>.move(by: offset .<member>)`.
241
241
auto createMemberMethodCallExpr = [&](VarDecl *member) -> Expr * {
242
242
auto *module = nominal->getModuleContext ();
243
243
auto memberType =
244
244
parentDC->mapTypeIntoContext (member->getValueInterfaceType ());
245
245
auto confRef = module ->lookupConformance (memberType, diffProto);
246
246
assert (confRef && " Member does not conform to `Differentiable`" );
247
247
248
- // Get member type's requirement witness: `<Member>.move(along :)`.
248
+ // Get member type's requirement witness: `<Member>.move(by :)`.
249
249
ValueDecl *memberWitnessDecl = requirement;
250
250
if (confRef.isConcrete ())
251
251
if (auto *witness = confRef.getConcrete ()->getWitnessDecl (requirement))
252
252
memberWitnessDecl = witness;
253
253
assert (memberWitnessDecl && " Member witness declaration must exist" );
254
254
255
- // Create reference to member method: `self.<member>.move(along :)`.
255
+ // Create reference to member method: `self.<member>.move(by :)`.
256
256
Expr *memberExpr =
257
257
new (C) MemberRefExpr (selfDRE, SourceLoc (), member, DeclNameLoc (),
258
258
/* Implicit*/ true );
259
259
auto *memberMethodExpr =
260
260
new (C) MemberRefExpr (memberExpr, SourceLoc (), memberWitnessDecl,
261
261
DeclNameLoc (), /* Implicit*/ true );
262
262
263
- // Create reference to parameter member: `direction .<member>`.
263
+ // Create reference to parameter member: `offset .<member>`.
264
264
VarDecl *paramMember = nullptr ;
265
265
auto *paramNominal = paramDecl->getType ()->getAnyNominal ();
266
266
assert (paramNominal && " Parameter should have a nominal type" );
@@ -275,12 +275,12 @@ deriveBodyDifferentiable_move(AbstractFunctionDecl *funcDecl, void *) {
275
275
auto *paramMemberExpr =
276
276
new (C) MemberRefExpr (paramDRE, SourceLoc (), paramMember, DeclNameLoc (),
277
277
/* Implicit*/ true );
278
- // Create expression: `self.<member>.move(along: direction .<member>)`.
278
+ // Create expression: `self.<member>.move(by: offset .<member>)`.
279
279
return CallExpr::createImplicit (C, memberMethodExpr, {paramMemberExpr},
280
- {C.Id_along });
280
+ {C.Id_by });
281
281
};
282
282
283
- // Collect member `move(along :)` method call expressions.
283
+ // Collect member `move(by :)` method call expressions.
284
284
SmallVector<ASTNode, 2 > memberMethodCallExprs;
285
285
SmallVector<Identifier, 2 > memberNames;
286
286
for (auto *member : diffProperties) {
@@ -326,14 +326,14 @@ static ValueDecl *deriveDifferentiable_method(
326
326
return funcDecl;
327
327
}
328
328
329
- // / Synthesize the `move(along :)` function declaration.
329
+ // / Synthesize the `move(by :)` function declaration.
330
330
static ValueDecl *deriveDifferentiable_move (DerivedConformance &derived) {
331
331
auto &C = derived.Context ;
332
332
auto *parentDC = derived.getConformanceContext ();
333
333
auto tangentType =
334
334
getTangentVectorInterfaceType (parentDC->getSelfTypeInContext (), parentDC);
335
335
return deriveDifferentiable_method (
336
- derived, C.Id_move , C.Id_along , C.Id_direction , tangentType,
336
+ derived, C.Id_move , C.Id_by , C.Id_offset , tangentType,
337
337
C.TheEmptyTupleType , {deriveBodyDifferentiable_move, nullptr });
338
338
}
339
339
@@ -561,7 +561,7 @@ static void checkAndDiagnoseImplicitNoDerivative(ASTContext &Context,
561
561
if (originalProperty->getAttrs ().hasAttribute <NoDerivativeAttr>())
562
562
continue ;
563
563
// Diagnose wrapped properties whose property wrappers do not define
564
- // `wrappedValue.set`. `mutating func move(along :)` cannot be synthesized
564
+ // `wrappedValue.set`. `mutating func move(by :)` cannot be synthesized
565
565
// to update these properties.
566
566
if (!originalProperty->isSettable (DC)) {
567
567
auto *wrapperDecl =
0 commit comments