Skip to content

Commit ef832ce

Browse files
committed
Remove @transposing attribute.
`@transposing` attribute has no known users, so deleting it outright makes maintenance easier. Other assorted gardening included.
1 parent 959186f commit ef832ce

File tree

14 files changed

+42
-172
lines changed

14 files changed

+42
-172
lines changed

include/swift/AST/Attr.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,6 @@ DECL_ATTR(differentiating, Differentiating,
545545
OnFunc | LongAttribute | AllowMultipleAttributes |
546546
ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIBreakingToRemove |
547547
NotSerialized, 98)
548-
// TODO(TF-999): Remove deprecated `@transposing` attribute.
549-
DECL_ATTR(transposing, Transposing,
550-
OnFunc | LongAttribute | AllowMultipleAttributes |
551-
ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIBreakingToRemove |
552-
NotSerialized, 99)
553548
// SWIFT_ENABLE_TENSORFLOW END
554549

555550
#undef TYPE_ATTR

include/swift/AST/Attr.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ class TransposeAttr final
17601760
AbstractFunctionDecl *OriginalFunction = nullptr;
17611761
/// The number of parsed parameters specified in 'wrt:'.
17621762
unsigned NumParsedParameters = 0;
1763-
/// The differentiation parameters' indices, resolved by the type checker.
1763+
/// The transposed parameters' indices, resolved by the type checker.
17641764
IndexSubset *ParameterIndices = nullptr;
17651765

17661766
explicit TransposeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
@@ -1793,8 +1793,8 @@ class TransposeAttr final
17931793
OriginalFunction = decl;
17941794
}
17951795

1796-
/// The parsed transposing parameters, i.e. the list of parameters
1797-
/// specified in 'wrt:'.
1796+
/// The parsed transposed parameters, i.e. the list of parameters specified in
1797+
/// 'wrt:'.
17981798
ArrayRef<ParsedAutoDiffParameter> getParsedParameters() const {
17991799
return {getTrailingObjects<ParsedAutoDiffParameter>(), NumParsedParameters};
18001800
}
@@ -1817,9 +1817,6 @@ class TransposeAttr final
18171817
}
18181818
};
18191819

1820-
// TODO(TF-999): Remove deprecated `@transposing` attribute.
1821-
using TransposingAttr = TransposeAttr;
1822-
18231820
/// Relates a property to its projection value property, as described by a property wrapper. For
18241821
/// example, given
18251822
/// \code

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,12 +1577,9 @@ ERROR(attr_transpose_expected_original_name,PointsToFirstBadToken,
15771577
"expected an original function name", ())
15781578
ERROR(attr_transpose_expected_label_linear_or_wrt,none,
15791579
"expected 'wrt:'", ())
1580-
WARNING(attr_transposing_deprecated,PointsToFirstBadToken,
1581-
"'@transposing' attribute is deprecated; use '@transpose(of:)' instead",
1582-
())
15831580

1584-
// transposing `wrt` parameters clause
1585-
ERROR(transposing_params_clause_expected_parameter,PointsToFirstBadToken,
1581+
// transpose `wrt` parameters clause
1582+
ERROR(transpose_params_clause_expected_parameter,PointsToFirstBadToken,
15861583
"expected a parameter, which can be a 'unsigned int' parameter number "
15871584
"or 'self'", ())
15881585

include/swift/Parse/Parser.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -996,13 +996,10 @@ class Parser {
996996
Optional<DeclNameWithLoc> &jvpSpec, Optional<DeclNameWithLoc> &vjpSpec,
997997
TrailingWhereClause *&whereClause);
998998

999-
/// Parse a differentiation parameters clause.
999+
/// Parse a differentiation parameters clause, i.e. the "wrt:" clause in
1000+
/// @differentiable and @derivative attributes.
10001001
bool parseDifferentiationParametersClause(
10011002
SmallVectorImpl<ParsedAutoDiffParameter> &params, StringRef attrName);
1002-
1003-
/// Parse a transposing parameters clause.
1004-
bool parseTransposingParametersClause(
1005-
SmallVectorImpl<ParsedAutoDiffParameter> &params, StringRef attrName);
10061003

10071004
/// Parse the @derivative attribute.
10081005
ParserResult<DerivativeAttr> parseDerivativeAttribute(SourceLoc AtLoc,
@@ -1013,15 +1010,15 @@ class Parser {
10131010
ParserResult<DerivativeAttr> parseDifferentiatingAttribute(SourceLoc AtLoc,
10141011
SourceLoc Loc);
10151012

1013+
/// Parse a transposed parameters clause, i.e. the "wrt:" clause in @transpose
1014+
/// attributes.
1015+
bool parseTransposedParametersClause(
1016+
SmallVectorImpl<ParsedAutoDiffParameter> &params, StringRef attrName);
1017+
10161018
/// Parse the @transpose attribute.
10171019
ParserResult<TransposeAttr> parseTransposeAttribute(SourceLoc AtLoc,
10181020
SourceLoc Loc);
10191021

1020-
/// Parse the deprecated @transposing attribute.
1021-
// TODO(TF-999): Remove the deprecated `@transposing` attribute.
1022-
ParserResult<TransposeAttr> parseTransposingAttribute(SourceLoc AtLoc,
1023-
SourceLoc Loc);
1024-
10251022
/// Parse the @quoted attribute.
10261023
ParserResult<QuotedAttr> parseQuotedAttribute(SourceLoc AtLoc, SourceLoc Loc);
10271024

lib/AST/Attr.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,10 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
936936
}
937937

938938
// SWIFT_ENABLE_TENSORFLOW
939-
case DAK_Transposing: {
940-
Printer.printAttrName("@transposing");
939+
case DAK_Transpose: {
940+
Printer.printAttrName("@transpose");
941941
Printer << '(';
942-
auto *attr = cast<TransposingAttr>(this);
942+
auto *attr = cast<TransposeAttr>(this);
943943
auto *transpose = cast<AbstractFunctionDecl>(D);
944944
Printer << attr->getOriginalFunctionName().Name;
945945
auto transParamsString = getTransposedParametersClauseString(
@@ -1114,10 +1114,9 @@ StringRef DeclAttribute::getAttrName() const {
11141114
return "transpose";
11151115
case DAK_Differentiating:
11161116
return "differentiating";
1117-
case DAK_Transposing:
1118-
return "transposing";
11191117
case DAK_Quoted:
11201118
return "quoted";
1119+
// SWIFT_ENABLE_TENSORFLOW END
11211120
}
11221121
llvm_unreachable("bad DeclAttrKind");
11231122
}

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ bool Parser::parseDifferentiationParametersClause(
929929
return false;
930930
}
931931

932-
bool Parser::parseTransposingParametersClause(
932+
bool Parser::parseTransposedParametersClause(
933933
SmallVectorImpl<ParsedAutoDiffParameter> &params, StringRef attrName) {
934934
SyntaxParsingContext TransposeParamsClauseContext(
935935
SyntaxContext, SyntaxKind::DifferentiationParamsClause);
@@ -950,7 +950,7 @@ bool Parser::parseTransposingParametersClause(
950950
unsigned int paramNum;
951951
if (parseUnsignedInteger(
952952
paramNum, paramLoc,
953-
diag::transposing_params_clause_expected_parameter))
953+
diag::transpose_params_clause_expected_parameter))
954954
return true;
955955

956956
params.push_back(
@@ -963,7 +963,7 @@ bool Parser::parseTransposingParametersClause(
963963
break;
964964
}
965965
default:
966-
diagnose(Tok, diag::transposing_params_clause_expected_parameter);
966+
diagnose(Tok, diag::transpose_params_clause_expected_parameter);
967967
return true;
968968
}
969969
if (parseTrailingComma && Tok.isNot(tok::r_paren))
@@ -1362,73 +1362,9 @@ ParserResult<TransposeAttr> Parser::parseTransposeAttribute(SourceLoc atLoc,
13621362
if (consumeIfTrailingComma())
13631363
return makeParserError();
13641364
}
1365-
// Parse the optional 'wrt' differentiation parameters clause.
1366-
if (Tok.is(tok::identifier) && Tok.getText() == "wrt" &&
1367-
parseTransposingParametersClause(params, AttrName))
1368-
return makeParserError();
1369-
}
1370-
// Parse ')'.
1371-
if (!consumeIf(tok::r_paren, rParenLoc)) {
1372-
diagnose(getEndOfPreviousLoc(), diag::attr_expected_rparen, AttrName,
1373-
/*DeclModifier*/ false);
1374-
return makeParserError();
1375-
}
1376-
return ParserResult<TransposeAttr>(TransposeAttr::create(
1377-
Context, /*implicit*/ false, atLoc, SourceRange(loc, rParenLoc), baseType,
1378-
original, params));
1379-
}
1380-
1381-
ParserResult<TransposeAttr> Parser::parseTransposingAttribute(SourceLoc atLoc,
1382-
SourceLoc loc) {
1383-
StringRef AttrName = "transposing";
1384-
SourceLoc lParenLoc = loc, rParenLoc = loc;
1385-
TypeRepr *baseType;
1386-
DeclNameWithLoc original;
1387-
SmallVector<ParsedAutoDiffParameter, 8> params;
1388-
1389-
// Parse trailing comma, if it exists, and check for errors.
1390-
auto consumeIfTrailingComma = [&]() -> bool {
1391-
if (!consumeIf(tok::comma))
1392-
return false;
1393-
// Diagnose trailing comma before ')'.
1394-
if (Tok.is(tok::r_paren)) {
1395-
diagnose(Tok, diag::unexpected_separator, ",");
1396-
return errorAndSkipUntilConsumeRightParen(*this, AttrName);
1397-
}
1398-
// Check that token after comma is 'wrt:'.
1399-
if (isIdentifier(Tok, "wrt"))
1400-
return false;
1401-
diagnose(Tok, diag::attr_expected_label, "wrt", AttrName);
1402-
return errorAndSkipUntilConsumeRightParen(*this, AttrName);
1403-
};
1404-
1405-
// Parse '('.
1406-
if (!consumeIf(tok::l_paren, lParenLoc)) {
1407-
diagnose(getEndOfPreviousLoc(), diag::attr_expected_lparen, AttrName,
1408-
/*DeclModifier*/ false);
1409-
return makeParserError();
1410-
}
1411-
{
1412-
SyntaxParsingContext ContentContext(
1413-
SyntaxContext,
1414-
SyntaxKind::DeprecatedDerivativeRegistrationAttributeArguments);
1415-
{
1416-
// Parse the optionally qualified function name.
1417-
// TODO(TF-1009): Fix syntax support for dot-separated qualified names.
1418-
// Currently, `SyntaxKind::FunctionDeclName` only supports unqualified
1419-
// names.
1420-
SyntaxParsingContext FuncDeclNameContext(SyntaxContext,
1421-
SyntaxKind::FunctionDeclName);
1422-
if (parseQualifiedDeclName(*this,
1423-
diag::attr_transpose_expected_original_name,
1424-
baseType, original))
1425-
return makeParserError();
1426-
if (consumeIfTrailingComma())
1427-
return makeParserError();
1428-
}
1429-
// Parse the optional 'wrt' differentiation parameters clause.
1365+
// Parse the optional 'wrt' transposed parameters clause.
14301366
if (Tok.is(tok::identifier) && Tok.getText() == "wrt" &&
1431-
parseTransposingParametersClause(params, AttrName))
1367+
parseTransposedParametersClause(params, AttrName))
14321368
return makeParserError();
14331369
}
14341370
// Parse ')'.
@@ -2308,21 +2244,6 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
23082244
break;
23092245
}
23102246

2311-
// SWIFT_ENABLE_TENSORFLOW
2312-
case DAK_Transposing: {
2313-
// Diagnose deprecated `@transposing` attribute.
2314-
diagnose(Loc, diag::attr_transposing_deprecated);
2315-
2316-
// `@transposing` in a local scope is not allowed.
2317-
if (CurDeclContext->isLocalContext())
2318-
diagnose(Loc, diag::attr_only_at_non_local_scope, '@' + AttrName.str());
2319-
2320-
auto Attr = parseTransposingAttribute(AtLoc, Loc);
2321-
if (Attr.isNonNull())
2322-
Attributes.add(Attr.get());
2323-
break;
2324-
}
2325-
23262247
case DAK_ProjectedValueProperty: {
23272248
if (!consumeIf(tok::l_paren)) {
23282249
diagnose(Loc, diag::attr_expected_lparen, AttrName,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
252252
void visitTransposeAttr(TransposeAttr *attr);
253253
// TODO(TF-999): Remove deprecated `@differentiating` attribute.
254254
void visitDifferentiatingAttr(DerivativeAttr *attr);
255-
// TODO(TF-999): Remove deprecated `@transposing` attribute.
256-
void visitTransposingAttr(TransposeAttr *attr);
257255
void visitCompilerEvaluableAttr(CompilerEvaluableAttr *attr);
258256
void visitNoDerivativeAttr(NoDerivativeAttr *attr);
259257
// SWIFT_ENABLE_TENSORFLOW END
@@ -3094,15 +3092,13 @@ static IndexSubset *computeDifferentiationParameters(
30943092
}
30953093

30963094
// SWIFT_ENABLE_TENSORFLOW
3097-
// Computes `IndexSubset` from the given parsed transposing parameters
3098-
// (possibly empty) for the given function, then verifies that the parameter
3099-
// indices are valid.
3100-
// The attribute name/location are used in diagnostics.
3101-
static IndexSubset *computeTransposingParameters(
3095+
// Computes `IndexSubset` from the given parsed transposed parameters (possibly
3096+
// empty) for the given function, then verifies that the parameter indices are
3097+
// valid. The attribute name/location are used in diagnostics.
3098+
static IndexSubset *computeTransposedParameters(
31023099
ArrayRef<ParsedAutoDiffParameter> parsedWrtParams,
31033100
AbstractFunctionDecl *transposeFunction, bool isCurried,
3104-
GenericEnvironment *derivativeGenEnv, SourceLoc attrLoc
3105-
) {
3101+
GenericEnvironment *derivativeGenEnv, SourceLoc attrLoc) {
31063102
auto &ctx = transposeFunction->getASTContext();
31073103
auto &diags = ctx.Diags;
31083104

@@ -3248,11 +3244,10 @@ static bool checkDifferentiationParameters(
32483244
// context. Returns true on error.
32493245
// The parsed differentiation parameters and attribute location are used in
32503246
// diagnostics.
3251-
static bool checkTransposingParameters(
3252-
AbstractFunctionDecl *AFD,
3253-
SmallVector<Type, 4> wrtParamTypes, GenericEnvironment *derivativeGenEnv,
3254-
ModuleDecl *module, ArrayRef<ParsedAutoDiffParameter> parsedWrtParams,
3255-
SourceLoc attrLoc) {
3247+
static bool checkTransposedParameters(
3248+
AbstractFunctionDecl *AFD, SmallVector<Type, 4> wrtParamTypes,
3249+
GenericEnvironment *derivativeGenEnv, ModuleDecl *module,
3250+
ArrayRef<ParsedAutoDiffParameter> parsedWrtParams, SourceLoc attrLoc) {
32563251
auto &ctx = AFD->getASTContext();
32573252
auto &diags = ctx.Diags;
32583253

@@ -4001,17 +3996,17 @@ void AttributeChecker::visitTransposeAttr(TransposeAttr *attr) {
40013996
// If checked wrt param indices are not specified, compute them.
40023997
bool isCurried = transposeInterfaceType->getResult()->is<AnyFunctionType>();
40033998
if (!wrtParamIndices)
4004-
wrtParamIndices = computeTransposingParameters(
3999+
wrtParamIndices = computeTransposedParameters(
40054000
parsedWrtParams, transpose, isCurried,
40064001
transpose->getGenericEnvironment(), attr->getLocation());
40074002
if (!wrtParamIndices) {
40084003
D->getAttrs().removeAttribute(attr);
40094004
attr->setInvalid();
40104005
return;
40114006
}
4012-
4007+
40134008
// Diagnose empty parameter indices. This occurs when no `wrt` clause is
4014-
// declared and no differentiation parameters can be inferred.
4009+
// declared and no transposed parameters can be inferred.
40154010
if (wrtParamIndices->isEmpty()) {
40164011
diagnose(attr->getLocation(),
40174012
diag::diff_params_clause_no_inferred_parameters);
@@ -4104,8 +4099,8 @@ void AttributeChecker::visitTransposeAttr(TransposeAttr *attr) {
41044099
originalName.Name);
41054100
};
41064101

4107-
// Returns true if the derivative function and original function candidate are
4108-
// defined in compatible type contexts. If the derivative function and the
4102+
// Returns true if the transpose function and original function candidate are
4103+
// defined in compatible type contexts. If the transpose function and the
41094104
// original function candidate have different parents, return false.
41104105
std::function<bool(AbstractFunctionDecl *)> hasValidTypeContext =
41114106
[&](AbstractFunctionDecl *decl) { return true; };
@@ -4138,34 +4133,29 @@ void AttributeChecker::visitTransposeAttr(TransposeAttr *attr) {
41384133

41394134
attr->setOriginalFunction(originalAFD);
41404135

4141-
// Gather differentiation parameters.
4142-
// Differentiation parameters are with respect to the original function.
4136+
// Get the transposed parameter types.
41434137
SmallVector<Type, 4> wrtParamTypes;
41444138
autodiff::getSubsetParameterTypes(wrtParamIndices, expectedOriginalFnType,
41454139
wrtParamTypes);
41464140

4147-
// Check if differentiation parameter indices are valid.
4148-
if (checkTransposingParameters(originalAFD, wrtParamTypes,
4149-
transpose->getGenericEnvironment(),
4150-
transpose->getModuleContext(), parsedWrtParams,
4151-
attr->getLocation())) {
4141+
// Check if transposed parameter indices are valid.
4142+
if (checkTransposedParameters(originalAFD, wrtParamTypes,
4143+
transpose->getGenericEnvironment(),
4144+
transpose->getModuleContext(), parsedWrtParams,
4145+
attr->getLocation())) {
41524146
D->getAttrs().removeAttribute(attr);
41534147
attr->setInvalid();
41544148
return;
41554149
}
41564150

4157-
// Set the checked differentiation parameter indices in the attribute.
4151+
// Set the checked transposed parameter indices in the attribute.
41584152
attr->setParameterIndices(wrtParamIndices);
41594153
}
41604154

41614155
void AttributeChecker::visitDifferentiatingAttr(DerivativeAttr *attr) {
41624156
visitDerivativeAttr(attr);
41634157
}
41644158

4165-
void AttributeChecker::visitTransposingAttr(TransposeAttr *attr) {
4166-
visitTransposeAttr(attr);
4167-
}
4168-
41694159
static bool
41704160
compilerEvaluableAllowedInExtensionDecl(ExtensionDecl *extensionDecl) {
41714161
auto extendedTypeKind = extensionDecl->getExtendedType()->getKind();

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,6 @@ namespace {
14291429
UNINTERESTING_ATTR(Derivative)
14301430
UNINTERESTING_ATTR(Transpose)
14311431
UNINTERESTING_ATTR(Differentiating)
1432-
UNINTERESTING_ATTR(Transposing)
14331432
UNINTERESTING_ATTR(NoDerivative)
14341433
UNINTERESTING_ATTR(CompilerEvaluable)
14351434
// SWIFT_ENABLE_TENSORFLOW END

lib/Serialization/ModuleFormat.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,6 @@ namespace decls_block {
17921792
BCArray<BCFixed<1>> // Differentiation parameter indices' bitvector.
17931793
>;
17941794

1795-
// TODO(TF-999): Remove deprecated `@transposing` attribute.
1796-
using TransposingDeclAttrLayout = TransposeDeclAttrLayout;
1797-
17981795
#define SIMPLE_DECL_ATTR(X, CLASS, ...) \
17991796
using CLASS##DeclAttrLayout = BCRecordLayout< \
18001797
CLASS##_DECL_ATTR, \

lib/Serialization/Serialization.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,6 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
21272127
case DAK_Derivative:
21282128
case DAK_Transpose:
21292129
case DAK_Differentiating:
2130-
case DAK_Transposing:
21312130
llvm_unreachable("cannot serialize attribute");
21322131
// SWIFT_ENABLE_TENSORFLOW END
21332132

0 commit comments

Comments
 (0)