|
14 | 14 | // |
15 | 15 | //===----------------------------------------------------------------------===// |
16 | 16 |
|
17 | | -#include "swift/Parse/Parser.h" |
18 | 17 | #include "swift/AST/ASTWalker.h" |
19 | 18 | #include "swift/AST/Attr.h" |
20 | 19 | #include "swift/AST/DiagnosticsParse.h" |
21 | 20 | #include "swift/AST/TypeRepr.h" |
| 21 | +#include "swift/Basic/Defer.h" |
22 | 22 | #include "swift/Basic/EditorPlaceholder.h" |
| 23 | +#include "swift/Basic/StringExtras.h" |
23 | 24 | #include "swift/Parse/IDEInspectionCallbacks.h" |
| 25 | +#include "swift/Parse/Parser.h" |
24 | 26 | #include "llvm/ADT/SmallString.h" |
25 | 27 | #include "llvm/ADT/StringSwitch.h" |
26 | 28 | #include "llvm/ADT/Twine.h" |
27 | | -#include "swift/Basic/Defer.h" |
28 | | -#include "swift/Basic/StringExtras.h" |
29 | 29 | #include "llvm/Support/Compiler.h" |
30 | 30 | #include "llvm/Support/SaveAndRestore.h" |
31 | 31 | #include "llvm/Support/raw_ostream.h" |
| 32 | +#include <utility> |
32 | 33 |
|
33 | 34 | using namespace swift; |
34 | 35 |
|
@@ -2579,8 +2580,16 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2579 | 2580 | BacktrackingScope backtrack(*this); |
2580 | 2581 |
|
2581 | 2582 | // Consume attributes. |
2582 | | - while (Tok.is(tok::at_sign)) { |
2583 | | - skipAnyAttribute(); |
| 2583 | + auto parsingNonisolated = [this] { |
| 2584 | + return Context.LangOpts.hasFeature(Feature::ClosureIsolation) && |
| 2585 | + Tok.isContextualKeyword("nonisolated"); |
| 2586 | + }; |
| 2587 | + while (Tok.is(tok::at_sign) || parsingNonisolated()) { |
| 2588 | + if (parsingNonisolated()) { |
| 2589 | + consumeToken(); |
| 2590 | + } else { |
| 2591 | + skipAnyAttribute(); |
| 2592 | + } |
2584 | 2593 | } |
2585 | 2594 |
|
2586 | 2595 | // Skip by a closure capture list if present. |
@@ -2644,7 +2653,12 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2644 | 2653 | return makeParserSuccess(); |
2645 | 2654 | } |
2646 | 2655 | ParserStatus status; |
2647 | | - (void)parseDeclAttributeList(attributes); |
| 2656 | + // 'nonisolated' cannot be parameterized in a closure due to ambiguity with |
| 2657 | + // closure parameters. |
| 2658 | + const auto entryNonisolatedState = |
| 2659 | + std::exchange(EnableParameterizedNonisolated, false); |
| 2660 | + (void)parseClosureDeclAttributeList(attributes); |
| 2661 | + EnableParameterizedNonisolated = entryNonisolatedState; |
2648 | 2662 |
|
2649 | 2663 | if (Tok.is(tok::l_square) && peekToken().is(tok::r_square)) { |
2650 | 2664 | SourceLoc lBracketLoc = consumeToken(tok::l_square); |
@@ -2814,6 +2828,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2814 | 2828 | } else { |
2815 | 2829 | // Parse identifier (',' identifier)* |
2816 | 2830 | SmallVector<ParamDecl*, 4> elements; |
| 2831 | + const auto parameterListLoc = Tok.getLoc(); |
2817 | 2832 | bool HasNext; |
2818 | 2833 | do { |
2819 | 2834 | if (Tok.isNot(tok::identifier, tok::kw__, tok::code_complete)) { |
@@ -2843,6 +2858,15 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2843 | 2858 | } while (HasNext); |
2844 | 2859 |
|
2845 | 2860 | params = ParameterList::create(Context, elements); |
| 2861 | + |
| 2862 | + if (Context.LangOpts.hasFeature(Feature::ClosureIsolation) && params && |
| 2863 | + (params->size() > 0) && attributes.hasAttribute<NonisolatedAttr>()) { |
| 2864 | + diagnose(parameterListLoc, |
| 2865 | + diag::nonisolated_closure_parameter_parentheses) |
| 2866 | + .fixItInsert(parameterListLoc, "(") |
| 2867 | + .fixItInsert(Tok.getLoc(), ")"); |
| 2868 | + status.setIsParseError(); |
| 2869 | + } |
2846 | 2870 | } |
2847 | 2871 |
|
2848 | 2872 | TypeRepr *thrownTypeRepr = nullptr; |
@@ -2973,13 +2997,13 @@ ParserResult<Expr> Parser::parseExprClosure() { |
2973 | 2997 | DeclAttributes attributes; |
2974 | 2998 | SourceRange bracketRange; |
2975 | 2999 | SmallVector<CaptureListEntry, 2> captureList; |
2976 | | - VarDecl *capturedSelfDecl; |
| 3000 | + VarDecl *capturedSelfDecl = nullptr; |
2977 | 3001 | ParameterList *params = nullptr; |
2978 | 3002 | SourceLoc asyncLoc; |
2979 | 3003 | SourceLoc throwsLoc; |
2980 | | - TypeExpr *thrownType; |
| 3004 | + TypeExpr *thrownType = nullptr; |
2981 | 3005 | SourceLoc arrowLoc; |
2982 | | - TypeExpr *explicitResultType; |
| 3006 | + TypeExpr *explicitResultType = nullptr; |
2983 | 3007 | SourceLoc inLoc; |
2984 | 3008 | Status |= parseClosureSignatureIfPresent( |
2985 | 3009 | attributes, bracketRange, captureList, capturedSelfDecl, params, asyncLoc, |
|
0 commit comments