Skip to content

Commit 5a88257

Browse files
Merge pull request #69624 from sophiapoirier/nonisolated-unsafe-globals-temp
parse nonisolated(unsafe) as decl contextual keyword in top-level global scope rather than as function invocation
2 parents 36a15ce + e10504f commit 5a88257

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
@@ -5435,10 +5435,30 @@ static void skipAttribute(Parser &P) {
54355435

54365436
bool Parser::isStartOfSwiftDecl(bool allowPoundIfAttributes,
54375437
bool hadAttrsOrModifiers) {
5438+
const bool isTopLevelLibrary = (SF.Kind == SourceFileKind::Library) ||
5439+
(SF.Kind == SourceFileKind::Interface) ||
5440+
(SF.Kind == SourceFileKind::SIL);
54385441
if (Tok.is(tok::at_sign) && peekToken().is(tok::kw_rethrows)) {
54395442
// @rethrows does not follow the general rule of @<identifier> so
54405443
// it is needed to short circuit this else there will be an infinite
54415444
// loop on invalid attributes of just rethrows
5445+
} else if (Context.LangOpts.hasFeature(Feature::GlobalConcurrency) &&
5446+
(Tok.getKind() == tok::identifier) &&
5447+
Tok.getText().equals("nonisolated") && isTopLevelLibrary &&
5448+
!CurDeclContext->isLocalContext()) {
5449+
// TODO: hack to unblock proposal review by treating top-level nonisolated
5450+
// contextual keyword like an attribute; more robust implementation pending
5451+
BacktrackingScope backtrack(*this);
5452+
skipAttribute(*this);
5453+
5454+
// If this attribute is the last element in the block,
5455+
// consider it is a start of incomplete decl.
5456+
if (Tok.isAny(tok::r_brace, tok::eof) ||
5457+
(Tok.is(tok::pound_endif) && !allowPoundIfAttributes))
5458+
return true;
5459+
5460+
return isStartOfSwiftDecl(allowPoundIfAttributes,
5461+
/*hadAttrsOrModifiers=*/true);
54425462
} else if (!isKeywordPossibleDeclStart(Context.LangOpts, Tok)) {
54435463
// If this is obviously not the start of a decl, then we're done.
54445464
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)