Skip to content

[SE-0458] Implement "unsafe" effect for the for-in loop #2971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 24, 2025

Conversation

DougGregor
Copy link
Member

No description provided.

@DougGregor
Copy link
Member Author

swiftlang/swift#79573

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/swift#79573

@swift-ci please test Linux

@DougGregor
Copy link
Member Author

swiftlang/swift#79573

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

swiftlang/swift#79573

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/swift#79573

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

swiftlang/swift#79573

@swift-ci please test Windows

lexeme: self.currentToken,
experimentalFeatures: self.experimentalFeatures
), modifierKeyword == .unsafe, !self.peek(isAt: .keyword(.in)) {
unsafeKeyword = self.consumeAnyToken(remapping: .keyword)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to check at least for : to make sure the following continues to parse:

for unsafe: Int in [1, 2] {
  print(unsafe)
}

Also, I’d prefer to do self.expect(.keyword(.unsafe)) instead of consumeAnyToken. It just adds more context to what kind of keyword unsafeKeyword is and another layer of safety if the current token should not be unsafe for any reason in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, I read your comments out of order. We indeed need to deal with the :. Thanks for the self.expect(.keyword(.unsafe)) hint.

assertParse(
"for try await unsafe in e { }",
experimentalFeatures: [.unsafeExpression]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test for for unsafe in e { }?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. There's another ambiguity I also need to check for, i.e., for unsafe: Int in e { } needs to not parse as the unsafe keyword.

@DougGregor
Copy link
Member Author

@ahoppen I'll address your comments in a follow-up PR, because I want to get the bones of this in place for the compiler PR to land

@DougGregor DougGregor merged commit 5e42f4c into swiftlang:main Feb 24, 2025
3 checks passed
@DougGregor DougGregor deleted the unsafe-for-in-loop branch February 24, 2025 21:49
@DougGregor
Copy link
Member Author

Code review comments addressed via #2977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants