@@ -6030,20 +6030,6 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition, bool IsTopLevel) {
6030
6030
}
6031
6031
}
6032
6032
6033
- // / Set the original declaration in `@differentiable` attributes.
6034
- // /
6035
- // / Necessary because `Parser::parseNewDeclAttribute` (which calls
6036
- // / `Parser::parseDifferentiableAttribute`) does not have access to the
6037
- // / parent declaration of parsed attributes.
6038
- static void
6039
- setOriginalDeclarationForDifferentiableAttributes (DeclAttributes attrs,
6040
- Decl *D) {
6041
- for (auto *attr : attrs.getAttributes <DifferentiableAttr>())
6042
- const_cast <DifferentiableAttr *>(attr)->setOriginalDeclaration (D);
6043
- for (auto *attr : attrs.getAttributes <DerivativeAttr>())
6044
- const_cast <DerivativeAttr *>(attr)->setOriginalDeclaration (D);
6045
- }
6046
-
6047
6033
// / Determine the declaration parsing options to use when parsing the decl in
6048
6034
// / the given context.
6049
6035
static Parser::ParseDeclOptions getParseDeclOptions (DeclContext *DC) {
@@ -6469,7 +6455,6 @@ ParserStatus Parser::parseDecl(bool IsAtStartOfLineOrPreviousHadSemi,
6469
6455
Decl *D = DeclResult.get ();
6470
6456
if (!HandlerAlreadyCalled)
6471
6457
Handler (D);
6472
- setOriginalDeclarationForDifferentiableAttributes (D->getAttrs (), D);
6473
6458
}
6474
6459
6475
6460
if (!DeclResult.isParseErrorOrHasCompletion ()) {
@@ -6665,7 +6650,7 @@ ParserResult<ImportDecl> Parser::parseDeclImport(ParseDeclOptions Flags,
6665
6650
6666
6651
auto *ID = ImportDecl::create (Context, CurDeclContext, ImportLoc, Kind,
6667
6652
KindLoc, importPath.get ());
6668
- ID->getAttrs () = Attributes;
6653
+ ID->attachParsedAttrs ( Attributes) ;
6669
6654
return DCC.fixupParserResult (ID);
6670
6655
}
6671
6656
@@ -7109,7 +7094,7 @@ Parser::parseDeclExtension(ParseDeclOptions Flags, DeclAttributes &Attributes) {
7109
7094
Context.AllocateCopy (Inherited),
7110
7095
CurDeclContext,
7111
7096
trailingWhereClause);
7112
- ext->getAttrs () = Attributes;
7097
+ ext->attachParsedAttrs ( Attributes) ;
7113
7098
if (trailingWhereHadCodeCompletion && CodeCompletionCallbacks)
7114
7099
CodeCompletionCallbacks->setParsedDecl (ext);
7115
7100
@@ -7444,7 +7429,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
7444
7429
}
7445
7430
7446
7431
TAD->setUnderlyingTypeRepr (UnderlyingTy.getPtrOrNull ());
7447
- TAD->getAttrs () = Attributes;
7432
+ TAD->attachParsedAttrs ( Attributes) ;
7448
7433
7449
7434
// Parse a 'where' clause if present.
7450
7435
if (Tok.is (tok::kw_where)) {
@@ -7561,7 +7546,7 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
7561
7546
auto assocType = AssociatedTypeDecl::createParsed (
7562
7547
Context, CurDeclContext, AssociatedTypeLoc, Id, IdLoc,
7563
7548
UnderlyingTy.getPtrOrNull (), TrailingWhere);
7564
- assocType->getAttrs () = Attributes;
7549
+ assocType->attachParsedAttrs ( Attributes) ;
7565
7550
if (!Inherited.empty ())
7566
7551
assocType->setInherited (Context.AllocateCopy (Inherited));
7567
7552
return makeParserResult (Status, assocType);
@@ -7916,7 +7901,7 @@ bool Parser::parseAccessorAfterIntroducer(
7916
7901
auto *accessor = AccessorDecl::createParsed (
7917
7902
Context, Kind, storage, /* declLoc*/ Loc, /* accessorKeywordLoc*/ Loc,
7918
7903
param, asyncLoc, throwsLoc, thrownTy, CurDeclContext);
7919
- accessor->getAttrs () = Attributes;
7904
+ accessor->attachParsedAttrs ( Attributes) ;
7920
7905
7921
7906
// Collect this accessor and detect conflicts.
7922
7907
if (auto existingAccessor = accessors.add (accessor)) {
@@ -8195,7 +8180,7 @@ void Parser::parseExpandedAttributeList(SmallVectorImpl<ASTNode> &items,
8195
8180
// macro will attach the attribute list to.
8196
8181
MissingDecl *missing =
8197
8182
MissingDecl::create (Context, CurDeclContext, Tok.getLoc ());
8198
- missing->getAttrs () = attributes;
8183
+ missing->attachParsedAttrs ( attributes) ;
8199
8184
8200
8185
items.push_back (ASTNode (missing));
8201
8186
return ;
@@ -8325,11 +8310,6 @@ Parser::parseDeclVarGetSet(PatternBindingEntry &entry, ParseDeclOptions Flags,
8325
8310
8326
8311
accessors.record (*this , PrimaryVar, Invalid);
8327
8312
8328
- // Set original declaration in `@differentiable` attributes.
8329
- for (auto *accessor : accessors.Accessors )
8330
- setOriginalDeclarationForDifferentiableAttributes (accessor->getAttrs (),
8331
- accessor);
8332
-
8333
8313
return makeParserResult (AccessorStatus, PrimaryVar);
8334
8314
}
8335
8315
@@ -8619,12 +8599,9 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
8619
8599
// Configure all vars with attributes, 'static' and parent pattern.
8620
8600
pattern->forEachVariable ([&](VarDecl *VD) {
8621
8601
VD->setStatic (StaticLoc.isValid ());
8622
- VD->getAttrs () = Attributes;
8602
+ VD->attachParsedAttrs ( Attributes) ;
8623
8603
VD->setTopLevelGlobal (topLevelDecl);
8624
8604
8625
- // Set original declaration in `@differentiable` attributes.
8626
- setOriginalDeclarationForDifferentiableAttributes (Attributes, VD);
8627
-
8628
8605
Decls.push_back (VD);
8629
8606
if (hasOpaqueReturnTy && sf && !InInactiveClauseEnvironment
8630
8607
&& !InFreestandingMacroArgument) {
@@ -8944,7 +8921,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
8944
8921
diagnoseOperatorFixityAttributes (*this , Attributes, FD);
8945
8922
// Add the attributes here so if we need them while parsing the body
8946
8923
// they are available.
8947
- FD->getAttrs () = Attributes;
8924
+ FD->attachParsedAttrs ( Attributes) ;
8948
8925
8949
8926
// Pass the function signature to code completion.
8950
8927
if (Status.hasCodeCompletion ()) {
@@ -9135,7 +9112,7 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
9135
9112
9136
9113
EnumDecl *ED = new (Context) EnumDecl (EnumLoc, EnumName, EnumNameLoc,
9137
9114
{ }, GenericParams, CurDeclContext);
9138
- ED->getAttrs () = Attributes;
9115
+ ED->attachParsedAttrs ( Attributes) ;
9139
9116
9140
9117
ContextChange CC (*this , ED);
9141
9118
@@ -9330,7 +9307,7 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
9330
9307
result->setImplicit (); // Parse error
9331
9308
}
9332
9309
9333
- result->getAttrs () = Attributes;
9310
+ result->attachParsedAttrs ( Attributes) ;
9334
9311
Elements.push_back (result);
9335
9312
9336
9313
// Continue through the comma-separated list.
@@ -9397,7 +9374,7 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
9397
9374
{ },
9398
9375
GenericParams,
9399
9376
CurDeclContext);
9400
- SD->getAttrs () = Attributes;
9377
+ SD->attachParsedAttrs ( Attributes) ;
9401
9378
9402
9379
ContextChange CC (*this , SD);
9403
9380
@@ -9486,7 +9463,7 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
9486
9463
ClassDecl *CD = new (Context) ClassDecl (ClassLoc, ClassName, ClassNameLoc,
9487
9464
{ }, GenericParams, CurDeclContext,
9488
9465
isExplicitActorDecl);
9489
- CD->getAttrs () = Attributes;
9466
+ CD->attachParsedAttrs ( Attributes) ;
9490
9467
9491
9468
// Parsed classes never have missing vtable entries.
9492
9469
CD->setHasMissingVTableEntries (false );
@@ -9665,7 +9642,7 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
9665
9642
Context.AllocateCopy (PrimaryAssociatedTypeNames),
9666
9643
Context.AllocateCopy (InheritedProtocols), TrailingWhere);
9667
9644
9668
- Proto->getAttrs () = Attributes;
9645
+ Proto->attachParsedAttrs ( Attributes) ;
9669
9646
if (whereClauseHadCodeCompletion && CodeCompletionCallbacks)
9670
9647
CodeCompletionCallbacks->setParsedDecl (Proto);
9671
9648
@@ -9792,7 +9769,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
9792
9769
auto *const Subscript = SubscriptDecl::createParsed (
9793
9770
Context, StaticLoc, StaticSpelling, SubscriptLoc, Indices.get (), ArrowLoc,
9794
9771
ElementTy.get (), CurDeclContext, GenericParams);
9795
- Subscript->getAttrs () = Attributes;
9772
+ Subscript->attachParsedAttrs ( Attributes) ;
9796
9773
9797
9774
// Let the source file track the opaque return type mapping, if any.
9798
9775
if (ElementTy.get () && ElementTy.get ()->hasOpaque () &&
@@ -9853,11 +9830,6 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
9853
9830
accessors.record (*this , Subscript, (Invalid || !Status.isSuccess () ||
9854
9831
Status.hasCodeCompletion ()));
9855
9832
9856
- // Set original declaration in `@differentiable` attributes.
9857
- for (auto *accessor : accessors.Accessors )
9858
- setOriginalDeclarationForDifferentiableAttributes (accessor->getAttrs (),
9859
- accessor);
9860
-
9861
9833
// No need to setLocalDiscriminator because subscripts cannot
9862
9834
// validly appear outside of type decls.
9863
9835
return makeParserResult (Status, Subscript);
@@ -9967,7 +9939,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
9967
9939
thrownTy, BodyParams, GenericParams,
9968
9940
CurDeclContext, FuncRetTy);
9969
9941
CD->setImplicitlyUnwrappedOptional (IUO);
9970
- CD->getAttrs () = Attributes;
9942
+ CD->attachParsedAttrs ( Attributes) ;
9971
9943
9972
9944
// Parse a 'where' clause if present.
9973
9945
if (Tok.is (tok::kw_where)) {
@@ -10056,7 +10028,7 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
10056
10028
auto *DD = new (Context) DestructorDecl (DestructorLoc, CurDeclContext);
10057
10029
parseAbstractFunctionBody (DD);
10058
10030
10059
- DD->getAttrs () = Attributes;
10031
+ DD->attachParsedAttrs ( Attributes) ;
10060
10032
10061
10033
// Reject 'destructor' functions outside of structs, enums, classes, or
10062
10034
// extensions that provide objc implementations.
@@ -10263,7 +10235,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
10263
10235
10264
10236
diagnoseOperatorFixityAttributes (*this , Attributes, res);
10265
10237
10266
- res->getAttrs () = Attributes;
10238
+ res->attachParsedAttrs ( Attributes) ;
10267
10239
return makeParserResult (res);
10268
10240
}
10269
10241
@@ -10320,7 +10292,7 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
10320
10292
higherThanKeywordLoc, higherThan,
10321
10293
lowerThanKeywordLoc, lowerThan,
10322
10294
rbraceLoc);
10323
- result->getAttrs () = attributes;
10295
+ result->attachParsedAttrs ( attributes) ;
10324
10296
return result;
10325
10297
};
10326
10298
auto createInvalid = [&](bool hasCodeCompletion) {
@@ -10575,7 +10547,7 @@ ParserResult<MacroDecl> Parser::parseDeclMacro(DeclAttributes &attributes) {
10575
10547
auto *macro = new (Context) MacroDecl (
10576
10548
macroLoc, macroFullName, macroNameLoc, genericParams, parameterList,
10577
10549
arrowLoc, resultType, definition, CurDeclContext);
10578
- macro->getAttrs () = attributes;
10550
+ macro->attachParsedAttrs ( attributes) ;
10579
10551
10580
10552
// Parse a 'where' clause if present.
10581
10553
if (Tok.is (tok::kw_where)) {
@@ -10611,7 +10583,7 @@ Parser::parseDeclMacroExpansion(ParseDeclOptions flags,
10611
10583
auto *med = MacroExpansionDecl::create (
10612
10584
CurDeclContext, poundLoc, macroNameRef, macroNameLoc, leftAngleLoc,
10613
10585
Context.AllocateCopy (genericArgs), rightAngleLoc, argList);
10614
- med->getAttrs () = attributes;
10586
+ med->attachParsedAttrs ( attributes) ;
10615
10587
10616
10588
return makeParserResult (status, med);
10617
10589
}
0 commit comments