Skip to content

Commit 8635b90

Browse files
committed
Rename "associated function" to "derivative function".
1 parent 3fbd2bb commit 8635b90

File tree

14 files changed

+53
-53
lines changed

14 files changed

+53
-53
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ class ASTMangler : public Mangler {
155155
ModuleDecl *Module);
156156

157157
// SWIFT_ENABLE_TENSORFLOW
158-
// Mangle the autodiff associated function (JVP/VJP) with the given:
158+
// Mangle the derivative function (JVP/VJP) with the given:
159159
// - Mangled original function name.
160-
// - Associated function kind.
160+
// - Derivative function kind.
161161
// - Parameter/result indices.
162162
std::string mangleAutoDiffDerivativeFunctionHelper(
163163
StringRef name, AutoDiffDerivativeFunctionKind kind,

include/swift/AST/AutoDiff.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ struct AutoDiffLinearMapKind {
431431
operator innerty() const { return rawValue; }
432432
};
433433

434-
/// The kind of an associated function.
434+
/// The kind of an derivative function.
435435
struct AutoDiffDerivativeFunctionKind {
436436
enum innerty : uint8_t {
437437
// The Jacobian-vector products function.
@@ -452,7 +452,7 @@ struct AutoDiffDerivativeFunctionKind {
452452
};
453453

454454
/// In conjunction with the original function declaration, identifies an
455-
/// autodiff associated function.
455+
/// autodiff derivative function.
456456
///
457457
/// Is uniquely allocated within an ASTContext so that it can be hashed and
458458
/// compared by opaque pointer value.
@@ -523,7 +523,7 @@ bool getBuiltinAutoDiffApplyConfig(StringRef operationName,
523523
AutoDiffDerivativeFunctionKind &kind,
524524
unsigned &arity, bool &rethrows);
525525

526-
/// Computes the correct linkage for an associated function given the linkage of
526+
/// Computes the correct linkage for an derivative function given the linkage of
527527
/// the original function. If the original linkage is not external and
528528
/// `isDerivativeFnExported` is true, use the original function's linkage. Otherwise,
529529
/// return hidden linkage.

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,15 +1597,15 @@ ERROR(sil_inst_autodiff_attr_expected_rsquare,PointsToFirstBadToken,
15971597
ERROR(sil_inst_autodiff_expected_parameter_index,PointsToFirstBadToken,
15981598
"expected the index of a parameter to differentiate with respect to", ())
15991599
ERROR(sil_inst_autodiff_operand_list_expected_lbrace,PointsToFirstBadToken,
1600-
"expected '{' to start an associated function list", ())
1600+
"expected '{' to start an derivative function list", ())
16011601
ERROR(sil_inst_autodiff_operand_list_expected_comma,PointsToFirstBadToken,
1602-
"expected ',' between operands in an associated function list", ())
1602+
"expected ',' between operands in an derivative function list", ())
16031603
ERROR(sil_inst_autodiff_operand_list_expected_rbrace,PointsToFirstBadToken,
1604-
"expected '}' to start an associated function list", ())
1604+
"expected '}' to start an derivative function list", ())
16051605
ERROR(sil_inst_autodiff_num_operand_list_order_mismatch,PointsToFirstBadToken,
16061606
"the number of operand lists does not match the order", ())
16071607
ERROR(sil_inst_autodiff_expected_associated_function_kind_attr,PointsToFirstBadToken,
1608-
"expected an associated function kind attribute, e.g. '[jvp]'", ())
1608+
"expected an derivative function kind attribute, e.g. '[jvp]'", ())
16091609
ERROR(sil_inst_autodiff_expected_function_type_operand,PointsToFirstBadToken,
16101610
"expected an operand of a function type", ())
16111611

include/swift/AST/Types.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,10 +3100,10 @@ class AnyFunctionType : public TypeBase {
31003100

31013101
// SWIFT_ENABLE_TENSORFLOW
31023102
/// Given `indices` and `kind`, calculates the type of the corresponding
3103-
/// autodiff associated function.
3103+
/// autodiff derivative function.
31043104
///
31053105
/// By default, if the original type has a self parameter list and parameter
3106-
/// indices include self, the computed associated function type will return a
3106+
/// indices include self, the computed derivative function type will return a
31073107
/// linear map taking/returning self's tangent *last* instead of first, for
31083108
/// consistency with SIL.
31093109
///
@@ -3121,11 +3121,11 @@ class AnyFunctionType : public TypeBase {
31213121
GenericSignature *whereClauseGenericSignature = nullptr,
31223122
bool makeSelfParamFirst = false);
31233123

3124-
/// Given the type of an autodiff associated function, returns the
3124+
/// Given the type of an autodiff derivative function, returns the
31253125
/// corresponding original function type.
31263126
AnyFunctionType *getAutoDiffOriginalFunctionType();
31273127

3128-
/// Given the type of a transposing associated function, returns the
3128+
/// Given the type of a transposing derivative function, returns the
31293129
/// corresponding original function type.
31303130
AnyFunctionType *
31313131
getTransposeOriginalFunctionType(TransposingAttr *attr,

include/swift/SIL/SILDeclRef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct SILDeclRef {
157157

158158
// SWIFT_ENABLE_TENSORFLOW
159159
/// When this is non-null, it modifies the SILDeclRef to refer to the
160-
/// corresponding autodiff associated function.
160+
/// corresponding autodiff derivative function.
161161
AutoDiffDerivativeFunctionIdentifier *autoDiffDerivativeFunctionIdentifier;
162162

163163
/// Produces a null SILDeclRef.
@@ -363,7 +363,7 @@ struct SILDeclRef {
363363
}
364364

365365
/// Returns the entry point for the original function corresponding to an
366-
/// autodiff associated function.
366+
/// autodiff derivative function.
367367
SILDeclRef asAutoDiffOriginalFunction() const {
368368
assert(autoDiffDerivativeFunctionIdentifier);
369369
SILDeclRef r = *this;

include/swift/SILOptimizer/Analysis/BottomUpIPAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BottomUpIPAnalysis : public SILAnalysis {
4343
/// analysis information for a function.
4444
/// This base class stores the administrative information needed for
4545
/// invalidation and updating the analysis.
46-
/// In the following "this function" refers to the associated function.
46+
/// In the following "this function" refers to the derivative function.
4747
template<typename FunctionInfo> class FunctionInfoBase {
4848
public:
4949

lib/AST/Attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static void printDifferentiableAttrArguments(
520520
stream << diffParamsString;
521521
}
522522
}
523-
// Print associated function names, unless they are to be omitted.
523+
// Print derivative function names, unless they are to be omitted.
524524
if (!omitDerivativeFunctions) {
525525
// Print jvp function name, if specified.
526526
if (auto jvp = attr->getJVP()) {

lib/AST/Builtins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,14 @@ static ValueDecl *getAutoDiffApplyDerivativeFunction(
10351035
}
10361036
};
10371037
// Eagerly build the type of the first arg, then use that to compute the type
1038-
// of the associated function type.
1038+
// of the derivative function type.
10391039
auto *origFnTy =
10401040
firstArgGen.build(builder)->castTo<AnyFunctionType>();
10411041
origFnTy = origFnTy->getWithoutDifferentiability()->withExtInfo(
10421042
origFnTy->getExtInfo().withNoEscape(false));
10431043
auto *paramIndices = AutoDiffIndexSubset::get(
10441044
Context, SmallBitVector(origFnTy->getNumParams(), true));
1045-
// Generator for the resultant function type, i.e. the AD associated function.
1045+
// Generator for the resultant function type, i.e. the AD derivative function.
10461046
BuiltinGenericSignatureBuilder::LambdaGenerator resultGen{
10471047
[=, &Context](BuiltinGenericSignatureBuilder &builder) -> Type {
10481048
auto derivativeFnTy = origFnTy->getAutoDiffDerivativeFunctionType(

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4677,7 +4677,7 @@ AnyFunctionType *AnyFunctionType::getAutoDiffDerivativeFunctionType(
46774677
curryLevels.back(), curryLevels.back()->getParams(), retTy,
46784678
curryLevels.size() == 1 ? whereClauseGenSig : nullptr);
46794679

4680-
// Wrap the associated function type in additional curry levels.
4680+
// Wrap the derivative function type in additional curry levels.
46814681
auto curryLevelsWithoutLast =
46824682
ArrayRef<AnyFunctionType *>(curryLevels).drop_back(1);
46834683
for (auto pair : enumerate(reversed(curryLevelsWithoutLast))) {
@@ -4716,7 +4716,7 @@ AnyFunctionType::getAutoDiffOriginalFunctionType() {
47164716
curryLevels.back(), curryLevels.back()->getParams(), originalResult,
47174717
curryLevels.size() == 1 ? getOptGenericSignature() : nullptr);
47184718

4719-
// Wrap the associated function type in additional curry levels.
4719+
// Wrap the derivative function type in additional curry levels.
47204720
auto curryLevelsWithoutLast =
47214721
ArrayRef<AnyFunctionType *>(curryLevels).drop_back(1);
47224722
for (auto pair : enumerate(reversed(curryLevelsWithoutLast))) {

lib/ParseSIL/ParseSIL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,9 +2960,9 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
29602960
// Parse an optional operand list `with { <operand> , <operand> }`.
29612961
if (P.Tok.is(tok::identifier) && P.Tok.getText() == "with") {
29622962
P.consumeToken(tok::identifier);
2963-
// Parse associated function values as an operand list.
2963+
// Parse derivative function values as an operand list.
29642964
// FIXME(rxwei): Change this to *not* require a type signature once
2965-
// we can infer AD associated function types.
2965+
// we can infer derivative function types.
29662966
SILValue derivFn1, derivFn2;
29672967
if (P.parseToken(tok::l_brace,
29682968
diag::sil_inst_autodiff_operand_list_expected_lbrace) ||
@@ -3003,7 +3003,7 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
30033003
diag::sil_inst_autodiff_expected_associated_function_kind_attr) ||
30043004
P.parseToken(tok::r_square,
30053005
diag::sil_inst_autodiff_attr_expected_rsquare,
3006-
"associated function kind"))
3006+
"derivative function kind"))
30073007
return true;
30083008
if (parseTypedValueRef(functionOperand, B) ||
30093009
parseSILDebugLocation(InstLoc, B))

lib/SILGen/SILGen.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
148148
CanSILFunctionType constantTy);
149149

150150
// SWIFT_ENABLE_TENSORFLOW
151-
/// Get or create an autodiff associated function thunk for the given
152-
/// SILDeclRef, SILFunction, and associated function type.
151+
/// Get or create an autodiff derivative function thunk for the given
152+
/// SILDeclRef, SILFunction, and derivative function type.
153153
SILFunction *getOrCreateAutoDiffThunk(SILDeclRef derivativeFnRef,
154154
SILFunction *derivativeFn,
155155
CanSILFunctionType derivativeFnTy);
156156

157157
// SWIFT_ENABLE_TENSORFLOW
158-
/// Get or create an autodiff associated function vtable entry thunk for the
159-
/// given SILDeclRef and associated function type.
158+
/// Get or create an autodiff derivative function vtable entry thunk for the
159+
/// given SILDeclRef and derivative function type.
160160
SILFunction *
161161
getOrCreateAutoDiffClassMethodThunk(SILDeclRef derivativeFnRef,
162162
CanSILFunctionType derivativeFnTy);

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ static ManagedValue emitBuiltinAutoDiffApplyDerivativeFunction(
10401040
for (auto& arg : args.drop_front(1))
10411041
origFnArgVals.push_back(arg.getValue());
10421042

1043-
// Get the associated function.
1043+
// Get the derivative function.
10441044
SILValue derivativeFn = SGF.B.createDifferentiableFunctionExtract(
10451045
loc, kind, origFnVal);
10461046
auto derivativeFnType = derivativeFn->getType().castTo<SILFunctionType>();

lib/SILOptimizer/Mandatory/Differentiation.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ class ADContext {
878878
/// Saved for deletion during cleanup.
879879
SmallVector<SILFunction *, 32> generatedFunctions;
880880

881-
/// List of associated function references, generated via
881+
/// List of derivative function references, generated via
882882
/// `emitDerivativeFunctionReference`.
883883
/// Saved for deletion during cleanup.
884884
SmallVector<SILValue, 32> generatedDerivativeFunctionReferences;
@@ -1131,7 +1131,7 @@ class ADContext {
11311131
DifferentiationInvoker invoker);
11321132

11331133
/// Process the given `differentiable_function` instruction, filling in
1134-
/// missing associated functions if necessary.
1134+
/// missing derivative functions if necessary.
11351135
bool processDifferentiableFunctionInst(DifferentiableFunctionInst *dfi);
11361136

11371137
/// Fold `differentiable_function_extract` users of the given
@@ -1145,27 +1145,27 @@ class ADContext {
11451145
/// purposes.
11461146
void foldDifferentiableFunctionExtraction(DifferentiableFunctionInst *source);
11471147

1148-
/// Get or create an associated function index subset thunk from
1149-
/// `actualIndices` to `desiredIndices` for the given associated function
1148+
/// Get or create an derivative function index subset thunk from
1149+
/// `actualIndices` to `desiredIndices` for the given derivative function
11501150
/// value and original function operand.
11511151
/// Calls `getOrCreateSubsetParametersThunkForLinearMap` to thunk the linear
1152-
/// map returned by the associated function.
1152+
/// map returned by the derivative function.
11531153
std::pair<SILFunction *, SubstitutionMap>
11541154
getOrCreateSubsetParametersThunkForDerivativeFunction(
11551155
SILValue origFnOperand, SILValue assocFn,
11561156
AutoDiffDerivativeFunctionKind kind, SILAutoDiffIndices desiredIndices,
11571157
SILAutoDiffIndices actualIndices);
11581158

1159-
/// Get or create an associated function index subset thunk from
1160-
/// `actualIndices` to `desiredIndices` for the given associated function
1159+
/// Get or create an derivative function index subset thunk from
1160+
/// `actualIndices` to `desiredIndices` for the given derivative function
11611161
/// value and original function operand.
11621162
SILFunction *getOrCreateSubsetParametersThunkForLinearMap(
11631163
SILFunction *assocFn, CanSILFunctionType linearMapType,
11641164
CanSILFunctionType targetType, AutoDiffDerivativeFunctionKind kind,
11651165
SILAutoDiffIndices desiredIndices, SILAutoDiffIndices actualIndices);
11661166

11671167
public:
1168-
/// Declare an external reference to an associated function of `original`,
1168+
/// Declare an external reference to an derivative function of `original`,
11691169
/// given a `[differentiable]` attribute of `original` and the associated
11701170
/// function kind.
11711171
SILFunction *
@@ -1705,7 +1705,7 @@ void LinearMapInfo::generateDifferentiationDataStructures(
17051705
auto *loopAnalysis = context.getPassManager().getAnalysis<SILLoopAnalysis>();
17061706
auto *loopInfo = loopAnalysis->get(original);
17071707

1708-
// Get the associated function generic signature.
1708+
// Get the derivative function generic signature.
17091709
CanGenericSignature assocFnGenSig = nullptr;
17101710
if (auto *assocFnGenEnv = assocFn->getGenericEnvironment())
17111711
assocFnGenSig =
@@ -2530,9 +2530,9 @@ static SubstitutionMap getSubstitutionMap(
25302530
return substMap;
25312531
}
25322532

2533-
/// Emits a reference to an associated function of `original`, differentiated
2533+
/// Emits a reference to an derivative function of `original`, differentiated
25342534
/// with respect to a superset of `desiredIndices`. Returns the `SILValue` for
2535-
/// the associated function and the actual indices that the associated function
2535+
/// the derivative function and the actual indices that the derivative function
25362536
/// is with respect to.
25372537
///
25382538
/// Returns `None` on failure, signifying that a diagnostic has been emitted.
@@ -2554,15 +2554,15 @@ emitDerivativeFunctionReference(
25542554

25552555
// If `original` is itself an `DifferentiableFunctionExtractInst` whose kind matches
25562556
// the given kind and desired differentiation parameter indices, simply
2557-
// extract the associated function of its function operand, retain the
2558-
// associated function, and return it.
2557+
// extract the derivative function of its function operand, retain the
2558+
// derivative function, and return it.
25592559
if (auto *inst = original->getDefiningInstruction())
25602560
if (auto *dfei = dyn_cast<DifferentiableFunctionExtractInst>(inst))
25612561
if (dfei->getExtractee() == DifferentiableFunctionExtractee::Original)
25622562
functionSource = dfei->getFunctionOperand();
25632563

25642564
// If `functionSource` is a `@differentiable` function, just extract the
2565-
// associated function.
2565+
// derivative function.
25662566
if (auto diffableFnType =
25672567
functionSource->getType().castTo<SILFunctionType>()) {
25682568
if (diffableFnType->isDifferentiable()) {
@@ -2711,7 +2711,7 @@ emitDerivativeFunctionReference(
27112711
diag::autodiff_member_subset_indices_not_differentiable);
27122712
return None;
27132713
}
2714-
// Emit a `witness_method` instruction for the associated function.
2714+
// Emit a `witness_method` instruction for the derivative function.
27152715
auto originalType = witnessMethod->getType().castTo<SILFunctionType>();
27162716
auto assocType = originalType->getAutoDiffDerivativeFunctionType(
27172717
minimalIndices.parameters, minimalIndices.source,
@@ -2758,7 +2758,7 @@ emitDerivativeFunctionReference(
27582758
diag::autodiff_member_subset_indices_not_differentiable);
27592759
return None;
27602760
}
2761-
// Emit a `class_method` instruction for the associated function.
2761+
// Emit a `class_method` instruction for the derivative function.
27622762
auto originalType = classMethodInst->getType().castTo<SILFunctionType>();
27632763
auto assocType = originalType->getAutoDiffDerivativeFunctionType(
27642764
minimalIndices.parameters, minimalIndices.source,
@@ -7980,7 +7980,7 @@ bool ADContext::processDifferentiableAttribute(
79807980
attr->setJVPName(jvpName);
79817981
}
79827982

7983-
// If differentiation is triggered by `[differentiable]`, associated function
7983+
// If differentiation is triggered by `[differentiable]`, derivative function
79847984
// should share linkage of original function.
79857985
auto isAssocFnExported =
79867986
invoker.getKind() ==
@@ -8334,7 +8334,7 @@ ADContext::getOrCreateSubsetParametersThunkForDerivativeFunction(
83348334
AutoDiffDerivativeFunctionKind kind, SILAutoDiffIndices desiredIndices,
83358335
SILAutoDiffIndices actualIndices) {
83368336
LLVM_DEBUG(getADDebugStream()
8337-
<< "Getting a subset parameters thunk for associated function "
8337+
<< "Getting a subset parameters thunk for derivative function "
83388338
<< assocFn << " of the original function " << origFnOperand
83398339
<< " from " << actualIndices << " to " << desiredIndices << '\n');
83408340

@@ -8441,7 +8441,7 @@ ADContext::getOrCreateSubsetParametersThunkForDerivativeFunction(
84418441
loc, classOperand, assocMethodInst->getMember(),
84428442
thunk->mapTypeIntoContext(assocMethodInst->getType()));
84438443
}
8444-
assert(assocRef && "Expected associated function to be resolved");
8444+
assert(assocRef && "Expected derivative function to be resolved");
84458445

84468446
assocSubstMap = assocSubstMap.subst(thunk->getForwardingSubstitutionMap());
84478447
assocFnType = assocRef->getType().castTo<SILFunctionType>();
@@ -8592,7 +8592,7 @@ SILValue ADContext::promoteToDifferentiableFunction(
85928592
getGeneratedDerivativeFunctionReferences().push_back(assocFn);
85938593

85948594
// If desired indices are a subset of actual indices, create a "subset
8595-
// indices thunk" and destroy the emitted associated function reference.
8595+
// indices thunk" and destroy the emitted derivative function reference.
85968596
// - For JVPs: the thunked JVP returns a differential taking fewer
85978597
// parameters (using `.zero` for the dropped parameters).
85988598
// - For VJPs: the thunked VJP returns a pullback that drops the unused
@@ -8606,7 +8606,7 @@ SILValue ADContext::promoteToDifferentiableFunction(
86068606
getASTContext(), actualIndices.parameters->getCapacity());
86078607
if (actualIndices.source != desiredIndices.source ||
86088608
!actualIndices.parameters->equals(extendedDesiredIndices)) {
8609-
// Destroy the already emitted associated function reference because it
8609+
// Destroy the already emitted derivative function reference because it
86108610
// is no longer used.
86118611
builder.emitDestroyValueOperation(loc, assocFn);
86128612
// Check if underlying original function reference has been partially
@@ -8661,7 +8661,7 @@ SILValue ADContext::promoteToDifferentiableFunction(
86618661

86628662
assocFns.push_back(assocFn);
86638663
}
8664-
// Deallocate temporary buffers used for creating associated functions.
8664+
// Deallocate temporary buffers used for creating derivative functions.
86658665
for (auto *buf : reversed(newBuffersToDealloc))
86668666
builder.createDeallocStack(loc, buf);
86678667

@@ -8701,7 +8701,7 @@ void ADContext::foldDifferentiableFunctionExtraction(
87018701
dfei->eraseFromParent();
87028702
continue;
87038703
}
8704-
// Fold associated function extractors.
8704+
// Fold derivative function extractors.
87058705
auto assocFnValue =
87068706
source->getDerivativeFunction(dfei->getDerivativeFunctionKind());
87078707
dfei->replaceAllUsesWith(assocFnValue);

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ class VarDeclUsageChecker : public ASTWalker {
22482248
};
22492249

22502250
/// An AST walker that determines the underlying type of an opaque return decl
2251-
/// from its associated function body.
2251+
/// from its derivative function body.
22522252
class OpaqueUnderlyingTypeChecker : public ASTWalker {
22532253
TypeChecker &TC;
22542254
AbstractFunctionDecl *Implementation;

0 commit comments

Comments
 (0)