@@ -6000,20 +6000,6 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition, bool IsTopLevel) {
6000
6000
}
6001
6001
}
6002
6002
6003
- // / Set the original declaration in `@differentiable` attributes.
6004
- // /
6005
- // / Necessary because `Parser::parseNewDeclAttribute` (which calls
6006
- // / `Parser::parseDifferentiableAttribute`) does not have access to the
6007
- // / parent declaration of parsed attributes.
6008
- static void
6009
- setOriginalDeclarationForDifferentiableAttributes (DeclAttributes attrs,
6010
- Decl *D) {
6011
- for (auto *attr : attrs.getAttributes <DifferentiableAttr>())
6012
- const_cast <DifferentiableAttr *>(attr)->setOriginalDeclaration (D);
6013
- for (auto *attr : attrs.getAttributes <DerivativeAttr>())
6014
- const_cast <DerivativeAttr *>(attr)->setOriginalDeclaration (D);
6015
- }
6016
-
6017
6003
// / Determine the declaration parsing options to use when parsing the decl in
6018
6004
// / the given context.
6019
6005
static Parser::ParseDeclOptions getParseDeclOptions (DeclContext *DC) {
@@ -6439,7 +6425,6 @@ ParserStatus Parser::parseDecl(bool IsAtStartOfLineOrPreviousHadSemi,
6439
6425
Decl *D = DeclResult.get ();
6440
6426
if (!HandlerAlreadyCalled)
6441
6427
Handler (D);
6442
- setOriginalDeclarationForDifferentiableAttributes (D->getAttrs (), D);
6443
6428
}
6444
6429
6445
6430
if (!DeclResult.isParseErrorOrHasCompletion ()) {
@@ -6635,7 +6620,7 @@ ParserResult<ImportDecl> Parser::parseDeclImport(ParseDeclOptions Flags,
6635
6620
6636
6621
auto *ID = ImportDecl::create (Context, CurDeclContext, ImportLoc, Kind,
6637
6622
KindLoc, importPath.get ());
6638
- ID->getAttrs () = Attributes;
6623
+ ID->attachParsedAttrs ( Attributes) ;
6639
6624
return DCC.fixupParserResult (ID);
6640
6625
}
6641
6626
@@ -7079,7 +7064,7 @@ Parser::parseDeclExtension(ParseDeclOptions Flags, DeclAttributes &Attributes) {
7079
7064
Context.AllocateCopy (Inherited),
7080
7065
CurDeclContext,
7081
7066
trailingWhereClause);
7082
- ext->getAttrs () = Attributes;
7067
+ ext->attachParsedAttrs ( Attributes) ;
7083
7068
if (trailingWhereHadCodeCompletion && CodeCompletionCallbacks)
7084
7069
CodeCompletionCallbacks->setParsedDecl (ext);
7085
7070
@@ -7414,7 +7399,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
7414
7399
}
7415
7400
7416
7401
TAD->setUnderlyingTypeRepr (UnderlyingTy.getPtrOrNull ());
7417
- TAD->getAttrs () = Attributes;
7402
+ TAD->attachParsedAttrs ( Attributes) ;
7418
7403
7419
7404
// Parse a 'where' clause if present.
7420
7405
if (Tok.is (tok::kw_where)) {
@@ -7531,7 +7516,7 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
7531
7516
auto assocType = AssociatedTypeDecl::createParsed (
7532
7517
Context, CurDeclContext, AssociatedTypeLoc, Id, IdLoc,
7533
7518
UnderlyingTy.getPtrOrNull (), TrailingWhere);
7534
- assocType->getAttrs () = Attributes;
7519
+ assocType->attachParsedAttrs ( Attributes) ;
7535
7520
if (!Inherited.empty ())
7536
7521
assocType->setInherited (Context.AllocateCopy (Inherited));
7537
7522
return makeParserResult (Status, assocType);
@@ -7886,7 +7871,7 @@ bool Parser::parseAccessorAfterIntroducer(
7886
7871
auto *accessor = AccessorDecl::createParsed (
7887
7872
Context, Kind, storage, /* declLoc*/ Loc, /* accessorKeywordLoc*/ Loc,
7888
7873
param, asyncLoc, throwsLoc, thrownTy, CurDeclContext);
7889
- accessor->getAttrs () = Attributes;
7874
+ accessor->attachParsedAttrs ( Attributes) ;
7890
7875
7891
7876
// Collect this accessor and detect conflicts.
7892
7877
if (auto existingAccessor = accessors.add (accessor)) {
@@ -8165,7 +8150,7 @@ void Parser::parseExpandedAttributeList(SmallVectorImpl<ASTNode> &items,
8165
8150
// macro will attach the attribute list to.
8166
8151
MissingDecl *missing =
8167
8152
MissingDecl::create (Context, CurDeclContext, Tok.getLoc ());
8168
- missing->getAttrs () = attributes;
8153
+ missing->attachParsedAttrs ( attributes) ;
8169
8154
8170
8155
items.push_back (ASTNode (missing));
8171
8156
return ;
@@ -8295,11 +8280,6 @@ Parser::parseDeclVarGetSet(PatternBindingEntry &entry, ParseDeclOptions Flags,
8295
8280
8296
8281
accessors.record (*this , PrimaryVar, Invalid);
8297
8282
8298
- // Set original declaration in `@differentiable` attributes.
8299
- for (auto *accessor : accessors.Accessors )
8300
- setOriginalDeclarationForDifferentiableAttributes (accessor->getAttrs (),
8301
- accessor);
8302
-
8303
8283
return makeParserResult (AccessorStatus, PrimaryVar);
8304
8284
}
8305
8285
@@ -8589,12 +8569,9 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
8589
8569
// Configure all vars with attributes, 'static' and parent pattern.
8590
8570
pattern->forEachVariable ([&](VarDecl *VD) {
8591
8571
VD->setStatic (StaticLoc.isValid ());
8592
- VD->getAttrs () = Attributes;
8572
+ VD->attachParsedAttrs ( Attributes) ;
8593
8573
VD->setTopLevelGlobal (topLevelDecl);
8594
8574
8595
- // Set original declaration in `@differentiable` attributes.
8596
- setOriginalDeclarationForDifferentiableAttributes (Attributes, VD);
8597
-
8598
8575
Decls.push_back (VD);
8599
8576
if (hasOpaqueReturnTy && sf && !InInactiveClauseEnvironment
8600
8577
&& !InFreestandingMacroArgument) {
@@ -8921,7 +8898,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
8921
8898
diagnoseOperatorFixityAttributes (*this , Attributes, FD);
8922
8899
// Add the attributes here so if we need them while parsing the body
8923
8900
// they are available.
8924
- FD->getAttrs () = Attributes;
8901
+ FD->attachParsedAttrs ( Attributes) ;
8925
8902
8926
8903
// Pass the function signature to code completion.
8927
8904
if (Status.hasCodeCompletion ()) {
@@ -9112,7 +9089,7 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
9112
9089
9113
9090
EnumDecl *ED = new (Context) EnumDecl (EnumLoc, EnumName, EnumNameLoc,
9114
9091
{ }, GenericParams, CurDeclContext);
9115
- ED->getAttrs () = Attributes;
9092
+ ED->attachParsedAttrs ( Attributes) ;
9116
9093
9117
9094
ContextChange CC (*this , ED);
9118
9095
@@ -9307,7 +9284,7 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
9307
9284
result->setImplicit (); // Parse error
9308
9285
}
9309
9286
9310
- result->getAttrs () = Attributes;
9287
+ result->attachParsedAttrs ( Attributes) ;
9311
9288
Elements.push_back (result);
9312
9289
9313
9290
// Continue through the comma-separated list.
@@ -9374,7 +9351,7 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
9374
9351
{ },
9375
9352
GenericParams,
9376
9353
CurDeclContext);
9377
- SD->getAttrs () = Attributes;
9354
+ SD->attachParsedAttrs ( Attributes) ;
9378
9355
9379
9356
ContextChange CC (*this , SD);
9380
9357
@@ -9463,7 +9440,7 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
9463
9440
ClassDecl *CD = new (Context) ClassDecl (ClassLoc, ClassName, ClassNameLoc,
9464
9441
{ }, GenericParams, CurDeclContext,
9465
9442
isExplicitActorDecl);
9466
- CD->getAttrs () = Attributes;
9443
+ CD->attachParsedAttrs ( Attributes) ;
9467
9444
9468
9445
// Parsed classes never have missing vtable entries.
9469
9446
CD->setHasMissingVTableEntries (false );
@@ -9642,7 +9619,7 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
9642
9619
Context.AllocateCopy (PrimaryAssociatedTypeNames),
9643
9620
Context.AllocateCopy (InheritedProtocols), TrailingWhere);
9644
9621
9645
- Proto->getAttrs () = Attributes;
9622
+ Proto->attachParsedAttrs ( Attributes) ;
9646
9623
if (whereClauseHadCodeCompletion && CodeCompletionCallbacks)
9647
9624
CodeCompletionCallbacks->setParsedDecl (Proto);
9648
9625
@@ -9769,7 +9746,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
9769
9746
auto *const Subscript = SubscriptDecl::createParsed (
9770
9747
Context, StaticLoc, StaticSpelling, SubscriptLoc, Indices.get (), ArrowLoc,
9771
9748
ElementTy.get (), CurDeclContext, GenericParams);
9772
- Subscript->getAttrs () = Attributes;
9749
+ Subscript->attachParsedAttrs ( Attributes) ;
9773
9750
9774
9751
// Let the source file track the opaque return type mapping, if any.
9775
9752
if (ElementTy.get () && ElementTy.get ()->hasOpaque () &&
@@ -9830,11 +9807,6 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
9830
9807
accessors.record (*this , Subscript, (Invalid || !Status.isSuccess () ||
9831
9808
Status.hasCodeCompletion ()));
9832
9809
9833
- // Set original declaration in `@differentiable` attributes.
9834
- for (auto *accessor : accessors.Accessors )
9835
- setOriginalDeclarationForDifferentiableAttributes (accessor->getAttrs (),
9836
- accessor);
9837
-
9838
9810
// No need to setLocalDiscriminator because subscripts cannot
9839
9811
// validly appear outside of type decls.
9840
9812
return makeParserResult (Status, Subscript);
@@ -9944,7 +9916,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
9944
9916
thrownTy, BodyParams, GenericParams,
9945
9917
CurDeclContext, FuncRetTy);
9946
9918
CD->setImplicitlyUnwrappedOptional (IUO);
9947
- CD->getAttrs () = Attributes;
9919
+ CD->attachParsedAttrs ( Attributes) ;
9948
9920
9949
9921
// Parse a 'where' clause if present.
9950
9922
if (Tok.is (tok::kw_where)) {
@@ -10033,7 +10005,7 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
10033
10005
auto *DD = new (Context) DestructorDecl (DestructorLoc, CurDeclContext);
10034
10006
parseAbstractFunctionBody (DD);
10035
10007
10036
- DD->getAttrs () = Attributes;
10008
+ DD->attachParsedAttrs ( Attributes) ;
10037
10009
10038
10010
// Reject 'destructor' functions outside of structs, enums, classes, or
10039
10011
// extensions that provide objc implementations.
@@ -10240,7 +10212,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
10240
10212
10241
10213
diagnoseOperatorFixityAttributes (*this , Attributes, res);
10242
10214
10243
- res->getAttrs () = Attributes;
10215
+ res->attachParsedAttrs ( Attributes) ;
10244
10216
return makeParserResult (res);
10245
10217
}
10246
10218
@@ -10297,7 +10269,7 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
10297
10269
higherThanKeywordLoc, higherThan,
10298
10270
lowerThanKeywordLoc, lowerThan,
10299
10271
rbraceLoc);
10300
- result->getAttrs () = attributes;
10272
+ result->attachParsedAttrs ( attributes) ;
10301
10273
return result;
10302
10274
};
10303
10275
auto createInvalid = [&](bool hasCodeCompletion) {
@@ -10552,7 +10524,7 @@ ParserResult<MacroDecl> Parser::parseDeclMacro(DeclAttributes &attributes) {
10552
10524
auto *macro = new (Context) MacroDecl (
10553
10525
macroLoc, macroFullName, macroNameLoc, genericParams, parameterList,
10554
10526
arrowLoc, resultType, definition, CurDeclContext);
10555
- macro->getAttrs () = attributes;
10527
+ macro->attachParsedAttrs ( attributes) ;
10556
10528
10557
10529
// Parse a 'where' clause if present.
10558
10530
if (Tok.is (tok::kw_where)) {
@@ -10588,7 +10560,7 @@ Parser::parseDeclMacroExpansion(ParseDeclOptions flags,
10588
10560
auto *med = MacroExpansionDecl::create (
10589
10561
CurDeclContext, poundLoc, macroNameRef, macroNameLoc, leftAngleLoc,
10590
10562
Context.AllocateCopy (genericArgs), rightAngleLoc, argList);
10591
- med->getAttrs () = attributes;
10563
+ med->attachParsedAttrs ( attributes) ;
10592
10564
10593
10565
return makeParserResult (status, med);
10594
10566
}
0 commit comments