Skip to content

[Sema] Don’t allow unresolved type variables if LeaveBraceStmtBodyUnchecked is true #36943

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 2 commits into from
May 7, 2021

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Apr 16, 2021

[Sema] Don’t allow unresolved type variables if LeaveBraceStmtBodyUnchecked is true

According to Pavel, we want to eliminate allowing unresolved variables as much as possible. Removing this flag doesn’t break any test cases (at least not in a meaningful way) and fixes a crasher, so it seems reasonable to remove it.

When doing operator completion, we re-type-check the sequence expression. If we have an unresolve type already applied to ParsedExpr, which is the last element of the sequence, the type checker crashes in validation-test/IDE/crashers_2_fixed/0008-must-conform-to-literal-protocol.swift, because there are still inactive constraints in the constraint system when it finishes solving.

Previously, we would ignore because we allowed free type variables, which we no longer do since the last commit.

Fixes rdar://76686564

@ahoppen ahoppen requested a review from xedin April 16, 2021 10:52
@ahoppen
Copy link
Member Author

ahoppen commented Apr 20, 2021

@swift-ci Please test

@swiftlang swiftlang deleted a comment from swift-ci Apr 20, 2021
@swiftlang swiftlang deleted a comment from swift-ci Apr 20, 2021
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.

Is a solution with holes applied to the AST because this particular completion kind is still using old logic that relies on type-checked AST? If so, I think this fix is okay for now since in the future we’ll just stop doing AST transforms as switch to use typeCheckForCodeCompletion.

@ahoppen
Copy link
Member Author

ahoppen commented Apr 27, 2021

Yeah, AFAICT conforming method lists hasn’t been ported to typeCheckForCompletion yet (https://github.com/apple/swift/blob/main/lib/IDE/ConformingMethodList.cpp#L71).

@ahoppen ahoppen force-pushed the pr/conforming-methods-in-closure branch from 2ed06a4 to 75c5ed4 Compare May 6, 2021 08:18
…checked` is `true`

According to Pavel, we want to eliminate allowing unresolved variables as much as possible. Removing this flag doesn’t break any test cases (at least not in a meaningful way) and fixes a crasher, so it seems reasonable to remove it.

Fixes rdar://76686564
@ahoppen ahoppen changed the title [SourceKit] Fix crasher when retrieving conforming methods [Sema] Don’t allow unresolved type variables if LeaveBraceStmtBodyUnchecked is true May 6, 2021
@ahoppen ahoppen force-pushed the pr/conforming-methods-in-closure branch from 75c5ed4 to 74ff692 Compare May 6, 2021 08:19
@ahoppen
Copy link
Member Author

ahoppen commented May 6, 2021

@xedin Thanks for your feedback. As discussed offline, removing the AllowUnresolvedTypeVariables flag seems to fix the crash and not cause any other regressions, so it seems like a reasonable fix to me (especially since you would like to eliminate allowing unresolved type variables anyway).

@ahoppen ahoppen requested a review from rintaro May 6, 2021 08:20
@ahoppen
Copy link
Member Author

ahoppen commented May 6, 2021

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented May 6, 2021

Build failed
Swift Test Linux Platform
Git Sha - 74ff692

@swift-ci
Copy link
Contributor

swift-ci commented May 6, 2021

Build failed
Swift Test OS X Platform
Git Sha - 74ff692

…or completion

When doing operator completion, we re-type-check the sequence expression. If we have an unresolve type already applied to `ParsedExpr`, which is the last element of the sequence, the type checker crashes in `validation-test/IDE/crashers_2_fixed/0008-must-conform-to-literal-protocol.swift`, because there are still inactive constraints in the constraint system when it finishes solving.

Previously, we would ignore because we allowed free type variables, which we no longer do since the last commit.
@ahoppen
Copy link
Member Author

ahoppen commented May 6, 2021

@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.

Makes sense to me!

@swift-ci
Copy link
Contributor

swift-ci commented May 6, 2021

Build failed
Swift Test OS X Platform
Git Sha - 3d1f9b6

@ahoppen
Copy link
Member Author

ahoppen commented May 6, 2021

@swift-ci Please test macOS

@rintaro
Copy link
Member

rintaro commented May 6, 2021

We should remove another usage of TypeCheckExprFlags::AllowUnresolvedTypeVariables in visitReturnStmt. In fact the reproducer in rdar://76686564 is not fixed without removing it (probably because it's in an implicit ReturnStmt).

@xedin
Copy link
Contributor

xedin commented May 6, 2021

@ahoppen @rintaro It looks like there are just a couple of usages of TypeCheckExprFlags::AllowUnresolvedTypeVariables in lib/Sema, should we try to remove all of them and see what in code completion breaks?

@ahoppen ahoppen merged commit 6f46ba6 into swiftlang:main May 7, 2021
@ahoppen ahoppen deleted the pr/conforming-methods-in-closure branch May 7, 2021 12:08
ahoppen added a commit to ahoppen/swift-source-compat-suite that referenced this pull request May 7, 2021
shahmishal added a commit to swiftlang/swift-source-compat-suite that referenced this pull request May 7, 2021
[Stress Tester XFails] Remove SR-14494 and swiftlang/swift#36943
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.

4 participants