@@ -877,7 +877,7 @@ static bool errorAndSkipUntilConsumeRightParen(Parser &P, StringRef attrName,
877
877
bool Parser::parseDifferentiationParametersClause (
878
878
SmallVectorImpl<ParsedAutoDiffParameter> ¶ms, StringRef attrName) {
879
879
SyntaxParsingContext DiffParamsClauseContext (
880
- SyntaxContext, SyntaxKind::DifferentiationParamsClause);
880
+ SyntaxContext, SyntaxKind::DifferentiationParamsClause);
881
881
consumeToken (tok::identifier);
882
882
if (!consumeIf (tok::colon)) {
883
883
diagnose (Tok, diag::expected_colon_after_label, " wrt" );
@@ -1207,17 +1207,19 @@ ParserResult<DerivativeAttr> Parser::parseDerivativeAttribute(SourceLoc atLoc,
1207
1207
}
1208
1208
{
1209
1209
// Parse the name of the function.
1210
- SyntaxParsingContext FuncDeclNameContext (SyntaxContext,
1211
- SyntaxKind::FunctionDeclName);
1210
+ // TODO(TF-1058): Make `@derivative` attribute support qualified
1211
+ // original declarations.
1212
+ SyntaxParsingContext DeclNameContext (SyntaxContext,
1213
+ SyntaxKind::QualifiedDeclName);
1212
1214
// NOTE: Use `afterDot = true` and `allowDeinitAndSubscript = true` to
1213
1215
// enable, e.g. `@derivative(of: init)` and `@derivative(of: subscript)`.
1214
1216
original.Name = parseUnqualifiedDeclName (
1215
1217
/* afterDot*/ true , original.Loc ,
1216
1218
diag::attr_derivative_expected_original_name, /* allowOperators*/ true ,
1217
1219
/* allowZeroArgCompoundNames*/ true , /* allowDeinitAndSubscript*/ true );
1218
- if (consumeIfTrailingComma ())
1219
- return makeParserError ();
1220
1220
}
1221
+ if (consumeIfTrailingComma ())
1222
+ return makeParserError ();
1221
1223
// Parse the optional 'wrt' differentiation parameters clause.
1222
1224
if (isIdentifier (Tok, " wrt" ) &&
1223
1225
parseDifferentiationParametersClause (params, AttrName))
@@ -1269,18 +1271,20 @@ Parser::parseDifferentiatingAttribute(SourceLoc atLoc, SourceLoc loc) {
1269
1271
SyntaxKind::DeprecatedDerivativeRegistrationAttributeArguments);
1270
1272
{
1271
1273
// Parse the name of the function.
1272
- SyntaxParsingContext FuncDeclNameContext (
1273
- SyntaxContext, SyntaxKind::FunctionDeclName);
1274
+ // TODO(TF-1058): Make `@differentiating` attribute support qualified
1275
+ // original declarations.
1276
+ SyntaxParsingContext DeclNameContext (SyntaxContext,
1277
+ SyntaxKind::QualifiedDeclName);
1274
1278
// NOTE: Use `afterDot = true` and `allowDeinitAndSubscript = true` to
1275
1279
// enable, e.g. `@differentiating(init)` and
1276
1280
// `@differentiating(subscript)`.
1277
1281
original.Name = parseUnqualifiedDeclName (
1278
1282
/* afterDot*/ true , original.Loc ,
1279
1283
diag::attr_derivative_expected_original_name, /* allowOperators*/ true ,
1280
1284
/* allowZeroArgCompoundNames*/ true , /* allowDeinitAndSubscript*/ true );
1281
- if (consumeIfTrailingComma ())
1282
- return makeParserError ();
1283
1285
}
1286
+ if (consumeIfTrailingComma ())
1287
+ return makeParserError ();
1284
1288
// Parse the optional 'wrt' differentiation parameters clause.
1285
1289
if (isIdentifier (Tok, " wrt" ) &&
1286
1290
parseDifferentiationParametersClause (params, AttrName))
@@ -1335,6 +1339,8 @@ static bool parseBaseTypeForQualifiedDeclName(Parser &P, TypeRepr *&baseType) {
1335
1339
// / Returns true on error (if function decl name could not be parsed).
1336
1340
bool parseQualifiedDeclName (Parser &P, Diag<> nameParseError,
1337
1341
TypeRepr *&baseType, DeclNameWithLoc &original) {
1342
+ SyntaxParsingContext DeclNameContext (P.SyntaxContext ,
1343
+ SyntaxKind::QualifiedDeclName);
1338
1344
if (parseBaseTypeForQualifiedDeclName (P, baseType))
1339
1345
return true ;
1340
1346
@@ -1399,18 +1405,13 @@ ParserResult<TransposeAttr> Parser::parseTransposeAttribute(SourceLoc atLoc,
1399
1405
}
1400
1406
{
1401
1407
// Parse the optionally qualified function name.
1402
- // TODO(TF-1009): Fix syntax support for dot-separated qualified names.
1403
- // Currently, `SyntaxKind::FunctionDeclName` only supports unqualified
1404
- // names.
1405
- SyntaxParsingContext FuncDeclNameContext (SyntaxContext,
1406
- SyntaxKind::FunctionDeclName);
1407
1408
if (parseQualifiedDeclName (*this ,
1408
1409
diag::attr_transpose_expected_original_name,
1409
1410
baseType, original))
1410
1411
return makeParserError ();
1411
- if (consumeIfTrailingComma ())
1412
- return makeParserError ();
1413
1412
}
1413
+ if (consumeIfTrailingComma ())
1414
+ return makeParserError ();
1414
1415
// Parse the optional 'wrt' transposed parameters clause.
1415
1416
if (Tok.is (tok::identifier) && Tok.getText () == " wrt" &&
1416
1417
parseTransposedParametersClause (params, AttrName))
0 commit comments