@@ -5968,20 +5968,6 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition, bool IsTopLevel) {
5968
5968
}
5969
5969
}
5970
5970
5971
- // / Set the original declaration in `@differentiable` attributes.
5972
- // /
5973
- // / Necessary because `Parser::parseNewDeclAttribute` (which calls
5974
- // / `Parser::parseDifferentiableAttribute`) does not have access to the
5975
- // / parent declaration of parsed attributes.
5976
- static void
5977
- setOriginalDeclarationForDifferentiableAttributes (DeclAttributes attrs,
5978
- Decl *D) {
5979
- for (auto *attr : attrs.getAttributes <DifferentiableAttr>())
5980
- const_cast <DifferentiableAttr *>(attr)->setOriginalDeclaration (D);
5981
- for (auto *attr : attrs.getAttributes <DerivativeAttr>())
5982
- const_cast <DerivativeAttr *>(attr)->setOriginalDeclaration (D);
5983
- }
5984
-
5985
5971
// / Determine the declaration parsing options to use when parsing the decl in
5986
5972
// / the given context.
5987
5973
static Parser::ParseDeclOptions getParseDeclOptions (DeclContext *DC) {
@@ -6407,7 +6393,6 @@ ParserStatus Parser::parseDecl(bool IsAtStartOfLineOrPreviousHadSemi,
6407
6393
Decl *D = DeclResult.get ();
6408
6394
if (!HandlerAlreadyCalled)
6409
6395
Handler (D);
6410
- setOriginalDeclarationForDifferentiableAttributes (D->getAttrs (), D);
6411
6396
}
6412
6397
6413
6398
if (!DeclResult.isParseErrorOrHasCompletion ()) {
@@ -6603,7 +6588,7 @@ ParserResult<ImportDecl> Parser::parseDeclImport(ParseDeclOptions Flags,
6603
6588
6604
6589
auto *ID = ImportDecl::create (Context, CurDeclContext, ImportLoc, Kind,
6605
6590
KindLoc, importPath.get ());
6606
- ID->getAttrs () = Attributes;
6591
+ ID->attachParsedAttrs ( Attributes) ;
6607
6592
return DCC.fixupParserResult (ID);
6608
6593
}
6609
6594
@@ -7047,7 +7032,7 @@ Parser::parseDeclExtension(ParseDeclOptions Flags, DeclAttributes &Attributes) {
7047
7032
Context.AllocateCopy (Inherited),
7048
7033
CurDeclContext,
7049
7034
trailingWhereClause);
7050
- ext->getAttrs () = Attributes;
7035
+ ext->attachParsedAttrs ( Attributes) ;
7051
7036
if (trailingWhereHadCodeCompletion && CodeCompletionCallbacks)
7052
7037
CodeCompletionCallbacks->setParsedDecl (ext);
7053
7038
@@ -7382,7 +7367,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
7382
7367
}
7383
7368
7384
7369
TAD->setUnderlyingTypeRepr (UnderlyingTy.getPtrOrNull ());
7385
- TAD->getAttrs () = Attributes;
7370
+ TAD->attachParsedAttrs ( Attributes) ;
7386
7371
7387
7372
// Parse a 'where' clause if present.
7388
7373
if (Tok.is (tok::kw_where)) {
@@ -7499,7 +7484,7 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
7499
7484
auto assocType = AssociatedTypeDecl::createParsed (
7500
7485
Context, CurDeclContext, AssociatedTypeLoc, Id, IdLoc,
7501
7486
UnderlyingTy.getPtrOrNull (), TrailingWhere);
7502
- assocType->getAttrs () = Attributes;
7487
+ assocType->attachParsedAttrs ( Attributes) ;
7503
7488
if (!Inherited.empty ())
7504
7489
assocType->setInherited (Context.AllocateCopy (Inherited));
7505
7490
return makeParserResult (Status, assocType);
@@ -7854,7 +7839,7 @@ bool Parser::parseAccessorAfterIntroducer(
7854
7839
auto *accessor = AccessorDecl::createParsed (
7855
7840
Context, Kind, storage, /* declLoc*/ Loc, /* accessorKeywordLoc*/ Loc,
7856
7841
param, asyncLoc, throwsLoc, thrownTy, CurDeclContext);
7857
- accessor->getAttrs () = Attributes;
7842
+ accessor->attachParsedAttrs ( Attributes) ;
7858
7843
7859
7844
// Collect this accessor and detect conflicts.
7860
7845
if (auto existingAccessor = accessors.add (accessor)) {
@@ -8133,7 +8118,7 @@ void Parser::parseExpandedAttributeList(SmallVectorImpl<ASTNode> &items,
8133
8118
// macro will attach the attribute list to.
8134
8119
MissingDecl *missing =
8135
8120
MissingDecl::create (Context, CurDeclContext, Tok.getLoc ());
8136
- missing->getAttrs () = attributes;
8121
+ missing->attachParsedAttrs ( attributes) ;
8137
8122
8138
8123
items.push_back (ASTNode (missing));
8139
8124
return ;
@@ -8263,11 +8248,6 @@ Parser::parseDeclVarGetSet(PatternBindingEntry &entry, ParseDeclOptions Flags,
8263
8248
8264
8249
accessors.record (*this , PrimaryVar, Invalid);
8265
8250
8266
- // Set original declaration in `@differentiable` attributes.
8267
- for (auto *accessor : accessors.Accessors )
8268
- setOriginalDeclarationForDifferentiableAttributes (accessor->getAttrs (),
8269
- accessor);
8270
-
8271
8251
return makeParserResult (AccessorStatus, PrimaryVar);
8272
8252
}
8273
8253
@@ -8557,12 +8537,9 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
8557
8537
// Configure all vars with attributes, 'static' and parent pattern.
8558
8538
pattern->forEachVariable ([&](VarDecl *VD) {
8559
8539
VD->setStatic (StaticLoc.isValid ());
8560
- VD->getAttrs () = Attributes;
8540
+ VD->attachParsedAttrs ( Attributes) ;
8561
8541
VD->setTopLevelGlobal (topLevelDecl);
8562
8542
8563
- // Set original declaration in `@differentiable` attributes.
8564
- setOriginalDeclarationForDifferentiableAttributes (Attributes, VD);
8565
-
8566
8543
Decls.push_back (VD);
8567
8544
if (hasOpaqueReturnTy && sf && !InInactiveClauseEnvironment
8568
8545
&& !InFreestandingMacroArgument) {
@@ -8882,7 +8859,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
8882
8859
diagnoseOperatorFixityAttributes (*this , Attributes, FD);
8883
8860
// Add the attributes here so if we need them while parsing the body
8884
8861
// they are available.
8885
- FD->getAttrs () = Attributes;
8862
+ FD->attachParsedAttrs ( Attributes) ;
8886
8863
8887
8864
// Pass the function signature to code completion.
8888
8865
if (Status.hasCodeCompletion ()) {
@@ -9073,7 +9050,7 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
9073
9050
9074
9051
EnumDecl *ED = new (Context) EnumDecl (EnumLoc, EnumName, EnumNameLoc,
9075
9052
{ }, GenericParams, CurDeclContext);
9076
- ED->getAttrs () = Attributes;
9053
+ ED->attachParsedAttrs ( Attributes) ;
9077
9054
9078
9055
ContextChange CC (*this , ED);
9079
9056
@@ -9268,7 +9245,7 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
9268
9245
result->setImplicit (); // Parse error
9269
9246
}
9270
9247
9271
- result->getAttrs () = Attributes;
9248
+ result->attachParsedAttrs ( Attributes) ;
9272
9249
Elements.push_back (result);
9273
9250
9274
9251
// Continue through the comma-separated list.
@@ -9335,7 +9312,7 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
9335
9312
{ },
9336
9313
GenericParams,
9337
9314
CurDeclContext);
9338
- SD->getAttrs () = Attributes;
9315
+ SD->attachParsedAttrs ( Attributes) ;
9339
9316
9340
9317
ContextChange CC (*this , SD);
9341
9318
@@ -9424,7 +9401,7 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
9424
9401
ClassDecl *CD = new (Context) ClassDecl (ClassLoc, ClassName, ClassNameLoc,
9425
9402
{ }, GenericParams, CurDeclContext,
9426
9403
isExplicitActorDecl);
9427
- CD->getAttrs () = Attributes;
9404
+ CD->attachParsedAttrs ( Attributes) ;
9428
9405
9429
9406
// Parsed classes never have missing vtable entries.
9430
9407
CD->setHasMissingVTableEntries (false );
@@ -9603,7 +9580,7 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
9603
9580
Context.AllocateCopy (PrimaryAssociatedTypeNames),
9604
9581
Context.AllocateCopy (InheritedProtocols), TrailingWhere);
9605
9582
9606
- Proto->getAttrs () = Attributes;
9583
+ Proto->attachParsedAttrs ( Attributes) ;
9607
9584
if (whereClauseHadCodeCompletion && CodeCompletionCallbacks)
9608
9585
CodeCompletionCallbacks->setParsedDecl (Proto);
9609
9586
@@ -9730,7 +9707,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
9730
9707
auto *const Subscript = SubscriptDecl::createParsed (
9731
9708
Context, StaticLoc, StaticSpelling, SubscriptLoc, Indices.get (), ArrowLoc,
9732
9709
ElementTy.get (), CurDeclContext, GenericParams);
9733
- Subscript->getAttrs () = Attributes;
9710
+ Subscript->attachParsedAttrs ( Attributes) ;
9734
9711
9735
9712
// Let the source file track the opaque return type mapping, if any.
9736
9713
if (ElementTy.get () && ElementTy.get ()->hasOpaque () &&
@@ -9791,11 +9768,6 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
9791
9768
accessors.record (*this , Subscript, (Invalid || !Status.isSuccess () ||
9792
9769
Status.hasCodeCompletion ()));
9793
9770
9794
- // Set original declaration in `@differentiable` attributes.
9795
- for (auto *accessor : accessors.Accessors )
9796
- setOriginalDeclarationForDifferentiableAttributes (accessor->getAttrs (),
9797
- accessor);
9798
-
9799
9771
// No need to setLocalDiscriminator because subscripts cannot
9800
9772
// validly appear outside of type decls.
9801
9773
return makeParserResult (Status, Subscript);
@@ -9905,7 +9877,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
9905
9877
thrownTy, BodyParams, GenericParams,
9906
9878
CurDeclContext, FuncRetTy);
9907
9879
CD->setImplicitlyUnwrappedOptional (IUO);
9908
- CD->getAttrs () = Attributes;
9880
+ CD->attachParsedAttrs ( Attributes) ;
9909
9881
9910
9882
// Parse a 'where' clause if present.
9911
9883
if (Tok.is (tok::kw_where)) {
@@ -9994,7 +9966,7 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
9994
9966
auto *DD = new (Context) DestructorDecl (DestructorLoc, CurDeclContext);
9995
9967
parseAbstractFunctionBody (DD);
9996
9968
9997
- DD->getAttrs () = Attributes;
9969
+ DD->attachParsedAttrs ( Attributes) ;
9998
9970
9999
9971
// Reject 'destructor' functions outside of structs, enums, classes, or
10000
9972
// extensions that provide objc implementations.
@@ -10201,7 +10173,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
10201
10173
10202
10174
diagnoseOperatorFixityAttributes (*this , Attributes, res);
10203
10175
10204
- res->getAttrs () = Attributes;
10176
+ res->attachParsedAttrs ( Attributes) ;
10205
10177
return makeParserResult (res);
10206
10178
}
10207
10179
@@ -10258,7 +10230,7 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
10258
10230
higherThanKeywordLoc, higherThan,
10259
10231
lowerThanKeywordLoc, lowerThan,
10260
10232
rbraceLoc);
10261
- result->getAttrs () = attributes;
10233
+ result->attachParsedAttrs ( attributes) ;
10262
10234
return result;
10263
10235
};
10264
10236
auto createInvalid = [&](bool hasCodeCompletion) {
@@ -10513,7 +10485,7 @@ ParserResult<MacroDecl> Parser::parseDeclMacro(DeclAttributes &attributes) {
10513
10485
auto *macro = new (Context) MacroDecl (
10514
10486
macroLoc, macroFullName, macroNameLoc, genericParams, parameterList,
10515
10487
arrowLoc, resultType, definition, CurDeclContext);
10516
- macro->getAttrs () = attributes;
10488
+ macro->attachParsedAttrs ( attributes) ;
10517
10489
10518
10490
// Parse a 'where' clause if present.
10519
10491
if (Tok.is (tok::kw_where)) {
@@ -10549,7 +10521,7 @@ Parser::parseDeclMacroExpansion(ParseDeclOptions flags,
10549
10521
auto *med = MacroExpansionDecl::create (
10550
10522
CurDeclContext, poundLoc, macroNameRef, macroNameLoc, leftAngleLoc,
10551
10523
Context.AllocateCopy (genericArgs), rightAngleLoc, argList);
10552
- med->getAttrs () = attributes;
10524
+ med->attachParsedAttrs ( attributes) ;
10553
10525
10554
10526
return makeParserResult (status, med);
10555
10527
}
0 commit comments