From 11551e13d0da769be9d387054153679921f16d91 Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Sun, 22 Mar 2020 21:30:33 -0700 Subject: [PATCH] [AutoDiff] NFC: formatting. (#30573) Run `clang-format` on changes in https://github.com/apple/swift/pull/30564. --- include/swift/AST/AutoDiff.h | 4 +-- include/swift/SIL/SILDeclRef.h | 53 +++++++++++++++------------------- lib/AST/AutoDiff.cpp | 10 +++---- lib/ParseSIL/ParseSIL.cpp | 4 +-- lib/SIL/SILDeclRef.cpp | 17 ++++------- lib/SIL/SILFunctionType.cpp | 4 +-- 6 files changed, 40 insertions(+), 52 deletions(-) diff --git a/include/swift/AST/AutoDiff.h b/include/swift/AST/AutoDiff.h index a52eea5bbeaaa..a0ec63684162b 100644 --- a/include/swift/AST/AutoDiff.h +++ b/include/swift/AST/AutoDiff.h @@ -90,9 +90,7 @@ class AutoDiffDerivativeFunctionIdentifier : public llvm::FoldingSetNode { public: AutoDiffDerivativeFunctionKind getKind() const { return kind; } - IndexSubset *getParameterIndices() const { - return parameterIndices; - } + IndexSubset *getParameterIndices() const { return parameterIndices; } GenericSignature getDerivativeGenericSignature() const { return derivativeGenericSignature; } diff --git a/include/swift/SIL/SILDeclRef.h b/include/swift/SIL/SILDeclRef.h index 778f7e99aa36b..4487fa4d8ef5d 100644 --- a/include/swift/SIL/SILDeclRef.h +++ b/include/swift/SIL/SILDeclRef.h @@ -150,16 +150,17 @@ struct SILDeclRef { unsigned defaultArgIndex : 10; /// The derivative function identifier. AutoDiffDerivativeFunctionIdentifier *derivativeFunctionIdentifier = nullptr; - + /// Produces a null SILDeclRef. - SILDeclRef() : loc(), kind(Kind::Func), isForeign(0), defaultArgIndex(0), - derivativeFunctionIdentifier(nullptr) {} - + SILDeclRef() + : loc(), kind(Kind::Func), isForeign(0), defaultArgIndex(0), + derivativeFunctionIdentifier(nullptr) {} + /// Produces a SILDeclRef of the given kind for the given decl. - explicit SILDeclRef(ValueDecl *decl, Kind kind, - bool isForeign = false, - AutoDiffDerivativeFunctionIdentifier *derivativeId = nullptr); - + explicit SILDeclRef( + ValueDecl *decl, Kind kind, bool isForeign = false, + AutoDiffDerivativeFunctionIdentifier *derivativeId = nullptr); + /// Produces a SILDeclRef for the given ValueDecl or /// AbstractClosureExpr: /// - If 'loc' is a func or closure, this returns a Func SILDeclRef. @@ -283,11 +284,10 @@ struct SILDeclRef { } bool operator==(SILDeclRef rhs) const { - return loc.getOpaqueValue() == rhs.loc.getOpaqueValue() - && kind == rhs.kind - && isForeign == rhs.isForeign - && defaultArgIndex == rhs.defaultArgIndex - && derivativeFunctionIdentifier == rhs.derivativeFunctionIdentifier; + return loc.getOpaqueValue() == rhs.loc.getOpaqueValue() && + kind == rhs.kind && isForeign == rhs.isForeign && + defaultArgIndex == rhs.defaultArgIndex && + derivativeFunctionIdentifier == rhs.derivativeFunctionIdentifier; } bool operator!=(SILDeclRef rhs) const { return !(*this == rhs); @@ -301,8 +301,8 @@ struct SILDeclRef { /// Returns the foreign (or native) entry point corresponding to the same /// decl. SILDeclRef asForeign(bool foreign = true) const { - return SILDeclRef(loc.getOpaqueValue(), kind, - foreign, defaultArgIndex, derivativeFunctionIdentifier); + return SILDeclRef(loc.getOpaqueValue(), kind, foreign, defaultArgIndex, + derivativeFunctionIdentifier); } /// Returns the entry point for the corresponding autodiff derivative @@ -400,16 +400,12 @@ struct SILDeclRef { private: friend struct llvm::DenseMapInfo; /// Produces a SILDeclRef from an opaque value. - explicit SILDeclRef(void *opaqueLoc, - Kind kind, - bool isForeign, + explicit SILDeclRef(void *opaqueLoc, Kind kind, bool isForeign, unsigned defaultArgIndex, AutoDiffDerivativeFunctionIdentifier *derivativeId) - : loc(Loc::getFromOpaqueValue(opaqueLoc)), kind(kind), - isForeign(isForeign), defaultArgIndex(defaultArgIndex), - derivativeFunctionIdentifier(derivativeId) - {} - + : loc(Loc::getFromOpaqueValue(opaqueLoc)), kind(kind), + isForeign(isForeign), defaultArgIndex(defaultArgIndex), + derivativeFunctionIdentifier(derivativeId) {} }; inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SILDeclRef C) { @@ -430,12 +426,12 @@ template<> struct DenseMapInfo { using UnsignedInfo = DenseMapInfo; static SILDeclRef getEmptyKey() { - return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func, - false, 0, nullptr); + return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func, false, 0, + nullptr); } static SILDeclRef getTombstoneKey() { - return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func, - false, 0, nullptr); + return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func, false, 0, + nullptr); } static unsigned getHashValue(swift::SILDeclRef Val) { unsigned h1 = PointerInfo::getHashValue(Val.loc.getOpaqueValue()); @@ -444,8 +440,7 @@ template<> struct DenseMapInfo { ? UnsignedInfo::getHashValue(Val.defaultArgIndex) : 0; unsigned h4 = UnsignedInfo::getHashValue(Val.isForeign); - unsigned h5 = - PointerInfo::getHashValue(Val.derivativeFunctionIdentifier); + unsigned h5 = PointerInfo::getHashValue(Val.derivativeFunctionIdentifier); return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7) ^ (h5 << 11); } static bool isEqual(swift::SILDeclRef const &LHS, diff --git a/lib/AST/AutoDiff.cpp b/lib/AST/AutoDiff.cpp index 43d4ee9cd56a1..c806382b65d31 100644 --- a/lib/AST/AutoDiff.cpp +++ b/lib/AST/AutoDiff.cpp @@ -19,11 +19,11 @@ using namespace swift; -AutoDiffDerivativeFunctionKind:: -AutoDiffDerivativeFunctionKind(StringRef string) { - Optional result = - llvm::StringSwitch>(string) - .Case("jvp", JVP).Case("vjp", VJP); +AutoDiffDerivativeFunctionKind::AutoDiffDerivativeFunctionKind( + StringRef string) { + Optional result = llvm::StringSwitch>(string) + .Case("jvp", JVP) + .Case("vjp", VJP); assert(result && "Invalid string"); rawValue = *result; } diff --git a/lib/ParseSIL/ParseSIL.cpp b/lib/ParseSIL/ParseSIL.cpp index ba2e3855ac7b2..2bc8370406fee 100644 --- a/lib/ParseSIL/ParseSIL.cpp +++ b/lib/ParseSIL/ParseSIL.cpp @@ -1456,8 +1456,8 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Result, return true; } // Parse parameter indices. - parameterIndices = IndexSubset::getFromString( - SILMod.getASTContext(), P.Tok.getText()); + parameterIndices = + IndexSubset::getFromString(SILMod.getASTContext(), P.Tok.getText()); if (!parameterIndices) { P.diagnose(P.Tok, diag::invalid_index_subset); return true; diff --git a/lib/SIL/SILDeclRef.cpp b/lib/SIL/SILDeclRef.cpp index 873e0ac9c0234..18c3d1d71ffb1 100644 --- a/lib/SIL/SILDeclRef.cpp +++ b/lib/SIL/SILDeclRef.cpp @@ -113,16 +113,13 @@ bool swift::requiresForeignEntryPoint(ValueDecl *vd) { return false; } -SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind, - bool isForeign, +SILDeclRef::SILDeclRef(ValueDecl *vd, SILDeclRef::Kind kind, bool isForeign, AutoDiffDerivativeFunctionIdentifier *derivativeId) - : loc(vd), kind(kind), isForeign(isForeign), defaultArgIndex(0), - derivativeFunctionIdentifier(derivativeId) -{} + : loc(vd), kind(kind), isForeign(isForeign), defaultArgIndex(0), + derivativeFunctionIdentifier(derivativeId) {} -SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc, bool asForeign) - : defaultArgIndex(0), derivativeFunctionIdentifier(nullptr) -{ +SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc, bool asForeign) + : defaultArgIndex(0), derivativeFunctionIdentifier(nullptr) { if (auto *vd = baseLoc.dyn_cast()) { if (auto *fd = dyn_cast(vd)) { // Map FuncDecls directly to Func SILDeclRefs. @@ -900,7 +897,7 @@ SILDeclRef SILDeclRef::getNextOverriddenVTableEntry() const { return SILDeclRef(); // JVPs/VJPs are overridden only if the base declaration has a - // `@differentiable` with the same parameter indices. + // `@differentiable` attribute with the same parameter indices. if (derivativeFunctionIdentifier) { auto overriddenAttrs = overridden.getDecl()->getAttrs().getAttributes(); @@ -908,8 +905,6 @@ SILDeclRef SILDeclRef::getNextOverriddenVTableEntry() const { if (attr->getParameterIndices() != derivativeFunctionIdentifier->getParameterIndices()) continue; - - // TODO(TF-1056): Do we need to check generic signature requirements? auto *overriddenDerivativeId = overridden.derivativeFunctionIdentifier; overridden.derivativeFunctionIdentifier = AutoDiffDerivativeFunctionIdentifier::get( diff --git a/lib/SIL/SILFunctionType.cpp b/lib/SIL/SILFunctionType.cpp index b5e2f8e7db259..e1462d789dfda 100644 --- a/lib/SIL/SILFunctionType.cpp +++ b/lib/SIL/SILFunctionType.cpp @@ -3115,8 +3115,8 @@ TypeConverter::getConstantInfo(TypeExpansionContext expansion, auto *loweredIndices = autodiff::getLoweredParameterIndices( derivativeId->getParameterIndices(), formalInterfaceType); silFnType = origFnConstantInfo.SILFnType->getAutoDiffDerivativeFunctionType( - loweredIndices, /*resultIndex*/ 0, derivativeId->getKind(), - *this, LookUpConformanceInModule(&M)); + loweredIndices, /*resultIndex*/ 0, derivativeId->getKind(), *this, + LookUpConformanceInModule(&M)); } LLVM_DEBUG(llvm::dbgs() << "lowering type for constant ";