@@ -1510,7 +1510,12 @@ void Parser::parseAllAvailabilityMacroArguments() {
15101510 AvailabilityMacroMap Map;
15111511
15121512 SourceManager &SM = Context.SourceMgr ;
1513- const LangOptions &LangOpts = Context.LangOpts ;
1513+ LangOptions LangOpts = Context.LangOpts ;
1514+ // The sub-parser is not actually parsing the source file but the LangOpts
1515+ // AvailabilityMacros. No point creating a libSyntax tree for it. In fact, the
1516+ // creation of a libSyntax tree would always fail because the
1517+ // AvailibilityMacro is not valid Swift source code.
1518+ LangOpts.BuildSyntaxTree = false ;
15141519
15151520 for (StringRef macro: LangOpts.AvailabilityMacros ) {
15161521
@@ -2145,7 +2150,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
21452150 bool SuppressLaterDiags = false ;
21462151 if (parseList (tok::r_paren, LeftLoc, RightLoc, false ,
21472152 diag::originally_defined_in_missing_rparen,
2148- SyntaxKind::Unknown , [&]() -> ParserStatus {
2153+ SyntaxKind::AvailabilitySpecList , [&]() -> ParserStatus {
21492154 SWIFT_DEFER {
21502155 if (NK != NextSegmentKind::PlatformVersion) {
21512156 NK = (NextSegmentKind)((uint8_t )NK + (uint8_t )1 );
@@ -2154,6 +2159,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
21542159 switch (NK) {
21552160 // Parse 'module: "original_module_name"'.
21562161 case NextSegmentKind::ModuleName: {
2162+ SyntaxParsingContext argumentContext (SyntaxContext,
2163+ SyntaxKind::AvailabilityLabeledArgument);
21572164 // Parse 'module' ':'.
21582165 if (!Tok.is (tok::identifier) || Tok.getText () != " module" ||
21592166 !peekToken ().is (tok::colon)) {
@@ -2182,6 +2189,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
21822189 }
21832190 // Parse 'OSX 13.13'.
21842191 case NextSegmentKind::PlatformVersion: {
2192+ SyntaxParsingContext argumentContext (SyntaxContext,
2193+ SyntaxKind::AvailabilityVersionRestriction);
21852194 if ((Tok.is (tok::identifier) || Tok.is (tok::oper_binary_spaced)) &&
21862195 (peekToken ().isAny (tok::integer_literal, tok::floating_literal) ||
21872196 peekAvailabilityMacroName ())) {
@@ -4421,6 +4430,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
44214430
44224431 if (shouldParseExperimentalConcurrency () &&
44234432 Tok.isContextualKeyword (" actor" ) && peekToken ().is (tok::identifier)) {
4433+ Tok.setKind (tok::contextual_keyword);
44244434 DeclParsingContext.setCreateSyntax (SyntaxKind::ClassDecl);
44254435 DeclResult = parseDeclClass (Flags, Attributes);
44264436 break ;
@@ -5007,6 +5017,9 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
50075017 .fixItInsert (endOfPrevious, " ;" );
50085018 }
50095019
5020+ SyntaxParsingContext DeclContext (SyntaxContext,
5021+ SyntaxKind::MemberDeclListItem);
5022+
50105023 if (Tok.isAny (tok::pound_sourceLocation, tok::pound_line)) {
50115024 auto LineDirectiveStatus = parseLineDirective (Tok.is (tok::pound_line));
50125025 if (LineDirectiveStatus.isErrorOrHasCompletion ())
@@ -5015,8 +5028,6 @@ ParserStatus Parser::parseDeclItem(bool &PreviousHadSemi,
50155028 }
50165029
50175030 ParserResult<Decl> Result;
5018- SyntaxParsingContext DeclContext (SyntaxContext,
5019- SyntaxKind::MemberDeclListItem);
50205031 if (loadCurrentSyntaxNodeFromCache ()) {
50215032 return ParserStatus ();
50225033 }
@@ -7540,7 +7551,6 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
75407551 // part of
75417552 SourceLoc ClassLoc;
75427553 if (isExplicitActorDecl) {
7543- assert (Tok.is (tok::identifier) && Tok.isContextualKeyword (" actor" ));
75447554 ClassLoc = consumeToken ();
75457555 } else {
75467556 ClassLoc = consumeToken (tok::kw_class);
0 commit comments