Skip to content

[CS] Explore additional bindings for fixes #30686

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 3 commits into from
Mar 29, 2020

Conversation

hamishknight
Copy link
Contributor

Previously we could skip defaultable constraints or supertype bindings if we had already found a solution with fixes, which could lead us to miss bindings that produce better diagnostics.

Tweak the logic such that we continue exploring if the bindings we've attempted so far have all required fixing.

Resolves SR-12399 & SR-12426.

@hamishknight hamishknight requested a review from xedin March 27, 2020 22:03
@hamishknight
Copy link
Contributor 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.

Impact changes look good. I have a couple of questions about changes related to scoring though.


// If this requirement is associated with an overload choice let's
// tie impact to how many times this requirement type is mentioned.
if (auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(anchor)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about an idea of not considering requirement failures recoverable in reference to operators?

I'm just trying to figure out how to move a needle in situations like:

func sr12438(_ e: Error) {
  func foo<T>(_ a: T, _ op: ((T, T) -> Bool)) {}
  foo(e, ==) // expected-error {{type of expression is ambiguous without more context}}
}

The problem here is that none of the operator declarations for == are going to match and they are all going to fail in different ways. I think we shouldn't try to rank such situations but instead be better at detecting completely hopeless situations...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, would that be specifically for unapplied operator references, or for operator references in general? Presumably we'd then emit a generic "operator cannot be applied with X operands" diagnostic?

I guess we could just try to detect the case where we have different possible overloads for an operator in diagnoseAmbiguityWithFixes, each with some kind of fix, and call into diagnoseOperatorAmbiguity (though it may need to be tweaked slightly to handle unapplied operator refs).

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, would that be specifically for unapplied operator references, or for operator references in general?

In general. I am hoping that improvement is going to be two-fold - fewer operators considered in diagnostics mode and more precise diagnostics when no operator overloads match.

That's what I was thinking as well, the problem is that we need to move diagnoseOperatorAmbiguity before findBestSolution and that could affect some of diagnostics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general. I am hoping that improvement is going to be two-fold - fewer operators considered in diagnostics mode and more precise diagnostics when no operator overloads match.

My only worry is for people defining their own operators that require conformances for arguments, it would be a shame to lose the requirement fixes there, perhaps we should limit it to known stdlib operators? Or maybe operators that have lots of overloads?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, maybe that should be limited only to stdlib operator overloads only.

Previously we could skip default literal or
supertype bindings if we had already found a solution
with fixes, which could lead us to miss bindings
that produce better diagnostics.

Tweak the logic such that we continue exploring if
we're in diagnostic mode.

Resolves SR-12399.
We should only be attempting such overloads for
nil literal args.

Resolves SR-12426.
- In `simplifyConformsToConstraint`, pass the LHS
type regardless of whether it is a type variable.

- Add the `choiceImpact` onto the impact for
adding a stdlib conformance.

- Treat Any and AnyObject as standard library
types.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test Windows

@hamishknight
Copy link
Contributor Author

Okay test/Parse/confusables.swift appears to be non-deterministically failing on Windows, but appears to be unrelated to my change as is also observable on master (https://ci-external.swift.org/job/oss-swift-windows-x86_64/3374/).

I've opened #30713 to adjust the test case, and filed rdar://61028087.

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