Skip to content

Commit fe959f4

Browse files
committed
[AutoDiff] NFC: formatting.
Run `clang-format` on changes in #30564.
1 parent 723b2d2 commit fe959f4

File tree

6 files changed

+40
-52
lines changed

6 files changed

+40
-52
lines changed

include/swift/AST/AutoDiff.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ class AutoDiffDerivativeFunctionIdentifier : public llvm::FoldingSetNode {
9090

9191
public:
9292
AutoDiffDerivativeFunctionKind getKind() const { return kind; }
93-
IndexSubset *getParameterIndices() const {
94-
return parameterIndices;
95-
}
93+
IndexSubset *getParameterIndices() const { return parameterIndices; }
9694
GenericSignature getDerivativeGenericSignature() const {
9795
return derivativeGenericSignature;
9896
}

include/swift/SIL/SILDeclRef.h

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,17 @@ struct SILDeclRef {
150150
unsigned defaultArgIndex : 10;
151151
/// The derivative function identifier.
152152
AutoDiffDerivativeFunctionIdentifier *derivativeFunctionIdentifier = nullptr;
153-
153+
154154
/// Produces a null SILDeclRef.
155-
SILDeclRef() : loc(), kind(Kind::Func), isForeign(0), defaultArgIndex(0),
156-
derivativeFunctionIdentifier(nullptr) {}
157-
155+
SILDeclRef()
156+
: loc(), kind(Kind::Func), isForeign(0), defaultArgIndex(0),
157+
derivativeFunctionIdentifier(nullptr) {}
158+
158159
/// Produces a SILDeclRef of the given kind for the given decl.
159-
explicit SILDeclRef(ValueDecl *decl, Kind kind,
160-
bool isForeign = false,
161-
AutoDiffDerivativeFunctionIdentifier *derivativeId = nullptr);
162-
160+
explicit SILDeclRef(
161+
ValueDecl *decl, Kind kind, bool isForeign = false,
162+
AutoDiffDerivativeFunctionIdentifier *derivativeId = nullptr);
163+
163164
/// Produces a SILDeclRef for the given ValueDecl or
164165
/// AbstractClosureExpr:
165166
/// - If 'loc' is a func or closure, this returns a Func SILDeclRef.
@@ -283,11 +284,10 @@ struct SILDeclRef {
283284
}
284285

285286
bool operator==(SILDeclRef rhs) const {
286-
return loc.getOpaqueValue() == rhs.loc.getOpaqueValue()
287-
&& kind == rhs.kind
288-
&& isForeign == rhs.isForeign
289-
&& defaultArgIndex == rhs.defaultArgIndex
290-
&& derivativeFunctionIdentifier == rhs.derivativeFunctionIdentifier;
287+
return loc.getOpaqueValue() == rhs.loc.getOpaqueValue() &&
288+
kind == rhs.kind && isForeign == rhs.isForeign &&
289+
defaultArgIndex == rhs.defaultArgIndex &&
290+
derivativeFunctionIdentifier == rhs.derivativeFunctionIdentifier;
291291
}
292292
bool operator!=(SILDeclRef rhs) const {
293293
return !(*this == rhs);
@@ -301,8 +301,8 @@ struct SILDeclRef {
301301
/// Returns the foreign (or native) entry point corresponding to the same
302302
/// decl.
303303
SILDeclRef asForeign(bool foreign = true) const {
304-
return SILDeclRef(loc.getOpaqueValue(), kind,
305-
foreign, defaultArgIndex, derivativeFunctionIdentifier);
304+
return SILDeclRef(loc.getOpaqueValue(), kind, foreign, defaultArgIndex,
305+
derivativeFunctionIdentifier);
306306
}
307307

308308
/// Returns the entry point for the corresponding autodiff derivative
@@ -400,16 +400,12 @@ struct SILDeclRef {
400400
private:
401401
friend struct llvm::DenseMapInfo<swift::SILDeclRef>;
402402
/// Produces a SILDeclRef from an opaque value.
403-
explicit SILDeclRef(void *opaqueLoc,
404-
Kind kind,
405-
bool isForeign,
403+
explicit SILDeclRef(void *opaqueLoc, Kind kind, bool isForeign,
406404
unsigned defaultArgIndex,
407405
AutoDiffDerivativeFunctionIdentifier *derivativeId)
408-
: loc(Loc::getFromOpaqueValue(opaqueLoc)), kind(kind),
409-
isForeign(isForeign), defaultArgIndex(defaultArgIndex),
410-
derivativeFunctionIdentifier(derivativeId)
411-
{}
412-
406+
: loc(Loc::getFromOpaqueValue(opaqueLoc)), kind(kind),
407+
isForeign(isForeign), defaultArgIndex(defaultArgIndex),
408+
derivativeFunctionIdentifier(derivativeId) {}
413409
};
414410

415411
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SILDeclRef C) {
@@ -430,12 +426,12 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {
430426
using UnsignedInfo = DenseMapInfo<unsigned>;
431427

432428
static SILDeclRef getEmptyKey() {
433-
return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func,
434-
false, 0, nullptr);
429+
return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func, false, 0,
430+
nullptr);
435431
}
436432
static SILDeclRef getTombstoneKey() {
437-
return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func,
438-
false, 0, nullptr);
433+
return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func, false, 0,
434+
nullptr);
439435
}
440436
static unsigned getHashValue(swift::SILDeclRef Val) {
441437
unsigned h1 = PointerInfo::getHashValue(Val.loc.getOpaqueValue());
@@ -444,8 +440,7 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {
444440
? UnsignedInfo::getHashValue(Val.defaultArgIndex)
445441
: 0;
446442
unsigned h4 = UnsignedInfo::getHashValue(Val.isForeign);
447-
unsigned h5 =
448-
PointerInfo::getHashValue(Val.derivativeFunctionIdentifier);
443+
unsigned h5 = PointerInfo::getHashValue(Val.derivativeFunctionIdentifier);
449444
return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7) ^ (h5 << 11);
450445
}
451446
static bool isEqual(swift::SILDeclRef const &LHS,

lib/AST/AutoDiff.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
using namespace swift;
2121

22-
AutoDiffDerivativeFunctionKind::
23-
AutoDiffDerivativeFunctionKind(StringRef string) {
24-
Optional<innerty> result =
25-
llvm::StringSwitch<Optional<innerty>>(string)
26-
.Case("jvp", JVP).Case("vjp", VJP);
22+
AutoDiffDerivativeFunctionKind::AutoDiffDerivativeFunctionKind(
23+
StringRef string) {
24+
Optional<innerty> result = llvm::StringSwitch<Optional<innerty>>(string)
25+
.Case("jvp", JVP)
26+
.Case("vjp", VJP);
2727
assert(result && "Invalid string");
2828
rawValue = *result;
2929
}

lib/ParseSIL/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,8 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Result,
14561456
return true;
14571457
}
14581458
// Parse parameter indices.
1459-
parameterIndices = IndexSubset::getFromString(
1460-
SILMod.getASTContext(), P.Tok.getText());
1459+
parameterIndices =
1460+
IndexSubset::getFromString(SILMod.getASTContext(), P.Tok.getText());
14611461
if (!parameterIndices) {
14621462
P.diagnose(P.Tok, diag::invalid_index_subset);
14631463
return true;

lib/SIL/SILDeclRef.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,13 @@ bool swift::requiresForeignEntryPoint(ValueDecl *vd) {
113113
return false;
114114
}
115115

116-
SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind,
117-
bool isForeign,
116+
SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind, bool isForeign,
118117
AutoDiffDerivativeFunctionIdentifier *derivativeId)
119-
: loc(vd), kind(kind), isForeign(isForeign), defaultArgIndex(0),
120-
derivativeFunctionIdentifier(derivativeId)
121-
{}
118+
: loc(vd), kind(kind), isForeign(isForeign), defaultArgIndex(0),
119+
derivativeFunctionIdentifier(derivativeId) {}
122120

123-
SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc, bool asForeign)
124-
: defaultArgIndex(0), derivativeFunctionIdentifier(nullptr)
125-
{
121+
SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc, bool asForeign)
122+
: defaultArgIndex(0), derivativeFunctionIdentifier(nullptr) {
126123
if (auto *vd = baseLoc.dyn_cast<ValueDecl*>()) {
127124
if (auto *fd = dyn_cast<FuncDecl>(vd)) {
128125
// Map FuncDecls directly to Func SILDeclRefs.
@@ -900,16 +897,14 @@ SILDeclRef SILDeclRef::getNextOverriddenVTableEntry() const {
900897
return SILDeclRef();
901898

902899
// JVPs/VJPs are overridden only if the base declaration has a
903-
// `@differentiable` with the same parameter indices.
900+
// `@differentiable` attribute with the same parameter indices.
904901
if (derivativeFunctionIdentifier) {
905902
auto overriddenAttrs =
906903
overridden.getDecl()->getAttrs().getAttributes<DifferentiableAttr>();
907904
for (const auto *attr : overriddenAttrs) {
908905
if (attr->getParameterIndices() !=
909906
derivativeFunctionIdentifier->getParameterIndices())
910907
continue;
911-
912-
// TODO(TF-1056): Do we need to check generic signature requirements?
913908
auto *overriddenDerivativeId = overridden.derivativeFunctionIdentifier;
914909
overridden.derivativeFunctionIdentifier =
915910
AutoDiffDerivativeFunctionIdentifier::get(

lib/SIL/SILFunctionType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,8 +3115,8 @@ TypeConverter::getConstantInfo(TypeExpansionContext expansion,
31153115
auto *loweredIndices = autodiff::getLoweredParameterIndices(
31163116
derivativeId->getParameterIndices(), formalInterfaceType);
31173117
silFnType = origFnConstantInfo.SILFnType->getAutoDiffDerivativeFunctionType(
3118-
loweredIndices, /*resultIndex*/ 0, derivativeId->getKind(),
3119-
*this, LookUpConformanceInModule(&M));
3118+
loweredIndices, /*resultIndex*/ 0, derivativeId->getKind(), *this,
3119+
LookUpConformanceInModule(&M));
31203120
}
31213121

31223122
LLVM_DEBUG(llvm::dbgs() << "lowering type for constant ";

0 commit comments

Comments
 (0)