|
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 |
|
@@ -2550,8 +2551,16 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2550 | 2551 | BacktrackingScope backtrack(*this); |
2551 | 2552 |
|
2552 | 2553 | // Consume attributes. |
2553 | | - while (Tok.is(tok::at_sign)) { |
2554 | | - skipAnyAttribute(); |
| 2554 | + auto parsingNonisolated = [this] { |
| 2555 | + return Context.LangOpts.hasFeature(Feature::ClosureIsolation) && |
| 2556 | + Tok.isContextualKeyword("nonisolated"); |
| 2557 | + }; |
| 2558 | + while (Tok.is(tok::at_sign) || parsingNonisolated()) { |
| 2559 | + if (parsingNonisolated()) { |
| 2560 | + consumeToken(); |
| 2561 | + } else { |
| 2562 | + skipAnyAttribute(); |
| 2563 | + } |
2555 | 2564 | } |
2556 | 2565 |
|
2557 | 2566 | // Skip by a closure capture list if present. |
@@ -2615,7 +2624,12 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2615 | 2624 | return makeParserSuccess(); |
2616 | 2625 | } |
2617 | 2626 | ParserStatus status; |
2618 | | - (void)parseDeclAttributeList(attributes); |
| 2627 | + // 'nonisolated' cannot be parameterized in a closure due to ambiguity with |
| 2628 | + // closure parameters. |
| 2629 | + const auto entryNonisolatedState = |
| 2630 | + std::exchange(EnableParameterizedNonisolated, false); |
| 2631 | + (void)parseClosureDeclAttributeList(attributes); |
| 2632 | + EnableParameterizedNonisolated = entryNonisolatedState; |
2619 | 2633 |
|
2620 | 2634 | if (Tok.is(tok::l_square) && peekToken().is(tok::r_square)) { |
2621 | 2635 | SourceLoc lBracketLoc = consumeToken(tok::l_square); |
@@ -2785,6 +2799,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2785 | 2799 | } else { |
2786 | 2800 | // Parse identifier (',' identifier)* |
2787 | 2801 | SmallVector<ParamDecl*, 4> elements; |
| 2802 | + const auto parameterListLoc = Tok.getLoc(); |
2788 | 2803 | bool HasNext; |
2789 | 2804 | do { |
2790 | 2805 | if (Tok.isNot(tok::identifier, tok::kw__, tok::code_complete)) { |
@@ -2814,6 +2829,15 @@ ParserStatus Parser::parseClosureSignatureIfPresent( |
2814 | 2829 | } while (HasNext); |
2815 | 2830 |
|
2816 | 2831 | params = ParameterList::create(Context, elements); |
| 2832 | + |
| 2833 | + if (Context.LangOpts.hasFeature(Feature::ClosureIsolation) && params && |
| 2834 | + (params->size() > 0) && attributes.hasAttribute<NonisolatedAttr>()) { |
| 2835 | + diagnose(parameterListLoc, |
| 2836 | + diag::nonisolated_closure_parameter_parentheses) |
| 2837 | + .fixItInsert(parameterListLoc, "(") |
| 2838 | + .fixItInsert(Tok.getLoc(), ")"); |
| 2839 | + status.setIsParseError(); |
| 2840 | + } |
2817 | 2841 | } |
2818 | 2842 |
|
2819 | 2843 | TypeRepr *thrownTypeRepr = nullptr; |
@@ -2944,13 +2968,13 @@ ParserResult<Expr> Parser::parseExprClosure() { |
2944 | 2968 | DeclAttributes attributes; |
2945 | 2969 | SourceRange bracketRange; |
2946 | 2970 | SmallVector<CaptureListEntry, 2> captureList; |
2947 | | - VarDecl *capturedSelfDecl; |
| 2971 | + VarDecl *capturedSelfDecl = nullptr; |
2948 | 2972 | ParameterList *params = nullptr; |
2949 | 2973 | SourceLoc asyncLoc; |
2950 | 2974 | SourceLoc throwsLoc; |
2951 | | - TypeExpr *thrownType; |
| 2975 | + TypeExpr *thrownType = nullptr; |
2952 | 2976 | SourceLoc arrowLoc; |
2953 | | - TypeExpr *explicitResultType; |
| 2977 | + TypeExpr *explicitResultType = nullptr; |
2954 | 2978 | SourceLoc inLoc; |
2955 | 2979 | Status |= parseClosureSignatureIfPresent( |
2956 | 2980 | attributes, bracketRange, captureList, capturedSelfDecl, params, asyncLoc, |
|
0 commit comments