Skip to content

[Sema][MiscDiag] Fix constantness diag to handle result builder patterns #40579

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 1 commit into from
Jan 11, 2022

Conversation

guitard0g
Copy link

We currently have a problem with how constantness diagnostics
traverse the AST to look for function calls to diagnose. We
special case closure bodies and don't check them (unless they're
single expression closures) because closure bodies are type-
checked separately and will be covered later. This poses a problem
in certain AST structures, such as what we see with result builders,
because the call expressions are rooted in declarations, which aren't
checked in the closure body type-checking covered by MiscDiag.

This patch fixes the problem by manually checking all closure bodies
and stopping misc diagnostics from checking the bodies separately.

rdar://85737300

@guitard0g
Copy link
Author

@swift-ci please test

We currently have a problem with how constantness diagnostics
traverse the AST to look for function calls to diagnose. We
special case closure bodies and don't check them (unless they're
single expression closures) because closure bodies are type-
checked separately and will be covered later. This poses a problem
in certain AST structures, such as what we see with result builders,
because the call expressions are rooted in declarations, which aren't
checked in the closure body type-checking covered by MiscDiag.

This patch fixes the problem by manually checking all closure bodies
and stopping misc diagnostics from checking the bodies separately.

rdar://85737300
@guitard0g guitard0g force-pushed the constantness-result-builders branch from b36ca49 to f748c84 Compare December 16, 2021 02:26
@guitard0g
Copy link
Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - f748c84

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

@guitard0g I think this is going to be fixed once I re-enable SE-0326 since all of the closures are going to be type-checked together with expression - so the check you have removed is always going to be true. Could you please give it a try and see if that works with -Xfrontend -experimental-multi-statement-closures flag set?

@guitard0g
Copy link
Author

@guitard0g I think this is going to be fixed once I re-enable SE-0326 since all of the closures are going to be type-checked together with expression - so the check you have removed is always going to be true. Could you please give it a try and see if that works with -Xfrontend -experimental-multi-statement-closures flag set?

@xedin This does seem to stop some of the exiting early, but not in all instances, so we may still need this check.

@guitard0g
Copy link
Author

@swift-ci please test

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Alright, we can revisit this once result builders are ported to use conjunction mechanism.

@swift-ci
Copy link
Contributor

swift-ci commented Jan 8, 2022

Build failed
Swift Test OS X Platform
Git Sha - f748c84

@guitard0g
Copy link
Author

@swift-ci please test macOS platform

@guitard0g guitard0g merged commit 967465e into swiftlang:main Jan 11, 2022
guitard0g pushed a commit to guitard0g/swift that referenced this pull request Jan 18, 2022
…patterns

(This is a cherry-pick of PR swiftlang#40579 to the release/5.6 branch.)

We currently have a problem with how constantness diagnostics
traverse the AST to look for function calls to diagnose. We
special case closure bodies and don't check them (unless they're
single expression closures) because closure bodies are type-
checked separately and will be covered later. This poses a problem
in certain AST structures, such as what we see with result builders,
because the call expressions are rooted in declarations, which aren't
checked in the closure body type-checking covered by MiscDiag.

This patch fixes the problem by manually checking all closure bodies
and stopping misc diagnostics from checking the bodies separately.

rdar://85737300
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.

3 participants