Skip to content

[CSGen] Turn invalid decls into holes #34584

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 5 commits into from
Nov 5, 2020
Merged

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Nov 5, 2020

Instead of failing constraint generation upon encountering
an invalid declaration, let's turn that declaration into a
potential hole and keep going. Doing so enables the solver
to reach a solution and diagnose any other issue with
expression.

Resolves: rdar://70880670

xedin added 5 commits November 3, 2020 17:52
Upon attempt to generate constraints for invalid declaration reference
let's turn that into a hole and record this new fix to diagnose it
once solution has been reached.
If AST node is a reference to an invalid declaration let's
diagnose it as such unless some errors have been emitted
(invalid declaration itself should have a diagnostic
describing a reason why it's invalid).
Instead of failing constraint generation upon encountering
an invalid declaration, let's turn that declaration into a
potential hole and keep going. Doing so enables the solver
to reach a solution and diagnose any other issue with
expression.
@xedin xedin requested review from hborla and nathawes November 5, 2020 00:21
@xedin
Copy link
Contributor Author

xedin commented Nov 5, 2020

@nathawes I believe that this is going to help code completion, maybe we have a few test-cases we could add to showcase that?

@xedin
Copy link
Contributor Author

xedin commented Nov 5, 2020

@swift-ci please test

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! Just one question below

// If no errors have been emitted yet, let's emit one
// about reference to an invalid declaration.

emitDiagnostic(diag::reference_to_invalid_decl, decl->getName());
Copy link
Member

Choose a reason for hiding this comment

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

When would the solver actually emit this error?

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 cases when actual problem with declaration hasn't been diagnosed due to a bug (hopefully never).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about adding bit about asking to report it just like we do with actual fallback diagnostic.

@@ -1227,9 +1227,11 @@ namespace {
if (knownType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just above this, within the CS.getVarType(VD) call it's getting the type of VD and replacing any ErrorTypes it contains with holes when CS.isForCodeCompletion is true. Does this change make that logic redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for code completion we'd want to preserve as much structure as possible so replacing everything with a single hole might not be the best way... I was thinking more of a second case where E->getDecl()->isInvalid() is true.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is, could we remove it and make the below behave the same way, preserving any wrapping types? (e.g. [ErrorType] becomes [<hole>] rather than just <hole>?

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't see your reply before I sent that, sorry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I could try to unify logic here to preserve some more structure for diagnostics, I'll give it a try!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into this some more and it looks like for solver and diagnostics in particular it make more sense to keep invalid declarations represented as type variables so they could assume any time from context instead otherwise we'd risk diagnosing issues which are effectively already diagnosed while validating declarations...

@xedin xedin merged commit 1f14005 into swiftlang:main Nov 5, 2020
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