Skip to content
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

[ConstraintSystem] Avoid applying invalid solution with fixes #30592

Merged
merged 6 commits into from Mar 25, 2020

Conversation

xedin
Copy link
Member

@xedin xedin commented Mar 23, 2020

If solution score indicates that there should be a fix but
none where recorded fail solution application and produce
a fallback diagnostic to pin-point a problem.

Couple of points:

  • Start tracking number of holes involved in each solution, this allows us to:
    a. Score solutions based on number of holes as a fallback for "fix" weight;
    b. Identify cases where there are one or more holes but not "fixes".

  • Detect misuse of _ (discard assignment expression) while performing
    constraint generation which helps to avoid solutions with holes and no fixes
    which used to be diagnosed by syntactic diagnostics before (in MiscDiagnostics).

Resolves: rdar://problem/60663007

@xedin xedin requested review from DougGregor and hborla March 23, 2020 22:39
@xedin
Copy link
Member Author

xedin commented Mar 23, 2020

@swift-ci please smoke test

@xedin
Copy link
Member Author

xedin commented Mar 24, 2020

@swift-ci please smoke test macOS platform

2 similar comments
@xedin
Copy link
Member Author

xedin commented Mar 24, 2020

@swift-ci please smoke test macOS platform

@xedin
Copy link
Member Author

xedin commented Mar 24, 2020

@swift-ci please smoke test macOS platform

Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

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

Looks great! I just have one small comment about using SK_Hole in other places

lib/Sema/ConstraintSystem.h Show resolved Hide resolved
If solution score indicates that there should be a fix but
none where recorded fail solution application and produce
a fallback diagnostic to pin-point a problem.

Resolves: rdar://problem/60663007
Introduce `SK_Hole` which is used to count a number of "holes" in
a given solution. It is used to distinguish solutions with fewer holes.

Also it makes it possible to check whether a solution has holes but
no fixes, which is an issue and such solution shouldn't be applied
to AST.
…neration

`_` or discard assignment expression should only be used on the left-hand
side of the assignment expression. Incorrect uses are easy to detect during
constraint generation which also allows us to avoid complications related
to other diagnostics when `_` is used incorrectly.
…xes/holes

If score indicates that a solution should have at least one fix
but it doesn't let's attempt to produce a fallback diagnostic inline.
Problems related to incorrect use of `_` where previously diagnosed
by syntactic diagnostics which meant that it could only happen on
type-checked AST. This is no longer a case so we don't have to allow
incorrect uses of `_` to form solution without any fixes.
… holes

`SK_Fix` was used to indicate that solver has encountered a hole
along the current path but since there is `SK_Hole` now, increasing
`SK_Fix` no longer makes sense.
@xedin
Copy link
Member Author

xedin commented Mar 25, 2020

@swift-ci please smoke test

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.

None yet

2 participants