Skip to content

Commit b7edae0

Browse files
committed
parse nonisolated(unsafe) as decl contextual keyword in top-level global scope rather than as function invocation (temporary solution)
1 parent 0079583 commit b7edae0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5184,10 +5184,30 @@ static void skipAttribute(Parser &P) {
51845184

51855185
bool Parser::isStartOfSwiftDecl(bool allowPoundIfAttributes,
51865186
bool hadAttrsOrModifiers) {
5187+
const bool isTopLevelLibrary = (SF.Kind == SourceFileKind::Library) ||
5188+
(SF.Kind == SourceFileKind::Interface) ||
5189+
(SF.Kind == SourceFileKind::SIL);
51875190
if (Tok.is(tok::at_sign) && peekToken().is(tok::kw_rethrows)) {
51885191
// @rethrows does not follow the general rule of @<identifier> so
51895192
// it is needed to short circuit this else there will be an infinite
51905193
// loop on invalid attributes of just rethrows
5194+
} else if (Context.LangOpts.hasFeature(Feature::GlobalConcurrency) &&
5195+
(Tok.getKind() == tok::identifier) &&
5196+
Tok.getText().equals("nonisolated") && isTopLevelLibrary &&
5197+
!CurDeclContext->isLocalContext()) {
5198+
// TODO: hack to unblock proposal review by treating top-level nonisolated
5199+
// contextual keyword like an attribute; more robust implementation pending
5200+
BacktrackingScope backtrack(*this);
5201+
skipAttribute(*this);
5202+
5203+
// If this attribute is the last element in the block,
5204+
// consider it is a start of incomplete decl.
5205+
if (Tok.isAny(tok::r_brace, tok::eof) ||
5206+
(Tok.is(tok::pound_endif) && !allowPoundIfAttributes))
5207+
return true;
5208+
5209+
return isStartOfSwiftDecl(allowPoundIfAttributes,
5210+
/*hadAttrsOrModifiers=*/true);
51915211
} else if (!isKeywordPossibleDeclStart(Context.LangOpts, Tok)) {
51925212
// If this is obviously not the start of a decl, then we're done.
51935213
return false;

test/Concurrency/experimental_feature_strictconcurrency.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ final class TestNonsendable {
4545
init() {}
4646
}
4747

48+
nonisolated(unsafe) let immutableNonisolatedUnsafeTopLevelGlobal = TestNonsendable()
49+
4850
@propertyWrapper
4951
public struct TestWrapper {
5052
public init() {}

0 commit comments

Comments
 (0)